@puckeditor/plugin-heading-analyzer 0.21.0-canary.d1c0d6a2
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 +34 -0
- package/dist/index.css +75 -0
- package/dist/index.d.mts +735 -0
- package/dist/index.d.ts +735 -0
- package/dist/index.js +2800 -0
- package/dist/index.mjs +2791 -0
- package/package.json +45 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
import { ReactElement, CSSProperties, ReactNode, ElementType, Ref, JSX } from 'react';
|
|
2
|
+
import { EditorStateSnapshot, Editor, Extensions } from '@tiptap/react';
|
|
3
|
+
import { BlockquoteOptions } from '@tiptap/extension-blockquote';
|
|
4
|
+
import { BoldOptions } from '@tiptap/extension-bold';
|
|
5
|
+
import { CodeOptions } from '@tiptap/extension-code';
|
|
6
|
+
import { CodeBlockOptions } from '@tiptap/extension-code-block';
|
|
7
|
+
import { HardBreakOptions } from '@tiptap/extension-hard-break';
|
|
8
|
+
import { HeadingOptions } from '@tiptap/extension-heading';
|
|
9
|
+
import { HorizontalRuleOptions } from '@tiptap/extension-horizontal-rule';
|
|
10
|
+
import { ItalicOptions } from '@tiptap/extension-italic';
|
|
11
|
+
import { LinkOptions } from '@tiptap/extension-link';
|
|
12
|
+
import { BulletListOptions, ListItemOptions, ListKeymapOptions, OrderedListOptions } from '@tiptap/extension-list';
|
|
13
|
+
import { ParagraphOptions } from '@tiptap/extension-paragraph';
|
|
14
|
+
import { StrikeOptions } from '@tiptap/extension-strike';
|
|
15
|
+
import { TextAlignOptions } from '@tiptap/extension-text-align';
|
|
16
|
+
import { UnderlineOptions } from '@tiptap/extension-underline';
|
|
17
|
+
|
|
18
|
+
type ItemSelector = {
|
|
19
|
+
index: number;
|
|
20
|
+
zone?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
declare const defaultEditorState: (ctx: EditorStateSnapshot, readOnly: boolean) => {
|
|
24
|
+
isAlignLeft?: undefined;
|
|
25
|
+
canAlignLeft?: undefined;
|
|
26
|
+
isAlignCenter?: undefined;
|
|
27
|
+
canAlignCenter?: undefined;
|
|
28
|
+
isAlignRight?: undefined;
|
|
29
|
+
canAlignRight?: undefined;
|
|
30
|
+
isAlignJustify?: undefined;
|
|
31
|
+
canAlignJustify?: undefined;
|
|
32
|
+
isBold?: undefined;
|
|
33
|
+
canBold?: undefined;
|
|
34
|
+
isItalic?: undefined;
|
|
35
|
+
canItalic?: undefined;
|
|
36
|
+
isUnderline?: undefined;
|
|
37
|
+
canUnderline?: undefined;
|
|
38
|
+
isStrike?: undefined;
|
|
39
|
+
canStrike?: undefined;
|
|
40
|
+
isInlineCode?: undefined;
|
|
41
|
+
canInlineCode?: undefined;
|
|
42
|
+
isBulletList?: undefined;
|
|
43
|
+
canBulletList?: undefined;
|
|
44
|
+
isOrderedList?: undefined;
|
|
45
|
+
canOrderedList?: undefined;
|
|
46
|
+
isCodeBlock?: undefined;
|
|
47
|
+
canCodeBlock?: undefined;
|
|
48
|
+
isBlockquote?: undefined;
|
|
49
|
+
canBlockquote?: undefined;
|
|
50
|
+
canHorizontalRule?: undefined;
|
|
51
|
+
} | {
|
|
52
|
+
isAlignLeft: boolean;
|
|
53
|
+
canAlignLeft: boolean;
|
|
54
|
+
isAlignCenter: boolean;
|
|
55
|
+
canAlignCenter: boolean;
|
|
56
|
+
isAlignRight: boolean;
|
|
57
|
+
canAlignRight: boolean;
|
|
58
|
+
isAlignJustify: boolean;
|
|
59
|
+
canAlignJustify: boolean;
|
|
60
|
+
isBold: boolean;
|
|
61
|
+
canBold: boolean;
|
|
62
|
+
isItalic: boolean;
|
|
63
|
+
canItalic: boolean;
|
|
64
|
+
isUnderline: boolean;
|
|
65
|
+
canUnderline: boolean;
|
|
66
|
+
isStrike: boolean;
|
|
67
|
+
canStrike: boolean;
|
|
68
|
+
isInlineCode: boolean;
|
|
69
|
+
canInlineCode: boolean;
|
|
70
|
+
isBulletList: boolean;
|
|
71
|
+
canBulletList: boolean;
|
|
72
|
+
isOrderedList: boolean;
|
|
73
|
+
canOrderedList: boolean;
|
|
74
|
+
isCodeBlock: boolean;
|
|
75
|
+
canCodeBlock: boolean;
|
|
76
|
+
isBlockquote: boolean;
|
|
77
|
+
canBlockquote: boolean;
|
|
78
|
+
canHorizontalRule: boolean;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type RichTextSelector = (ctx: EditorStateSnapshot, readOnly: boolean) => Partial<Record<string, boolean>>;
|
|
82
|
+
type DefaultEditorState = ReturnType<typeof defaultEditorState>;
|
|
83
|
+
type EditorState<Selector extends RichTextSelector = RichTextSelector> = DefaultEditorState & ReturnType<Selector> & Record<string, boolean | undefined>;
|
|
84
|
+
|
|
85
|
+
interface PuckRichTextOptions {
|
|
86
|
+
/**
|
|
87
|
+
* If set to false, the blockquote extension will not be registered
|
|
88
|
+
* @example blockquote: false
|
|
89
|
+
*/
|
|
90
|
+
blockquote: Partial<BlockquoteOptions> | false;
|
|
91
|
+
/**
|
|
92
|
+
* If set to false, the bold extension will not be registered
|
|
93
|
+
* @example bold: false
|
|
94
|
+
*/
|
|
95
|
+
bold: Partial<BoldOptions> | false;
|
|
96
|
+
/**
|
|
97
|
+
* If set to false, the bulletList extension will not be registered
|
|
98
|
+
* @example bulletList: false
|
|
99
|
+
*/
|
|
100
|
+
bulletList: Partial<BulletListOptions> | false;
|
|
101
|
+
/**
|
|
102
|
+
* If set to false, the code extension will not be registered
|
|
103
|
+
* @example code: false
|
|
104
|
+
*/
|
|
105
|
+
code: Partial<CodeOptions> | false;
|
|
106
|
+
/**
|
|
107
|
+
* If set to false, the codeBlock extension will not be registered
|
|
108
|
+
* @example codeBlock: false
|
|
109
|
+
*/
|
|
110
|
+
codeBlock: Partial<CodeBlockOptions> | false;
|
|
111
|
+
/**
|
|
112
|
+
* If set to false, the document extension will not be registered
|
|
113
|
+
* @example document: false
|
|
114
|
+
*/
|
|
115
|
+
document: false;
|
|
116
|
+
/**
|
|
117
|
+
* If set to false, the hardBreak extension will not be registered
|
|
118
|
+
* @example hardBreak: false
|
|
119
|
+
*/
|
|
120
|
+
hardBreak: Partial<HardBreakOptions> | false;
|
|
121
|
+
/**
|
|
122
|
+
* If set to false, the heading extension will not be registered
|
|
123
|
+
* @example heading: false
|
|
124
|
+
*/
|
|
125
|
+
heading: Partial<HeadingOptions> | false;
|
|
126
|
+
/**
|
|
127
|
+
* If set to false, the horizontalRule extension will not be registered
|
|
128
|
+
* @example horizontalRule: false
|
|
129
|
+
*/
|
|
130
|
+
horizontalRule: Partial<HorizontalRuleOptions> | false;
|
|
131
|
+
/**
|
|
132
|
+
* If set to false, the italic extension will not be registered
|
|
133
|
+
* @example italic: false
|
|
134
|
+
*/
|
|
135
|
+
italic: Partial<ItalicOptions> | false;
|
|
136
|
+
/**
|
|
137
|
+
* If set to false, the listItem extension will not be registered
|
|
138
|
+
* @example listItem: false
|
|
139
|
+
*/
|
|
140
|
+
listItem: Partial<ListItemOptions> | false;
|
|
141
|
+
/**
|
|
142
|
+
* If set to false, the listItemKeymap extension will not be registered
|
|
143
|
+
* @example listKeymap: false
|
|
144
|
+
*/
|
|
145
|
+
listKeymap: Partial<ListKeymapOptions> | false;
|
|
146
|
+
/**
|
|
147
|
+
* If set to false, the link extension will not be registered
|
|
148
|
+
* @example link: false
|
|
149
|
+
*/
|
|
150
|
+
link: Partial<LinkOptions> | false;
|
|
151
|
+
/**
|
|
152
|
+
* If set to false, the orderedList extension will not be registered
|
|
153
|
+
* @example orderedList: false
|
|
154
|
+
*/
|
|
155
|
+
orderedList: Partial<OrderedListOptions> | false;
|
|
156
|
+
/**
|
|
157
|
+
* If set to false, the paragraph extension will not be registered
|
|
158
|
+
* @example paragraph: false
|
|
159
|
+
*/
|
|
160
|
+
paragraph: Partial<ParagraphOptions> | false;
|
|
161
|
+
/**
|
|
162
|
+
* If set to false, the strike extension will not be registered
|
|
163
|
+
* @example strike: false
|
|
164
|
+
*/
|
|
165
|
+
strike: Partial<StrikeOptions> | false;
|
|
166
|
+
/**
|
|
167
|
+
* If set to false, the text extension will not be registered
|
|
168
|
+
* @example text: false
|
|
169
|
+
*/
|
|
170
|
+
text: false;
|
|
171
|
+
/**
|
|
172
|
+
* If set to false, the textAlign extension will not be registered
|
|
173
|
+
* @example text: false
|
|
174
|
+
*/
|
|
175
|
+
textAlign: Partial<TextAlignOptions> | false;
|
|
176
|
+
/**
|
|
177
|
+
* If set to false, the underline extension will not be registered
|
|
178
|
+
* @example underline: false
|
|
179
|
+
*/
|
|
180
|
+
underline: Partial<UnderlineOptions> | false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
type FieldOption = {
|
|
184
|
+
label: string;
|
|
185
|
+
value: string | number | boolean | undefined | null | object;
|
|
186
|
+
};
|
|
187
|
+
type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
188
|
+
interface BaseField {
|
|
189
|
+
label?: string;
|
|
190
|
+
labelIcon?: ReactElement;
|
|
191
|
+
metadata?: FieldMetadata;
|
|
192
|
+
visible?: boolean;
|
|
193
|
+
}
|
|
194
|
+
interface TextField extends BaseField {
|
|
195
|
+
type: "text";
|
|
196
|
+
placeholder?: string;
|
|
197
|
+
contentEditable?: boolean;
|
|
198
|
+
}
|
|
199
|
+
interface NumberField extends BaseField {
|
|
200
|
+
type: "number";
|
|
201
|
+
placeholder?: string;
|
|
202
|
+
min?: number;
|
|
203
|
+
max?: number;
|
|
204
|
+
step?: number;
|
|
205
|
+
}
|
|
206
|
+
interface TextareaField extends BaseField {
|
|
207
|
+
type: "textarea";
|
|
208
|
+
placeholder?: string;
|
|
209
|
+
contentEditable?: boolean;
|
|
210
|
+
}
|
|
211
|
+
interface SelectField extends BaseField {
|
|
212
|
+
type: "select";
|
|
213
|
+
options: FieldOptions;
|
|
214
|
+
}
|
|
215
|
+
interface RadioField extends BaseField {
|
|
216
|
+
type: "radio";
|
|
217
|
+
options: FieldOptions;
|
|
218
|
+
}
|
|
219
|
+
interface RichtextField<UserSelector extends RichTextSelector = RichTextSelector> extends BaseField {
|
|
220
|
+
type: "richtext";
|
|
221
|
+
contentEditable?: boolean;
|
|
222
|
+
initialHeight?: CSSProperties["height"];
|
|
223
|
+
options?: Partial<PuckRichTextOptions>;
|
|
224
|
+
renderMenu?: (props: {
|
|
225
|
+
children: ReactNode;
|
|
226
|
+
editor: Editor | null;
|
|
227
|
+
editorState: EditorState<UserSelector> | null;
|
|
228
|
+
readOnly: boolean;
|
|
229
|
+
}) => ReactNode;
|
|
230
|
+
renderInlineMenu?: (props: {
|
|
231
|
+
children: ReactNode;
|
|
232
|
+
editor: Editor | null;
|
|
233
|
+
editorState: EditorState<UserSelector> | null;
|
|
234
|
+
readOnly: boolean;
|
|
235
|
+
}) => ReactNode;
|
|
236
|
+
tiptap?: {
|
|
237
|
+
selector?: UserSelector;
|
|
238
|
+
extensions?: Extensions;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
interface ArrayField<Props extends {
|
|
242
|
+
[key: string]: any;
|
|
243
|
+
}[] = {
|
|
244
|
+
[key: string]: any;
|
|
245
|
+
}[], UserField extends {} = {}> extends BaseField {
|
|
246
|
+
type: "array";
|
|
247
|
+
arrayFields: {
|
|
248
|
+
[SubPropName in keyof Props[0]]: UserField extends {
|
|
249
|
+
type: PropertyKey;
|
|
250
|
+
} ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
|
|
251
|
+
};
|
|
252
|
+
defaultItemProps?: Props[0] | ((index: number) => Props[0]);
|
|
253
|
+
getItemSummary?: (item: Props[0], index?: number) => ReactNode;
|
|
254
|
+
max?: number;
|
|
255
|
+
min?: number;
|
|
256
|
+
}
|
|
257
|
+
interface ObjectField<Props extends any = {
|
|
258
|
+
[key: string]: any;
|
|
259
|
+
}, UserField extends {} = {}> extends BaseField {
|
|
260
|
+
type: "object";
|
|
261
|
+
objectFields: {
|
|
262
|
+
[SubPropName in keyof Props]: UserField extends {
|
|
263
|
+
type: PropertyKey;
|
|
264
|
+
} ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
|
268
|
+
name: string;
|
|
269
|
+
fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
|
|
270
|
+
mapProp?: (value: TableShape) => PropShape;
|
|
271
|
+
};
|
|
272
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
273
|
+
type ExternalFieldWithAdaptor<Props extends any = {
|
|
274
|
+
[key: string]: any;
|
|
275
|
+
}> = BaseField & {
|
|
276
|
+
type: "external";
|
|
277
|
+
placeholder?: string;
|
|
278
|
+
adaptor: Adaptor<any, any, Props>;
|
|
279
|
+
adaptorParams?: object;
|
|
280
|
+
getItemSummary: (item: NotUndefined<Props>, index?: number) => ReactNode;
|
|
281
|
+
};
|
|
282
|
+
type CacheOpts = {
|
|
283
|
+
enabled?: boolean;
|
|
284
|
+
};
|
|
285
|
+
interface ExternalField<Props extends any = {
|
|
286
|
+
[key: string]: any;
|
|
287
|
+
}> extends BaseField {
|
|
288
|
+
type: "external";
|
|
289
|
+
cache?: CacheOpts;
|
|
290
|
+
placeholder?: string;
|
|
291
|
+
fetchList: (params: {
|
|
292
|
+
query: string;
|
|
293
|
+
filters: Record<string, any>;
|
|
294
|
+
}) => Promise<any[] | null>;
|
|
295
|
+
mapProp?: (value: any) => Props;
|
|
296
|
+
mapRow?: (value: any) => Record<string, string | number | ReactElement>;
|
|
297
|
+
getItemSummary?: (item: NotUndefined<Props>, index?: number) => ReactNode;
|
|
298
|
+
showSearch?: boolean;
|
|
299
|
+
renderFooter?: (props: {
|
|
300
|
+
items: any[];
|
|
301
|
+
}) => ReactElement;
|
|
302
|
+
initialQuery?: string;
|
|
303
|
+
filterFields?: Record<string, Field>;
|
|
304
|
+
initialFilters?: Record<string, any>;
|
|
305
|
+
}
|
|
306
|
+
type CustomFieldRender<Value extends any> = (props: {
|
|
307
|
+
field: CustomField<Value>;
|
|
308
|
+
name: string;
|
|
309
|
+
id: string;
|
|
310
|
+
value: Value;
|
|
311
|
+
onChange: (value: Value) => void;
|
|
312
|
+
readOnly?: boolean;
|
|
313
|
+
}) => ReactElement;
|
|
314
|
+
interface CustomField<Value extends any> extends BaseField {
|
|
315
|
+
type: "custom";
|
|
316
|
+
render: CustomFieldRender<Value>;
|
|
317
|
+
contentEditable?: boolean;
|
|
318
|
+
key?: string;
|
|
319
|
+
}
|
|
320
|
+
interface SlotField extends BaseField {
|
|
321
|
+
type: "slot";
|
|
322
|
+
allow?: string[];
|
|
323
|
+
disallow?: string[];
|
|
324
|
+
}
|
|
325
|
+
type Field<ValueType = any, UserField extends {} = {}> = TextField | RichtextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
|
326
|
+
[key: string]: any;
|
|
327
|
+
}[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
|
328
|
+
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps, UserField extends {} = {}> = {
|
|
329
|
+
[PropName in keyof Omit<ComponentProps, "editMode">]: UserField extends {
|
|
330
|
+
type: PropertyKey;
|
|
331
|
+
} ? Field<ComponentProps[PropName], UserField> | UserField : Field<ComponentProps[PropName]>;
|
|
332
|
+
};
|
|
333
|
+
type FieldProps<F = Field<any>, ValueType = any> = {
|
|
334
|
+
field: F;
|
|
335
|
+
value: ValueType;
|
|
336
|
+
id?: string;
|
|
337
|
+
onChange: (value: ValueType, uiState?: Partial<UiState>) => void;
|
|
338
|
+
readOnly?: boolean;
|
|
339
|
+
};
|
|
340
|
+
|
|
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
|
+
type PuckContext = {
|
|
354
|
+
renderDropZone: (props: DropZoneProps) => React.ReactNode;
|
|
355
|
+
metadata: Metadata;
|
|
356
|
+
isEditing: boolean;
|
|
357
|
+
dragRef: ((element: Element | null) => void) | null;
|
|
358
|
+
};
|
|
359
|
+
type DefaultRootFieldProps = {
|
|
360
|
+
title?: string;
|
|
361
|
+
};
|
|
362
|
+
type DefaultComponentProps = {
|
|
363
|
+
[key: string]: any;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
type WithId<Props> = Props & {
|
|
367
|
+
id: string;
|
|
368
|
+
};
|
|
369
|
+
type WithPuckProps<Props> = Props & {
|
|
370
|
+
puck: PuckContext;
|
|
371
|
+
editMode?: boolean;
|
|
372
|
+
};
|
|
373
|
+
type AsFieldProps<Props> = Omit<Props, "children" | "puck" | "editMode">;
|
|
374
|
+
type WithChildren<Props> = Props & {
|
|
375
|
+
children: ReactNode;
|
|
376
|
+
};
|
|
377
|
+
type UserGenerics<UserConfig extends Config = Config, UserParams extends ExtractConfigParams<UserConfig> = ExtractConfigParams<UserConfig>, UserData extends Data<UserParams["props"], UserParams["rootProps"]> | Data = Data<UserParams["props"], UserParams["rootProps"]>, UserAppState extends PrivateAppState<UserData> = PrivateAppState<UserData>, UserPublicAppState extends AppState<UserData> = AppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
|
|
378
|
+
UserConfig: UserConfig;
|
|
379
|
+
UserParams: UserParams;
|
|
380
|
+
UserProps: UserParams["props"];
|
|
381
|
+
UserRootProps: UserParams["rootProps"] & DefaultRootFieldProps;
|
|
382
|
+
UserData: UserData;
|
|
383
|
+
UserAppState: UserAppState;
|
|
384
|
+
UserPublicAppState: UserPublicAppState;
|
|
385
|
+
UserComponentData: UserComponentData;
|
|
386
|
+
UserField: UserParams["field"];
|
|
387
|
+
};
|
|
388
|
+
type ExtractField<UserField extends {
|
|
389
|
+
type: PropertyKey;
|
|
390
|
+
}, T extends UserField["type"]> = Extract<UserField, {
|
|
391
|
+
type: T;
|
|
392
|
+
}>;
|
|
393
|
+
|
|
394
|
+
type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
|
|
395
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
|
396
|
+
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
|
397
|
+
}>>) => JSX.Element;
|
|
398
|
+
type ResolveDataTrigger = "insert" | "replace" | "load" | "force" | "move";
|
|
399
|
+
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
|
400
|
+
props?: Partial<Props>;
|
|
401
|
+
};
|
|
402
|
+
interface ComponentConfigExtensions {
|
|
403
|
+
}
|
|
404
|
+
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.
|
|
405
|
+
UserField extends BaseField = {}> = {
|
|
406
|
+
render: PuckComponent<RenderProps>;
|
|
407
|
+
label?: string;
|
|
408
|
+
defaultProps?: FieldProps;
|
|
409
|
+
fields?: Fields<FieldProps, UserField>;
|
|
410
|
+
permissions?: Partial<Permissions>;
|
|
411
|
+
inline?: boolean;
|
|
412
|
+
resolveFields?: (data: DataShape, params: {
|
|
413
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
|
414
|
+
id: string;
|
|
415
|
+
}>;
|
|
416
|
+
fields: Fields<FieldProps>;
|
|
417
|
+
lastFields: Fields<FieldProps>;
|
|
418
|
+
lastData: DataShape | null;
|
|
419
|
+
metadata: ComponentMetadata;
|
|
420
|
+
appState: AppState;
|
|
421
|
+
parent: ComponentData | null;
|
|
422
|
+
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
|
423
|
+
resolveData?: (data: DataShape, params: {
|
|
424
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
|
425
|
+
id: string;
|
|
426
|
+
}>;
|
|
427
|
+
lastData: DataShape | null;
|
|
428
|
+
metadata: ComponentMetadata;
|
|
429
|
+
trigger: ResolveDataTrigger;
|
|
430
|
+
parent: ComponentData | null;
|
|
431
|
+
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
|
432
|
+
resolvePermissions?: (data: DataShape, params: {
|
|
433
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
|
434
|
+
id: string;
|
|
435
|
+
}>;
|
|
436
|
+
lastPermissions: Partial<Permissions>;
|
|
437
|
+
permissions: Partial<Permissions>;
|
|
438
|
+
appState: AppState;
|
|
439
|
+
lastData: DataShape | null;
|
|
440
|
+
parent: ComponentData | null;
|
|
441
|
+
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
|
442
|
+
metadata?: ComponentMetadata;
|
|
443
|
+
} & ComponentConfigExtensions;
|
|
444
|
+
type RootConfigInternal<RootProps extends DefaultComponentProps = DefaultComponentProps, UserField extends BaseField = {}> = Partial<ComponentConfigInternal<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>, UserField>>;
|
|
445
|
+
type Category<ComponentName> = {
|
|
446
|
+
components?: ComponentName[];
|
|
447
|
+
title?: string;
|
|
448
|
+
visible?: boolean;
|
|
449
|
+
defaultExpanded?: boolean;
|
|
450
|
+
};
|
|
451
|
+
type ConfigInternal<Props extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultComponentProps, CategoryName extends string = string, UserField extends {} = {}> = {
|
|
452
|
+
categories?: Record<CategoryName, Category<keyof Props>> & {
|
|
453
|
+
other?: Category<keyof Props>;
|
|
454
|
+
};
|
|
455
|
+
components: {
|
|
456
|
+
[ComponentName in keyof Props]: Omit<ComponentConfigInternal<Props[ComponentName], Props[ComponentName], Omit<ComponentData<Props[ComponentName]>, "type">, UserField>, "type">;
|
|
457
|
+
};
|
|
458
|
+
root?: RootConfigInternal<RootProps, UserField>;
|
|
459
|
+
};
|
|
460
|
+
type DefaultComponents = Record<string, any>;
|
|
461
|
+
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>;
|
|
462
|
+
type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends ConfigInternal<infer PropsOrParams, infer RootProps, infer CategoryName, infer UserField> ? {
|
|
463
|
+
props: PropsOrParams;
|
|
464
|
+
rootProps: RootProps & DefaultRootFieldProps;
|
|
465
|
+
categoryNames: CategoryName;
|
|
466
|
+
field: UserField extends {
|
|
467
|
+
type: string;
|
|
468
|
+
} ? UserField : Field;
|
|
469
|
+
} : never;
|
|
470
|
+
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
|
471
|
+
components?: Components;
|
|
472
|
+
root?: RootProps;
|
|
473
|
+
categories?: CategoryNames;
|
|
474
|
+
fields?: AssertHasValue<UserFields>;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
type BaseData<Props extends {
|
|
478
|
+
[key: string]: any;
|
|
479
|
+
} = {
|
|
480
|
+
[key: string]: any;
|
|
481
|
+
}> = {
|
|
482
|
+
readOnly?: Partial<Record<keyof Props, boolean>>;
|
|
483
|
+
};
|
|
484
|
+
type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
|
|
485
|
+
props: Props;
|
|
486
|
+
};
|
|
487
|
+
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
|
488
|
+
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
|
489
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, Components extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
|
|
490
|
+
type: Name;
|
|
491
|
+
props: WithDeepSlots<WithId<Props>, Content<Components>>;
|
|
492
|
+
} & BaseData<Props>;
|
|
493
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
|
494
|
+
type: Name;
|
|
495
|
+
props: Props & {
|
|
496
|
+
id?: string;
|
|
497
|
+
};
|
|
498
|
+
} & BaseData<Props>;
|
|
499
|
+
type ComponentDataMap<Components extends DefaultComponents = DefaultComponents> = {
|
|
500
|
+
[K in keyof Components]: ComponentData<Components[K], K extends string ? K : never, Components>;
|
|
501
|
+
}[keyof Components];
|
|
502
|
+
type Content<PropsMap extends {
|
|
503
|
+
[key: string]: DefaultComponentProps;
|
|
504
|
+
} = {
|
|
505
|
+
[key: string]: DefaultComponentProps;
|
|
506
|
+
}> = ComponentDataMap<PropsMap>[];
|
|
507
|
+
type Data<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
|
508
|
+
root: WithDeepSlots<RootData<RootProps>, Content<Components>>;
|
|
509
|
+
content: Content<Components>;
|
|
510
|
+
zones?: Record<string, Content<Components>>;
|
|
511
|
+
};
|
|
512
|
+
type Metadata = {
|
|
513
|
+
[key: string]: any;
|
|
514
|
+
};
|
|
515
|
+
interface PuckMetadata extends Metadata {
|
|
516
|
+
}
|
|
517
|
+
interface ComponentMetadata extends PuckMetadata {
|
|
518
|
+
}
|
|
519
|
+
interface FieldMetadata extends Metadata {
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
type ItemWithId = {
|
|
523
|
+
_arrayId: string;
|
|
524
|
+
_originalIndex: number;
|
|
525
|
+
_currentIndex: number;
|
|
526
|
+
};
|
|
527
|
+
type ArrayState = {
|
|
528
|
+
items: ItemWithId[];
|
|
529
|
+
openId: string;
|
|
530
|
+
};
|
|
531
|
+
type UiState = {
|
|
532
|
+
leftSideBarVisible: boolean;
|
|
533
|
+
rightSideBarVisible: boolean;
|
|
534
|
+
leftSideBarWidth?: number | null;
|
|
535
|
+
rightSideBarWidth?: number | null;
|
|
536
|
+
mobilePanelExpanded?: boolean;
|
|
537
|
+
itemSelector: ItemSelector | null;
|
|
538
|
+
arrayState: Record<string, ArrayState | undefined>;
|
|
539
|
+
previewMode: "interactive" | "edit";
|
|
540
|
+
componentList: Record<string, {
|
|
541
|
+
components?: string[];
|
|
542
|
+
title?: string;
|
|
543
|
+
visible?: boolean;
|
|
544
|
+
expanded?: boolean;
|
|
545
|
+
}>;
|
|
546
|
+
isDragging: boolean;
|
|
547
|
+
viewports: {
|
|
548
|
+
current: {
|
|
549
|
+
width: number | "100%";
|
|
550
|
+
height: number | "auto";
|
|
551
|
+
};
|
|
552
|
+
controlsVisible: boolean;
|
|
553
|
+
options: Viewport[];
|
|
554
|
+
};
|
|
555
|
+
field: {
|
|
556
|
+
focus?: string | null;
|
|
557
|
+
metadata?: Record<string, any>;
|
|
558
|
+
};
|
|
559
|
+
plugin: {
|
|
560
|
+
current: string | null;
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
type AppState<UserData extends Data = Data> = {
|
|
564
|
+
data: UserData;
|
|
565
|
+
ui: UiState;
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
type ZoneType = "root" | "dropzone" | "slot";
|
|
569
|
+
type PuckNodeData = {
|
|
570
|
+
data: ComponentData;
|
|
571
|
+
flatData: ComponentData;
|
|
572
|
+
parentId: string | null;
|
|
573
|
+
zone: string;
|
|
574
|
+
path: string[];
|
|
575
|
+
};
|
|
576
|
+
type PuckZoneData = {
|
|
577
|
+
contentIds: string[];
|
|
578
|
+
type: ZoneType;
|
|
579
|
+
};
|
|
580
|
+
type NodeIndex = Record<string, PuckNodeData>;
|
|
581
|
+
type ZoneIndex = Record<string, PuckZoneData>;
|
|
582
|
+
type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
|
583
|
+
indexes: {
|
|
584
|
+
nodes: NodeIndex;
|
|
585
|
+
zones: ZoneIndex;
|
|
586
|
+
};
|
|
587
|
+
};
|
|
588
|
+
type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined;
|
|
589
|
+
/**
|
|
590
|
+
* Recursively walk T and replace Slots with SlotComponents
|
|
591
|
+
*/
|
|
592
|
+
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 ? {
|
|
593
|
+
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
|
594
|
+
} : T;
|
|
595
|
+
type FieldsExtension = {
|
|
596
|
+
[Type in string]: {
|
|
597
|
+
type: Type;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
|
|
601
|
+
type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
|
|
602
|
+
type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
|
|
603
|
+
never
|
|
604
|
+
] ? False : True;
|
|
605
|
+
type RenderFunc<Props extends {
|
|
606
|
+
[key: string]: any;
|
|
607
|
+
} = {
|
|
608
|
+
children: ReactNode;
|
|
609
|
+
}> = (props: Props) => ReactElement;
|
|
610
|
+
|
|
611
|
+
type MapFnParams<ThisField = Field> = {
|
|
612
|
+
value: any;
|
|
613
|
+
parentId: string;
|
|
614
|
+
propName: string;
|
|
615
|
+
field: ThisField;
|
|
616
|
+
propPath: string;
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
type FieldTransformFnParams<T> = Omit<MapFnParams<T>, "parentId"> & {
|
|
620
|
+
isReadOnly: boolean;
|
|
621
|
+
componentId: string;
|
|
622
|
+
};
|
|
623
|
+
type FieldTransformFn<T> = (params: FieldTransformFnParams<T>) => any;
|
|
624
|
+
type FieldTransforms<UserConfig extends Config = Config<{
|
|
625
|
+
fields: {};
|
|
626
|
+
}>, // Setting fields: {} helps TS choose default field types
|
|
627
|
+
G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
|
628
|
+
type: string;
|
|
629
|
+
} = Field | G["UserField"]> = Partial<{
|
|
630
|
+
[Type in UserField["type"]]: FieldTransformFn<ExtractField<UserField, Type>>;
|
|
631
|
+
}>;
|
|
632
|
+
|
|
633
|
+
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
|
|
634
|
+
type OverrideKey = (typeof overrideKeys)[number];
|
|
635
|
+
type OverridesGeneric<Shape extends {
|
|
636
|
+
[key in OverrideKey]: any;
|
|
637
|
+
}> = Shape;
|
|
638
|
+
type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
|
639
|
+
fieldTypes: Partial<FieldRenderFunctions<UserConfig>>;
|
|
640
|
+
header: RenderFunc<{
|
|
641
|
+
actions: ReactNode;
|
|
642
|
+
children: ReactNode;
|
|
643
|
+
}>;
|
|
644
|
+
actionBar: RenderFunc<{
|
|
645
|
+
label?: string;
|
|
646
|
+
children: ReactNode;
|
|
647
|
+
parentAction: ReactNode;
|
|
648
|
+
}>;
|
|
649
|
+
headerActions: RenderFunc<{
|
|
650
|
+
children: ReactNode;
|
|
651
|
+
}>;
|
|
652
|
+
preview: RenderFunc;
|
|
653
|
+
fields: RenderFunc<{
|
|
654
|
+
children: ReactNode;
|
|
655
|
+
isLoading: boolean;
|
|
656
|
+
itemSelector?: ItemSelector | null;
|
|
657
|
+
}>;
|
|
658
|
+
fieldLabel: RenderFunc<{
|
|
659
|
+
children?: ReactNode;
|
|
660
|
+
icon?: ReactNode;
|
|
661
|
+
label: string;
|
|
662
|
+
el?: "label" | "div";
|
|
663
|
+
readOnly?: boolean;
|
|
664
|
+
className?: string;
|
|
665
|
+
}>;
|
|
666
|
+
components: RenderFunc;
|
|
667
|
+
componentItem: RenderFunc<{
|
|
668
|
+
children: ReactNode;
|
|
669
|
+
name: string;
|
|
670
|
+
}>;
|
|
671
|
+
drawer: RenderFunc;
|
|
672
|
+
drawerItem: RenderFunc<{
|
|
673
|
+
children: ReactNode;
|
|
674
|
+
name: string;
|
|
675
|
+
}>;
|
|
676
|
+
iframe: RenderFunc<{
|
|
677
|
+
children: ReactNode;
|
|
678
|
+
document?: Document;
|
|
679
|
+
}>;
|
|
680
|
+
outline: RenderFunc;
|
|
681
|
+
componentOverlay: RenderFunc<{
|
|
682
|
+
children: ReactNode;
|
|
683
|
+
hover: boolean;
|
|
684
|
+
isSelected: boolean;
|
|
685
|
+
componentId: string;
|
|
686
|
+
componentType: string;
|
|
687
|
+
}>;
|
|
688
|
+
puck: RenderFunc;
|
|
689
|
+
}>;
|
|
690
|
+
type FieldRenderFunctions<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
|
691
|
+
type: string;
|
|
692
|
+
} = Field | G["UserField"]> = Omit<{
|
|
693
|
+
[Type in UserField["type"]]: React.FunctionComponent<FieldProps<ExtractField<UserField, Type>, any> & {
|
|
694
|
+
children: ReactNode;
|
|
695
|
+
name: string;
|
|
696
|
+
}>;
|
|
697
|
+
}, "custom">;
|
|
698
|
+
|
|
699
|
+
type DragAxis = "dynamic" | "y" | "x";
|
|
700
|
+
|
|
701
|
+
type iconTypes = "Smartphone" | "Monitor" | "Tablet";
|
|
702
|
+
type Viewport = {
|
|
703
|
+
width: number | "100%";
|
|
704
|
+
height?: number | "auto";
|
|
705
|
+
label?: string;
|
|
706
|
+
icon?: iconTypes | ReactNode;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
type Permissions = {
|
|
710
|
+
drag: boolean;
|
|
711
|
+
duplicate: boolean;
|
|
712
|
+
delete: boolean;
|
|
713
|
+
edit: boolean;
|
|
714
|
+
insert: boolean;
|
|
715
|
+
} & Record<string, boolean>;
|
|
716
|
+
type Plugin<UserConfig extends Config = Config> = {
|
|
717
|
+
name?: string;
|
|
718
|
+
label?: string;
|
|
719
|
+
icon?: ReactNode;
|
|
720
|
+
render?: () => ReactElement;
|
|
721
|
+
overrides?: Partial<Overrides<UserConfig>>;
|
|
722
|
+
fieldTransforms?: FieldTransforms<UserConfig>;
|
|
723
|
+
mobilePanelHeight?: "toggle" | "min-content";
|
|
724
|
+
};
|
|
725
|
+
type Slot<Props extends {
|
|
726
|
+
[key: string]: DefaultComponentProps;
|
|
727
|
+
} = {
|
|
728
|
+
[key: string]: DefaultComponentProps;
|
|
729
|
+
}> = {
|
|
730
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
|
731
|
+
}[keyof Props][];
|
|
732
|
+
|
|
733
|
+
declare const headingAnalyzer: Plugin;
|
|
734
|
+
|
|
735
|
+
export { headingAnalyzer as default };
|