@measured/puck-plugin-heading-analyzer 0.20.0-canary.755737e8 → 0.20.0-canary.77cef35d

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
@@ -7,7 +7,7 @@ type ItemSelector = {
7
7
 
8
8
  type FieldOption = {
9
9
  label: string;
10
- value: string | number | boolean;
10
+ value: string | number | boolean | undefined | null | object;
11
11
  };
12
12
  type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
13
13
  type BaseField = {
@@ -19,6 +19,7 @@ type BaseField = {
19
19
  type TextField = BaseField & {
20
20
  type: "text";
21
21
  placeholder?: string;
22
+ contentEditable?: boolean;
22
23
  };
23
24
  type NumberField = BaseField & {
24
25
  type: "number";
@@ -30,6 +31,7 @@ type NumberField = BaseField & {
30
31
  type TextareaField = BaseField & {
31
32
  type: "textarea";
32
33
  placeholder?: string;
34
+ contentEditable?: boolean;
33
35
  };
34
36
  type SelectField = BaseField & {
35
37
  type: "select";
@@ -39,11 +41,11 @@ type RadioField = BaseField & {
39
41
  type: "radio";
40
42
  options: FieldOptions;
41
43
  };
42
- type ArrayField<Props extends {
44
+ type ArrayField<Props extends any = {
43
45
  [key: string]: any;
44
- } = {
46
+ }> = Props extends {
45
47
  [key: string]: any;
46
- }> = BaseField & {
48
+ } ? BaseField & {
47
49
  type: "array";
48
50
  arrayFields: {
49
51
  [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
@@ -52,14 +54,12 @@ type ArrayField<Props extends {
52
54
  getItemSummary?: (item: Props[0], index?: number) => string;
53
55
  max?: number;
54
56
  min?: number;
55
- };
56
- type ObjectField<Props extends {
57
- [key: string]: any;
58
- } = {
57
+ } : never;
58
+ type ObjectField<Props extends any = {
59
59
  [key: string]: any;
60
60
  }> = BaseField & {
61
61
  type: "object";
62
- objectFields: Props extends any[] ? never : {
62
+ objectFields: {
63
63
  [SubPropName in keyof Props]: Field<Props[SubPropName]>;
64
64
  };
65
65
  };
@@ -68,20 +68,17 @@ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, Pr
68
68
  fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
69
69
  mapProp?: (value: TableShape) => PropShape;
70
70
  };
71
- type ExternalFieldWithAdaptor<Props extends {
72
- [key: string]: any;
73
- } = {
71
+ type NotUndefined<T> = T extends undefined ? Record<string, any> : T;
72
+ type ExternalFieldWithAdaptor<Props extends any = {
74
73
  [key: string]: any;
75
74
  }> = BaseField & {
76
75
  type: "external";
77
76
  placeholder?: string;
78
77
  adaptor: Adaptor<any, any, Props>;
79
78
  adaptorParams?: object;
80
- getItemSummary: (item: Props, index?: number) => string;
79
+ getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
81
80
  };
82
- type ExternalField<Props extends {
83
- [key: string]: any;
84
- } = {
81
+ type ExternalField<Props extends any = {
85
82
  [key: string]: any;
86
83
  }> = BaseField & {
87
84
  type: "external";
@@ -92,7 +89,7 @@ type ExternalField<Props extends {
92
89
  }) => Promise<any[] | null>;
93
90
  mapProp?: (value: any) => Props;
94
91
  mapRow?: (value: any) => Record<string, string | number | ReactElement>;
95
- getItemSummary?: (item: Props, index?: number) => string;
92
+ getItemSummary?: (item: NotUndefined<Props>, index?: number) => string;
96
93
  showSearch?: boolean;
97
94
  renderFooter?: (props: {
98
95
  items: any[];
@@ -112,21 +109,14 @@ type CustomFieldRender<Value extends any> = (props: {
112
109
  type CustomField<Value extends any> = BaseField & {
113
110
  type: "custom";
114
111
  render: CustomFieldRender<Value>;
112
+ contentEditable?: boolean;
115
113
  };
116
114
  type SlotField = BaseField & {
117
115
  type: "slot";
118
116
  allow?: string[];
119
117
  disallow?: string[];
120
118
  };
121
- type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
122
- [key: string]: any;
123
- } ? Props : any> | ObjectField<Props extends {
124
- [key: string]: any;
125
- } ? Props : any> | ExternalField<Props extends {
126
- [key: string]: any;
127
- } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
128
- [key: string]: any;
129
- } ? Props : any> | CustomField<Props> | SlotField;
119
+ type Field<ValueType = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType> | ObjectField<ValueType> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
130
120
  type FieldProps<F = Field<any>, ValueType = any> = {
131
121
  field: F;
132
122
  value: ValueType;
@@ -135,6 +125,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
135
125
  readOnly?: boolean;
136
126
  };
137
127
 
128
+ type ExtractField<T extends Field["type"]> = Extract<Field, {
129
+ type: T;
130
+ }>;
131
+
138
132
  type Metadata = {
139
133
  [key: string]: any;
140
134
  };
@@ -142,6 +136,7 @@ type Metadata = {
142
136
  type ItemWithId = {
143
137
  _arrayId: string;
144
138
  _originalIndex: number;
139
+ _currentIndex: number;
145
140
  };
146
141
  type ArrayState = {
147
142
  items: ItemWithId[];
@@ -150,6 +145,8 @@ type ArrayState = {
150
145
  type UiState = {
151
146
  leftSideBarVisible: boolean;
152
147
  rightSideBarVisible: boolean;
148
+ leftSideBarWidth?: number | null;
149
+ rightSideBarWidth?: number | null;
153
150
  itemSelector: ItemSelector | null;
154
151
  arrayState: Record<string, ArrayState | undefined>;
155
152
  previewMode: "interactive" | "edit";
@@ -179,7 +176,24 @@ type RenderFunc<Props extends {
179
176
  children: ReactNode;
180
177
  }> = (props: Props) => ReactElement;
181
178
 
182
- declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
179
+ type MapFnParams<ThisField = Field> = {
180
+ value: any;
181
+ parentId: string;
182
+ propName: string;
183
+ field: ThisField;
184
+ propPath: string;
185
+ };
186
+
187
+ type FieldTransformFnParams<T> = Omit<MapFnParams<T>, "parentId"> & {
188
+ isReadOnly: boolean;
189
+ componentId: string;
190
+ };
191
+ type FieldTransformFn<T = any> = (params: FieldTransformFnParams<T>) => any;
192
+ type FieldTransforms = Partial<{
193
+ [FieldType in Field["type"]]: FieldTransformFn<ExtractField<FieldType>>;
194
+ }>;
195
+
196
+ declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
183
197
  type OverrideKey = (typeof overrideKeys)[number];
184
198
  type OverridesGeneric<Shape extends {
185
199
  [key in OverrideKey]: any;
@@ -217,11 +231,23 @@ type Overrides = OverridesGeneric<{
217
231
  children: ReactNode;
218
232
  name: string;
219
233
  }>;
234
+ drawer: RenderFunc;
235
+ drawerItem: RenderFunc<{
236
+ children: ReactNode;
237
+ name: string;
238
+ }>;
220
239
  iframe: RenderFunc<{
221
240
  children: ReactNode;
222
241
  document?: Document;
223
242
  }>;
224
243
  outline: RenderFunc;
244
+ componentOverlay: RenderFunc<{
245
+ children: ReactNode;
246
+ hover: boolean;
247
+ isSelected: boolean;
248
+ componentId: string;
249
+ componentType: string;
250
+ }>;
225
251
  puck: RenderFunc;
226
252
  }>;
227
253
  type FieldRenderFunctions = Omit<{
@@ -252,6 +278,7 @@ type Plugin = {
252
278
  icon?: ReactNode;
253
279
  render?: () => ReactElement;
254
280
  overrides?: Partial<Overrides>;
281
+ fieldTransforms?: FieldTransforms;
255
282
  };
256
283
 
257
284
  declare const headingAnalyzer: Plugin;
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ type ItemSelector = {
7
7
 
8
8
  type FieldOption = {
9
9
  label: string;
10
- value: string | number | boolean;
10
+ value: string | number | boolean | undefined | null | object;
11
11
  };
12
12
  type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
13
13
  type BaseField = {
@@ -19,6 +19,7 @@ type BaseField = {
19
19
  type TextField = BaseField & {
20
20
  type: "text";
21
21
  placeholder?: string;
22
+ contentEditable?: boolean;
22
23
  };
23
24
  type NumberField = BaseField & {
24
25
  type: "number";
@@ -30,6 +31,7 @@ type NumberField = BaseField & {
30
31
  type TextareaField = BaseField & {
31
32
  type: "textarea";
32
33
  placeholder?: string;
34
+ contentEditable?: boolean;
33
35
  };
34
36
  type SelectField = BaseField & {
35
37
  type: "select";
@@ -39,11 +41,11 @@ type RadioField = BaseField & {
39
41
  type: "radio";
40
42
  options: FieldOptions;
41
43
  };
42
- type ArrayField<Props extends {
44
+ type ArrayField<Props extends any = {
43
45
  [key: string]: any;
44
- } = {
46
+ }> = Props extends {
45
47
  [key: string]: any;
46
- }> = BaseField & {
48
+ } ? BaseField & {
47
49
  type: "array";
48
50
  arrayFields: {
49
51
  [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
@@ -52,14 +54,12 @@ type ArrayField<Props extends {
52
54
  getItemSummary?: (item: Props[0], index?: number) => string;
53
55
  max?: number;
54
56
  min?: number;
55
- };
56
- type ObjectField<Props extends {
57
- [key: string]: any;
58
- } = {
57
+ } : never;
58
+ type ObjectField<Props extends any = {
59
59
  [key: string]: any;
60
60
  }> = BaseField & {
61
61
  type: "object";
62
- objectFields: Props extends any[] ? never : {
62
+ objectFields: {
63
63
  [SubPropName in keyof Props]: Field<Props[SubPropName]>;
64
64
  };
65
65
  };
@@ -68,20 +68,17 @@ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, Pr
68
68
  fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
69
69
  mapProp?: (value: TableShape) => PropShape;
70
70
  };
71
- type ExternalFieldWithAdaptor<Props extends {
72
- [key: string]: any;
73
- } = {
71
+ type NotUndefined<T> = T extends undefined ? Record<string, any> : T;
72
+ type ExternalFieldWithAdaptor<Props extends any = {
74
73
  [key: string]: any;
75
74
  }> = BaseField & {
76
75
  type: "external";
77
76
  placeholder?: string;
78
77
  adaptor: Adaptor<any, any, Props>;
79
78
  adaptorParams?: object;
80
- getItemSummary: (item: Props, index?: number) => string;
79
+ getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
81
80
  };
82
- type ExternalField<Props extends {
83
- [key: string]: any;
84
- } = {
81
+ type ExternalField<Props extends any = {
85
82
  [key: string]: any;
86
83
  }> = BaseField & {
87
84
  type: "external";
@@ -92,7 +89,7 @@ type ExternalField<Props extends {
92
89
  }) => Promise<any[] | null>;
93
90
  mapProp?: (value: any) => Props;
94
91
  mapRow?: (value: any) => Record<string, string | number | ReactElement>;
95
- getItemSummary?: (item: Props, index?: number) => string;
92
+ getItemSummary?: (item: NotUndefined<Props>, index?: number) => string;
96
93
  showSearch?: boolean;
97
94
  renderFooter?: (props: {
98
95
  items: any[];
@@ -112,21 +109,14 @@ type CustomFieldRender<Value extends any> = (props: {
112
109
  type CustomField<Value extends any> = BaseField & {
113
110
  type: "custom";
114
111
  render: CustomFieldRender<Value>;
112
+ contentEditable?: boolean;
115
113
  };
116
114
  type SlotField = BaseField & {
117
115
  type: "slot";
118
116
  allow?: string[];
119
117
  disallow?: string[];
120
118
  };
121
- type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
122
- [key: string]: any;
123
- } ? Props : any> | ObjectField<Props extends {
124
- [key: string]: any;
125
- } ? Props : any> | ExternalField<Props extends {
126
- [key: string]: any;
127
- } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
128
- [key: string]: any;
129
- } ? Props : any> | CustomField<Props> | SlotField;
119
+ type Field<ValueType = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType> | ObjectField<ValueType> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
130
120
  type FieldProps<F = Field<any>, ValueType = any> = {
131
121
  field: F;
132
122
  value: ValueType;
@@ -135,6 +125,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
135
125
  readOnly?: boolean;
136
126
  };
137
127
 
128
+ type ExtractField<T extends Field["type"]> = Extract<Field, {
129
+ type: T;
130
+ }>;
131
+
138
132
  type Metadata = {
139
133
  [key: string]: any;
140
134
  };
@@ -142,6 +136,7 @@ type Metadata = {
142
136
  type ItemWithId = {
143
137
  _arrayId: string;
144
138
  _originalIndex: number;
139
+ _currentIndex: number;
145
140
  };
146
141
  type ArrayState = {
147
142
  items: ItemWithId[];
@@ -150,6 +145,8 @@ type ArrayState = {
150
145
  type UiState = {
151
146
  leftSideBarVisible: boolean;
152
147
  rightSideBarVisible: boolean;
148
+ leftSideBarWidth?: number | null;
149
+ rightSideBarWidth?: number | null;
153
150
  itemSelector: ItemSelector | null;
154
151
  arrayState: Record<string, ArrayState | undefined>;
155
152
  previewMode: "interactive" | "edit";
@@ -179,7 +176,24 @@ type RenderFunc<Props extends {
179
176
  children: ReactNode;
180
177
  }> = (props: Props) => ReactElement;
181
178
 
182
- declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
179
+ type MapFnParams<ThisField = Field> = {
180
+ value: any;
181
+ parentId: string;
182
+ propName: string;
183
+ field: ThisField;
184
+ propPath: string;
185
+ };
186
+
187
+ type FieldTransformFnParams<T> = Omit<MapFnParams<T>, "parentId"> & {
188
+ isReadOnly: boolean;
189
+ componentId: string;
190
+ };
191
+ type FieldTransformFn<T = any> = (params: FieldTransformFnParams<T>) => any;
192
+ type FieldTransforms = Partial<{
193
+ [FieldType in Field["type"]]: FieldTransformFn<ExtractField<FieldType>>;
194
+ }>;
195
+
196
+ declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
183
197
  type OverrideKey = (typeof overrideKeys)[number];
184
198
  type OverridesGeneric<Shape extends {
185
199
  [key in OverrideKey]: any;
@@ -217,11 +231,23 @@ type Overrides = OverridesGeneric<{
217
231
  children: ReactNode;
218
232
  name: string;
219
233
  }>;
234
+ drawer: RenderFunc;
235
+ drawerItem: RenderFunc<{
236
+ children: ReactNode;
237
+ name: string;
238
+ }>;
220
239
  iframe: RenderFunc<{
221
240
  children: ReactNode;
222
241
  document?: Document;
223
242
  }>;
224
243
  outline: RenderFunc;
244
+ componentOverlay: RenderFunc<{
245
+ children: ReactNode;
246
+ hover: boolean;
247
+ isSelected: boolean;
248
+ componentId: string;
249
+ componentType: string;
250
+ }>;
225
251
  puck: RenderFunc;
226
252
  }>;
227
253
  type FieldRenderFunctions = Omit<{
@@ -252,6 +278,7 @@ type Plugin = {
252
278
  icon?: ReactNode;
253
279
  render?: () => ReactElement;
254
280
  overrides?: Partial<Overrides>;
281
+ fieldTransforms?: FieldTransforms;
255
282
  };
256
283
 
257
284
  declare const headingAnalyzer: Plugin;