@measured/puck-plugin-heading-analyzer 0.16.0-canary.538cb05 → 0.16.0-canary.53c8bfc

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,229 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+
3
+ type ItemSelector = {
4
+ index: number;
5
+ zone?: string;
6
+ };
7
+
8
+ type iconTypes = "Smartphone" | "Monitor" | "Tablet";
9
+ type Viewport = {
10
+ width: number;
11
+ height?: number | "auto";
12
+ label?: string;
13
+ icon?: iconTypes | ReactNode;
14
+ };
15
+
16
+ type ItemWithId = {
17
+ _arrayId: string;
18
+ _originalIndex: number;
19
+ };
20
+ type ArrayState = {
21
+ items: ItemWithId[];
22
+ openId: string;
23
+ };
24
+ type UiState = {
25
+ leftSideBarVisible: boolean;
26
+ rightSideBarVisible: boolean;
27
+ itemSelector: ItemSelector | null;
28
+ arrayState: Record<string, ArrayState | undefined>;
29
+ componentList: Record<string, {
30
+ components?: string[];
31
+ title?: string;
32
+ visible?: boolean;
33
+ expanded?: boolean;
34
+ }>;
35
+ isDragging: boolean;
36
+ viewports: {
37
+ current: {
38
+ width: number;
39
+ height: number | "auto";
40
+ };
41
+ controlsVisible: boolean;
42
+ options: Viewport[];
43
+ };
44
+ };
45
+
46
+ type FieldOption = {
47
+ label: string;
48
+ value: string | number | boolean;
49
+ };
50
+ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
51
+ type BaseField = {
52
+ label?: string;
53
+ };
54
+ type TextField = BaseField & {
55
+ type: "text";
56
+ };
57
+ type NumberField = BaseField & {
58
+ type: "number";
59
+ min?: number;
60
+ max?: number;
61
+ };
62
+ type TextareaField = BaseField & {
63
+ type: "textarea";
64
+ };
65
+ type SelectField = BaseField & {
66
+ type: "select";
67
+ options: FieldOptions;
68
+ };
69
+ type RadioField = BaseField & {
70
+ type: "radio";
71
+ options: FieldOptions;
72
+ };
73
+ type ArrayField<Props extends {
74
+ [key: string]: any;
75
+ } = {
76
+ [key: string]: any;
77
+ }> = BaseField & {
78
+ type: "array";
79
+ arrayFields: {
80
+ [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
81
+ };
82
+ defaultItemProps?: Props[0];
83
+ getItemSummary?: (item: Props[0], index?: number) => string;
84
+ max?: number;
85
+ min?: number;
86
+ };
87
+ type ObjectField<Props extends {
88
+ [key: string]: any;
89
+ } = {
90
+ [key: string]: any;
91
+ }> = BaseField & {
92
+ type: "object";
93
+ objectFields: Props extends any[] ? never : {
94
+ [SubPropName in keyof Props]: Field<Props[SubPropName]>;
95
+ };
96
+ };
97
+ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
98
+ name: string;
99
+ fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
100
+ mapProp?: (value: TableShape) => PropShape;
101
+ };
102
+ type ExternalFieldWithAdaptor<Props extends {
103
+ [key: string]: any;
104
+ } = {
105
+ [key: string]: any;
106
+ }> = BaseField & {
107
+ type: "external";
108
+ placeholder?: string;
109
+ adaptor: Adaptor<any, any, Props>;
110
+ adaptorParams?: object;
111
+ getItemSummary: (item: Props, index?: number) => string;
112
+ };
113
+ type ExternalField<Props extends {
114
+ [key: string]: any;
115
+ } = {
116
+ [key: string]: any;
117
+ }> = BaseField & {
118
+ type: "external";
119
+ placeholder?: string;
120
+ fetchList: (params: {
121
+ query: string;
122
+ filters: Record<string, any>;
123
+ }) => Promise<any[] | null>;
124
+ mapProp?: (value: any) => Props;
125
+ mapRow?: (value: any) => Record<string, string | number>;
126
+ getItemSummary?: (item: Props, index?: number) => string;
127
+ showSearch?: boolean;
128
+ initialQuery?: string;
129
+ filterFields?: Record<string, Field>;
130
+ initialFilters?: Record<string, any>;
131
+ };
132
+ type CustomField<Props extends any = {}> = BaseField & {
133
+ type: "custom";
134
+ render: (props: {
135
+ field: CustomField<Props>;
136
+ name: string;
137
+ id: string;
138
+ value: Props;
139
+ onChange: (value: Props) => void;
140
+ readOnly?: boolean;
141
+ }) => ReactElement;
142
+ };
143
+ type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
144
+ [key: string]: any;
145
+ } ? Props : any> | ObjectField<Props extends {
146
+ [key: string]: any;
147
+ } ? Props : any> | ExternalField<Props extends {
148
+ [key: string]: any;
149
+ } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
150
+ [key: string]: any;
151
+ } ? Props : any> | CustomField<Props>;
152
+ type FieldProps<ValueType = any, F = Field<any>> = {
153
+ field: F;
154
+ value: ValueType;
155
+ id?: string;
156
+ onChange: (value: ValueType, uiState?: Partial<UiState>) => void;
157
+ readOnly?: boolean;
158
+ };
159
+
160
+ type RenderFunc<Props extends {
161
+ [key: string]: any;
162
+ } = {
163
+ children: ReactNode;
164
+ }> = (props: Props) => ReactElement;
165
+ declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
166
+ type OverrideKey = (typeof overrideKeys)[number];
167
+ type OverridesGeneric<Shape extends {
168
+ [key in OverrideKey]: any;
169
+ }> = Shape;
170
+ type Overrides = OverridesGeneric<{
171
+ fieldTypes: Partial<FieldRenderFunctions>;
172
+ header: RenderFunc<{
173
+ actions: ReactNode;
174
+ children: ReactNode;
175
+ }>;
176
+ actionBar: RenderFunc<{
177
+ label?: string;
178
+ children: ReactNode;
179
+ }>;
180
+ headerActions: RenderFunc<{
181
+ children: ReactNode;
182
+ }>;
183
+ preview: RenderFunc;
184
+ fields: RenderFunc<{
185
+ children: ReactNode;
186
+ isLoading: boolean;
187
+ itemSelector?: ItemSelector | null;
188
+ }>;
189
+ fieldLabel: RenderFunc<{
190
+ children?: ReactNode;
191
+ icon?: ReactNode;
192
+ label: string;
193
+ el?: "label" | "div";
194
+ readOnly?: boolean;
195
+ className?: string;
196
+ }>;
197
+ components: RenderFunc;
198
+ componentItem: RenderFunc<{
199
+ children: ReactNode;
200
+ name: string;
201
+ }>;
202
+ iframe: RenderFunc<{
203
+ children: ReactNode;
204
+ document?: Document;
205
+ }>;
206
+ outline: RenderFunc;
207
+ puck: RenderFunc;
208
+ }>;
209
+ type FieldRenderFunctions = Omit<{
210
+ [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
211
+ type: Type;
212
+ }>> & {
213
+ children: ReactNode;
214
+ name: string;
215
+ }>;
216
+ }, "custom"> & {
217
+ [key: string]: React.FunctionComponent<FieldProps<any> & {
218
+ children: ReactNode;
219
+ name: string;
220
+ }>;
221
+ };
222
+
223
+ type Plugin = {
224
+ overrides: Partial<Overrides>;
225
+ };
226
+
227
+ declare const headingAnalyzer: Plugin;
228
+
229
+ export { headingAnalyzer as default };
package/dist/index.d.ts CHANGED
@@ -90,7 +90,7 @@ type ObjectField<Props extends {
90
90
  [key: string]: any;
91
91
  }> = BaseField & {
92
92
  type: "object";
93
- objectFields: {
93
+ objectFields: Props extends any[] ? never : {
94
94
  [SubPropName in keyof Props]: Field<Props[SubPropName]>;
95
95
  };
96
96
  };
@@ -173,6 +173,10 @@ type Overrides = OverridesGeneric<{
173
173
  actions: ReactNode;
174
174
  children: ReactNode;
175
175
  }>;
176
+ actionBar: RenderFunc<{
177
+ label?: string;
178
+ children: ReactNode;
179
+ }>;
176
180
  headerActions: RenderFunc<{
177
181
  children: ReactNode;
178
182
  }>;
@@ -195,6 +199,10 @@ type Overrides = OverridesGeneric<{
195
199
  children: ReactNode;
196
200
  name: string;
197
201
  }>;
202
+ iframe: RenderFunc<{
203
+ children: ReactNode;
204
+ document?: Document;
205
+ }>;
198
206
  outline: RenderFunc;
199
207
  puck: RenderFunc;
200
208
  }>;