@measured/puck-plugin-heading-analyzer 0.21.0-canary.a5160e5d → 0.21.0-canary.ac9eba2f

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/index.d.mts CHANGED
@@ -1,72 +1,269 @@
1
- import { ReactElement, CSSProperties, ReactNode, JSX } from 'react';
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';
2
17
 
3
18
  type ItemSelector = {
4
19
  index: number;
5
20
  zone?: string;
6
21
  };
7
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
+
8
183
  type FieldOption = {
9
184
  label: string;
10
185
  value: string | number | boolean | undefined | null | object;
11
186
  };
12
187
  type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
13
- type BaseField = {
188
+ interface BaseField {
14
189
  label?: string;
15
190
  labelIcon?: ReactElement;
16
- metadata?: Metadata;
191
+ metadata?: FieldMetadata;
17
192
  visible?: boolean;
18
- };
19
- type TextField = BaseField & {
193
+ }
194
+ interface TextField extends BaseField {
20
195
  type: "text";
21
196
  placeholder?: string;
22
197
  contentEditable?: boolean;
23
- };
24
- type NumberField = BaseField & {
198
+ }
199
+ interface NumberField extends BaseField {
25
200
  type: "number";
26
201
  placeholder?: string;
27
202
  min?: number;
28
203
  max?: number;
29
204
  step?: number;
30
- };
31
- type TextareaField = BaseField & {
205
+ }
206
+ interface TextareaField extends BaseField {
32
207
  type: "textarea";
33
208
  placeholder?: string;
34
209
  contentEditable?: boolean;
35
- };
36
- type SelectField = BaseField & {
210
+ }
211
+ interface SelectField extends BaseField {
37
212
  type: "select";
38
213
  options: FieldOptions;
39
- };
40
- type RadioField = BaseField & {
214
+ }
215
+ interface RadioField extends BaseField {
41
216
  type: "radio";
42
217
  options: FieldOptions;
43
- };
44
- type ArrayField<Props extends {
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 {
45
242
  [key: string]: any;
46
243
  }[] = {
47
244
  [key: string]: any;
48
- }[], UserField extends {} = {}> = BaseField & {
245
+ }[], UserField extends {} = {}> extends BaseField {
49
246
  type: "array";
50
247
  arrayFields: {
51
248
  [SubPropName in keyof Props[0]]: UserField extends {
52
249
  type: PropertyKey;
53
250
  } ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
54
251
  };
55
- defaultItemProps?: Props[0];
56
- getItemSummary?: (item: Props[0], index?: number) => string;
252
+ defaultItemProps?: Props[0] | ((index: number) => Props[0]);
253
+ getItemSummary?: (item: Props[0], index?: number) => ReactNode;
57
254
  max?: number;
58
255
  min?: number;
59
- };
60
- type ObjectField<Props extends any = {
256
+ }
257
+ interface ObjectField<Props extends any = {
61
258
  [key: string]: any;
62
- }, UserField extends {} = {}> = BaseField & {
259
+ }, UserField extends {} = {}> extends BaseField {
63
260
  type: "object";
64
261
  objectFields: {
65
262
  [SubPropName in keyof Props]: UserField extends {
66
263
  type: PropertyKey;
67
264
  } ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
68
265
  };
69
- };
266
+ }
70
267
  type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
71
268
  name: string;
72
269
  fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
@@ -80,14 +277,14 @@ type ExternalFieldWithAdaptor<Props extends any = {
80
277
  placeholder?: string;
81
278
  adaptor: Adaptor<any, any, Props>;
82
279
  adaptorParams?: object;
83
- getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
280
+ getItemSummary: (item: NotUndefined<Props>, index?: number) => ReactNode;
84
281
  };
85
282
  type CacheOpts = {
86
283
  enabled?: boolean;
87
284
  };
88
- type ExternalField<Props extends any = {
285
+ interface ExternalField<Props extends any = {
89
286
  [key: string]: any;
90
- }> = BaseField & {
287
+ }> extends BaseField {
91
288
  type: "external";
92
289
  cache?: CacheOpts;
93
290
  placeholder?: string;
@@ -97,7 +294,7 @@ type ExternalField<Props extends any = {
97
294
  }) => Promise<any[] | null>;
98
295
  mapProp?: (value: any) => Props;
99
296
  mapRow?: (value: any) => Record<string, string | number | ReactElement>;
100
- getItemSummary?: (item: NotUndefined<Props>, index?: number) => string;
297
+ getItemSummary?: (item: NotUndefined<Props>, index?: number) => ReactNode;
101
298
  showSearch?: boolean;
102
299
  renderFooter?: (props: {
103
300
  items: any[];
@@ -105,7 +302,7 @@ type ExternalField<Props extends any = {
105
302
  initialQuery?: string;
106
303
  filterFields?: Record<string, Field>;
107
304
  initialFilters?: Record<string, any>;
108
- };
305
+ }
109
306
  type CustomFieldRender<Value extends any> = (props: {
110
307
  field: CustomField<Value>;
111
308
  name: string;
@@ -114,17 +311,18 @@ type CustomFieldRender<Value extends any> = (props: {
114
311
  onChange: (value: Value) => void;
115
312
  readOnly?: boolean;
116
313
  }) => ReactElement;
117
- type CustomField<Value extends any> = BaseField & {
314
+ interface CustomField<Value extends any> extends BaseField {
118
315
  type: "custom";
119
316
  render: CustomFieldRender<Value>;
120
317
  contentEditable?: boolean;
121
- };
122
- type SlotField = BaseField & {
318
+ key?: string;
319
+ }
320
+ interface SlotField extends BaseField {
123
321
  type: "slot";
124
322
  allow?: string[];
125
323
  disallow?: string[];
126
- };
127
- type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
324
+ }
325
+ type Field<ValueType = any, UserField extends {} = {}> = TextField | RichtextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
128
326
  [key: string]: any;
129
327
  }[] ? ValueType : never, UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
130
328
  type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps, UserField extends {} = {}> = {
@@ -145,13 +343,15 @@ type DropZoneProps = {
145
343
  allow?: string[];
146
344
  disallow?: string[];
147
345
  style?: CSSProperties;
148
- minEmptyHeight?: number;
346
+ minEmptyHeight?: CSSProperties["minHeight"] | number;
149
347
  className?: string;
150
348
  collisionAxis?: DragAxis;
349
+ as?: ElementType;
350
+ ref?: Ref<any>;
151
351
  };
152
352
 
153
353
  type PuckContext = {
154
- renderDropZone: React.FC<DropZoneProps>;
354
+ renderDropZone: (props: DropZoneProps) => React.ReactNode;
155
355
  metadata: Metadata;
156
356
  isEditing: boolean;
157
357
  dragRef: ((element: Element | null) => void) | null;
@@ -199,6 +399,8 @@ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
199
399
  type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
200
400
  props?: Partial<Props>;
201
401
  };
402
+ interface ComponentConfigExtensions {
403
+ }
202
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.
203
405
  UserField extends BaseField = {}> = {
204
406
  render: PuckComponent<RenderProps>;
@@ -214,7 +416,7 @@ UserField extends BaseField = {}> = {
214
416
  fields: Fields<FieldProps>;
215
417
  lastFields: Fields<FieldProps>;
216
418
  lastData: DataShape | null;
217
- metadata: Metadata;
419
+ metadata: ComponentMetadata;
218
420
  appState: AppState;
219
421
  parent: ComponentData | null;
220
422
  }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
@@ -223,7 +425,7 @@ UserField extends BaseField = {}> = {
223
425
  id: string;
224
426
  }>;
225
427
  lastData: DataShape | null;
226
- metadata: Metadata;
428
+ metadata: ComponentMetadata;
227
429
  trigger: ResolveDataTrigger;
228
430
  }) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
229
431
  resolvePermissions?: (data: DataShape, params: {
@@ -234,9 +436,10 @@ UserField extends BaseField = {}> = {
234
436
  permissions: Partial<Permissions>;
235
437
  appState: AppState;
236
438
  lastData: DataShape | null;
439
+ parent: ComponentData | null;
237
440
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
238
- metadata?: Metadata;
239
- };
441
+ metadata?: ComponentMetadata;
442
+ } & ComponentConfigExtensions;
240
443
  type RootConfigInternal<RootProps extends DefaultComponentProps = DefaultComponentProps, UserField extends BaseField = {}> = Partial<ComponentConfigInternal<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>, UserField>>;
241
444
  type Category<ComponentName> = {
242
445
  components?: ComponentName[];
@@ -263,6 +466,12 @@ type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends
263
466
  type: string;
264
467
  } ? UserField : Field;
265
468
  } : never;
469
+ type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
470
+ components?: Components;
471
+ root?: RootProps;
472
+ categories?: CategoryNames;
473
+ fields?: AssertHasValue<UserFields>;
474
+ };
266
475
 
267
476
  type BaseData<Props extends {
268
477
  [key: string]: any;
@@ -302,6 +511,12 @@ type Data<Components extends DefaultComponents = DefaultComponents, RootProps ex
302
511
  type Metadata = {
303
512
  [key: string]: any;
304
513
  };
514
+ interface PuckMetadata extends Metadata {
515
+ }
516
+ interface ComponentMetadata extends PuckMetadata {
517
+ }
518
+ interface FieldMetadata extends Metadata {
519
+ }
305
520
 
306
521
  type ItemWithId = {
307
522
  _arrayId: string;
@@ -336,6 +551,7 @@ type UiState = {
336
551
  };
337
552
  field: {
338
553
  focus?: string | null;
554
+ metadata?: Record<string, any>;
339
555
  };
340
556
  };
341
557
  type AppState<UserData extends Data = Data> = {
@@ -370,12 +586,6 @@ type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined
370
586
  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 ? {
371
587
  [K in keyof T]: WithDeepSlots<T[K], SlotType>;
372
588
  } : T;
373
- type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = any, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
374
- components?: Components;
375
- root?: RootProps;
376
- categories?: CategoryNames;
377
- fields?: AssertHasValue<UserFields>;
378
- };
379
589
  type FieldsExtension = {
380
590
  [Type in string]: {
381
591
  type: Type;