@measured/puck-plugin-heading-analyzer 0.20.0-canary.274fe3d9 → 0.20.0-canary.29cd4d52
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 +292 -24
- package/dist/index.d.ts +292 -24
- package/dist/index.js +78 -46
- package/dist/index.mjs +78 -46
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ReactElement, ReactNode } from 'react';
|
1
|
+
import { ReactElement, CSSProperties, ReactNode, JSX } from 'react';
|
2
2
|
|
3
3
|
type ItemSelector = {
|
4
4
|
index: number;
|
@@ -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,26 +41,30 @@ type RadioField = BaseField & {
|
|
39
41
|
type: "radio";
|
40
42
|
options: FieldOptions;
|
41
43
|
};
|
42
|
-
type ArrayField<Props extends
|
44
|
+
type ArrayField<Props extends {
|
43
45
|
[key: string]: any;
|
44
|
-
}
|
46
|
+
}[] = {
|
45
47
|
[key: string]: any;
|
46
|
-
}
|
48
|
+
}[], UserField extends {} = {}> = BaseField & {
|
47
49
|
type: "array";
|
48
50
|
arrayFields: {
|
49
|
-
[SubPropName in keyof Props[0]]:
|
51
|
+
[SubPropName in keyof Props[0]]: UserField extends {
|
52
|
+
type: PropertyKey;
|
53
|
+
} ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
|
50
54
|
};
|
51
55
|
defaultItemProps?: Props[0];
|
52
56
|
getItemSummary?: (item: Props[0], index?: number) => string;
|
53
57
|
max?: number;
|
54
58
|
min?: number;
|
55
|
-
}
|
59
|
+
};
|
56
60
|
type ObjectField<Props extends any = {
|
57
61
|
[key: string]: any;
|
58
|
-
}> = BaseField & {
|
62
|
+
}, UserField extends {} = {}> = BaseField & {
|
59
63
|
type: "object";
|
60
64
|
objectFields: {
|
61
|
-
[SubPropName in keyof Props]:
|
65
|
+
[SubPropName in keyof Props]: UserField extends {
|
66
|
+
type: PropertyKey;
|
67
|
+
} ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
|
62
68
|
};
|
63
69
|
};
|
64
70
|
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
@@ -107,13 +113,21 @@ type CustomFieldRender<Value extends any> = (props: {
|
|
107
113
|
type CustomField<Value extends any> = BaseField & {
|
108
114
|
type: "custom";
|
109
115
|
render: CustomFieldRender<Value>;
|
116
|
+
contentEditable?: boolean;
|
110
117
|
};
|
111
118
|
type SlotField = BaseField & {
|
112
119
|
type: "slot";
|
113
120
|
allow?: string[];
|
114
121
|
disallow?: string[];
|
115
122
|
};
|
116
|
-
type Field<ValueType = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType
|
123
|
+
type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
124
|
+
[key: string]: any;
|
125
|
+
}[] ? ValueType : {}[], UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
126
|
+
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps, UserField extends {} = {}> = {
|
127
|
+
[PropName in keyof Omit<ComponentProps, "editMode">]: UserField extends {
|
128
|
+
type: PropertyKey;
|
129
|
+
} ? Field<ComponentProps[PropName], UserField> | UserField : Field<ComponentProps[PropName]>;
|
130
|
+
};
|
117
131
|
type FieldProps<F = Field<any>, ValueType = any> = {
|
118
132
|
field: F;
|
119
133
|
value: ValueType;
|
@@ -122,6 +136,164 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
122
136
|
readOnly?: boolean;
|
123
137
|
};
|
124
138
|
|
139
|
+
type DropZoneProps = {
|
140
|
+
zone: string;
|
141
|
+
allow?: string[];
|
142
|
+
disallow?: string[];
|
143
|
+
style?: CSSProperties;
|
144
|
+
minEmptyHeight?: number;
|
145
|
+
className?: string;
|
146
|
+
collisionAxis?: DragAxis;
|
147
|
+
};
|
148
|
+
|
149
|
+
type PuckContext = {
|
150
|
+
renderDropZone: React.FC<DropZoneProps>;
|
151
|
+
metadata: Metadata;
|
152
|
+
isEditing: boolean;
|
153
|
+
dragRef: ((element: Element | null) => void) | null;
|
154
|
+
};
|
155
|
+
type DefaultRootFieldProps = {
|
156
|
+
title?: string;
|
157
|
+
};
|
158
|
+
type DefaultComponentProps = {
|
159
|
+
[key: string]: any;
|
160
|
+
};
|
161
|
+
|
162
|
+
type WithId<Props> = Props & {
|
163
|
+
id: string;
|
164
|
+
};
|
165
|
+
type WithPuckProps<Props> = Props & {
|
166
|
+
puck: PuckContext;
|
167
|
+
editMode?: boolean;
|
168
|
+
};
|
169
|
+
type AsFieldProps<Props> = Omit<Props, "children" | "puck" | "editMode">;
|
170
|
+
type WithChildren<Props> = Props & {
|
171
|
+
children: ReactNode;
|
172
|
+
};
|
173
|
+
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]> = {
|
174
|
+
UserConfig: UserConfig;
|
175
|
+
UserParams: UserParams;
|
176
|
+
UserProps: UserParams["props"];
|
177
|
+
UserRootProps: UserParams["rootProps"] & DefaultRootFieldProps;
|
178
|
+
UserData: UserData;
|
179
|
+
UserAppState: UserAppState;
|
180
|
+
UserPublicAppState: UserPublicAppState;
|
181
|
+
UserComponentData: UserComponentData;
|
182
|
+
UserField: UserParams["field"];
|
183
|
+
};
|
184
|
+
type ExtractField<UserField extends {
|
185
|
+
type: PropertyKey;
|
186
|
+
}, T extends UserField["type"]> = Extract<UserField, {
|
187
|
+
type: T;
|
188
|
+
}>;
|
189
|
+
|
190
|
+
type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
|
191
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
192
|
+
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
193
|
+
}>>) => JSX.Element;
|
194
|
+
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
195
|
+
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
196
|
+
props?: Partial<Props>;
|
197
|
+
};
|
198
|
+
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.
|
199
|
+
UserField extends BaseField = {}> = {
|
200
|
+
render: PuckComponent<RenderProps>;
|
201
|
+
label?: string;
|
202
|
+
defaultProps?: FieldProps;
|
203
|
+
fields?: Fields<FieldProps, UserField>;
|
204
|
+
permissions?: Partial<Permissions>;
|
205
|
+
inline?: boolean;
|
206
|
+
resolveFields?: (data: DataShape, params: {
|
207
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
208
|
+
id: string;
|
209
|
+
}>;
|
210
|
+
fields: Fields<FieldProps>;
|
211
|
+
lastFields: Fields<FieldProps>;
|
212
|
+
lastData: DataShape | null;
|
213
|
+
appState: AppState;
|
214
|
+
parent: ComponentData | null;
|
215
|
+
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
216
|
+
resolveData?: (data: DataShape, params: {
|
217
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
218
|
+
id: string;
|
219
|
+
}>;
|
220
|
+
lastData: DataShape | null;
|
221
|
+
metadata: Metadata;
|
222
|
+
trigger: ResolveDataTrigger;
|
223
|
+
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
224
|
+
resolvePermissions?: (data: DataShape, params: {
|
225
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
226
|
+
id: string;
|
227
|
+
}>;
|
228
|
+
lastPermissions: Partial<Permissions>;
|
229
|
+
permissions: Partial<Permissions>;
|
230
|
+
appState: AppState;
|
231
|
+
lastData: DataShape | null;
|
232
|
+
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
233
|
+
metadata?: Metadata;
|
234
|
+
};
|
235
|
+
type RootConfigInternal<RootProps extends DefaultComponentProps = DefaultComponentProps, UserField extends BaseField = {}> = Partial<ComponentConfigInternal<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>, UserField>>;
|
236
|
+
type Category<ComponentName> = {
|
237
|
+
components?: ComponentName[];
|
238
|
+
title?: string;
|
239
|
+
visible?: boolean;
|
240
|
+
defaultExpanded?: boolean;
|
241
|
+
};
|
242
|
+
type ConfigInternal<Props extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultComponentProps, CategoryName extends string = string, UserField extends {} = {}> = {
|
243
|
+
categories?: Record<CategoryName, Category<keyof Props>> & {
|
244
|
+
other?: Category<keyof Props>;
|
245
|
+
};
|
246
|
+
components: {
|
247
|
+
[ComponentName in keyof Props]: Omit<ComponentConfigInternal<Props[ComponentName], Props[ComponentName], Omit<ComponentData<Props[ComponentName]>, "type">, UserField>, "type">;
|
248
|
+
};
|
249
|
+
root?: RootConfigInternal<RootProps, UserField>;
|
250
|
+
};
|
251
|
+
type DefaultComponents = Record<string, any>;
|
252
|
+
type Config<PropsOrParams extends LeftOrExactRight<PropsOrParams, DefaultComponents, ConfigParams> = DefaultComponents | ConfigParams, RootProps extends DefaultComponentProps = DefaultComponentProps, 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>;
|
253
|
+
type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends ConfigInternal<infer PropsOrParams, infer RootProps, infer CategoryName, infer UserField> ? {
|
254
|
+
props: PropsOrParams;
|
255
|
+
rootProps: RootProps & DefaultRootFieldProps;
|
256
|
+
categoryNames: CategoryName;
|
257
|
+
field: UserField extends {
|
258
|
+
type: string;
|
259
|
+
} ? UserField : Field;
|
260
|
+
} : never;
|
261
|
+
|
262
|
+
type BaseData<Props extends {
|
263
|
+
[key: string]: any;
|
264
|
+
} = {
|
265
|
+
[key: string]: any;
|
266
|
+
}> = {
|
267
|
+
readOnly?: Partial<Record<keyof Props, boolean>>;
|
268
|
+
};
|
269
|
+
type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
|
270
|
+
props: Props;
|
271
|
+
};
|
272
|
+
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
273
|
+
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
274
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, Components extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
|
275
|
+
type: Name;
|
276
|
+
props: WithDeepSlots<WithId<Props>, Content<Components>>;
|
277
|
+
} & BaseData<Props>;
|
278
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
279
|
+
type: Name;
|
280
|
+
props: Props & {
|
281
|
+
id?: string;
|
282
|
+
};
|
283
|
+
} & BaseData<Props>;
|
284
|
+
type ComponentDataMap<Components extends DefaultComponents = DefaultComponents> = {
|
285
|
+
[K in keyof Components]: ComponentData<Components[K], K extends string ? K : never, Components>;
|
286
|
+
}[keyof Components];
|
287
|
+
type Content<PropsMap extends {
|
288
|
+
[key: string]: DefaultComponentProps;
|
289
|
+
} = {
|
290
|
+
[key: string]: DefaultComponentProps;
|
291
|
+
}> = ComponentDataMap<PropsMap>[];
|
292
|
+
type Data<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
293
|
+
root: WithDeepSlots<RootData<RootProps>, Content<Components>>;
|
294
|
+
content: Content<Components>;
|
295
|
+
zones?: Record<string, Content<Components>>;
|
296
|
+
};
|
125
297
|
type Metadata = {
|
126
298
|
[key: string]: any;
|
127
299
|
};
|
@@ -137,6 +309,8 @@ type ArrayState = {
|
|
137
309
|
type UiState = {
|
138
310
|
leftSideBarVisible: boolean;
|
139
311
|
rightSideBarVisible: boolean;
|
312
|
+
leftSideBarWidth?: number | null;
|
313
|
+
rightSideBarWidth?: number | null;
|
140
314
|
itemSelector: ItemSelector | null;
|
141
315
|
arrayState: Record<string, ArrayState | undefined>;
|
142
316
|
previewMode: "interactive" | "edit";
|
@@ -159,19 +333,89 @@ type UiState = {
|
|
159
333
|
focus?: string | null;
|
160
334
|
};
|
161
335
|
};
|
336
|
+
type AppState<UserData extends Data = Data> = {
|
337
|
+
data: UserData;
|
338
|
+
ui: UiState;
|
339
|
+
};
|
340
|
+
|
341
|
+
type ZoneType = "root" | "dropzone" | "slot";
|
342
|
+
type PuckNodeData = {
|
343
|
+
data: ComponentData;
|
344
|
+
flatData: ComponentData;
|
345
|
+
parentId: string | null;
|
346
|
+
zone: string;
|
347
|
+
path: string[];
|
348
|
+
};
|
349
|
+
type PuckZoneData = {
|
350
|
+
contentIds: string[];
|
351
|
+
type: ZoneType;
|
352
|
+
};
|
353
|
+
type NodeIndex = Record<string, PuckNodeData>;
|
354
|
+
type ZoneIndex = Record<string, PuckZoneData>;
|
355
|
+
type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
356
|
+
indexes: {
|
357
|
+
nodes: NodeIndex;
|
358
|
+
zones: ZoneIndex;
|
359
|
+
};
|
360
|
+
};
|
361
|
+
type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined;
|
362
|
+
/**
|
363
|
+
* Recursively walk T and replace Slots with SlotComponents
|
364
|
+
*/
|
365
|
+
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 ? {
|
366
|
+
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
367
|
+
} : T;
|
368
|
+
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultComponentProps, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
369
|
+
components?: Components;
|
370
|
+
root?: RootProps;
|
371
|
+
categories?: CategoryNames;
|
372
|
+
fields?: AssertHasValue<UserFields>;
|
373
|
+
};
|
374
|
+
type FieldsExtension = {
|
375
|
+
[Type in string]: {
|
376
|
+
type: Type;
|
377
|
+
};
|
378
|
+
};
|
379
|
+
type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
|
380
|
+
type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
|
381
|
+
type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
|
382
|
+
never
|
383
|
+
] ? False : True;
|
384
|
+
|
385
|
+
type MapFnParams<ThisField = Field> = {
|
386
|
+
value: any;
|
387
|
+
parentId: string;
|
388
|
+
propName: string;
|
389
|
+
field: ThisField;
|
390
|
+
propPath: string;
|
391
|
+
};
|
392
|
+
|
393
|
+
type FieldTransformFnParams<T> = Omit<MapFnParams<T>, "parentId"> & {
|
394
|
+
isReadOnly: boolean;
|
395
|
+
componentId: string;
|
396
|
+
};
|
397
|
+
type FieldTransformFn<T> = (params: FieldTransformFnParams<T>) => any;
|
398
|
+
type FieldTransforms<UserConfig extends Config = Config<{
|
399
|
+
fields: {};
|
400
|
+
}>, // Setting fields: {} helps TS choose default field types
|
401
|
+
G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
402
|
+
type: string;
|
403
|
+
} = Field | G["UserField"]> = Partial<{
|
404
|
+
[Type in UserField["type"]]: FieldTransformFn<ExtractField<UserField, Type>>;
|
405
|
+
}>;
|
162
406
|
|
163
407
|
type RenderFunc<Props extends {
|
164
408
|
[key: string]: any;
|
165
409
|
} = {
|
166
410
|
children: ReactNode;
|
167
411
|
}> = (props: Props) => ReactElement;
|
168
|
-
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "
|
412
|
+
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
|
169
413
|
type OverrideKey = (typeof overrideKeys)[number];
|
170
414
|
type OverridesGeneric<Shape extends {
|
171
415
|
[key in OverrideKey]: any;
|
172
416
|
}> = Shape;
|
173
|
-
type Overrides = OverridesGeneric<{
|
174
|
-
fieldTypes: Partial<FieldRenderFunctions
|
417
|
+
type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
418
|
+
fieldTypes: Partial<FieldRenderFunctions<UserConfig>>;
|
175
419
|
header: RenderFunc<{
|
176
420
|
actions: ReactNode;
|
177
421
|
children: ReactNode;
|
@@ -203,26 +447,35 @@ type Overrides = OverridesGeneric<{
|
|
203
447
|
children: ReactNode;
|
204
448
|
name: string;
|
205
449
|
}>;
|
450
|
+
drawer: RenderFunc;
|
451
|
+
drawerItem: RenderFunc<{
|
452
|
+
children: ReactNode;
|
453
|
+
name: string;
|
454
|
+
}>;
|
206
455
|
iframe: RenderFunc<{
|
207
456
|
children: ReactNode;
|
208
457
|
document?: Document;
|
209
458
|
}>;
|
210
459
|
outline: RenderFunc;
|
211
|
-
|
212
|
-
}>;
|
213
|
-
type FieldRenderFunctions = Omit<{
|
214
|
-
[Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
|
215
|
-
type: Type;
|
216
|
-
}>, any> & {
|
460
|
+
componentOverlay: RenderFunc<{
|
217
461
|
children: ReactNode;
|
218
|
-
|
462
|
+
hover: boolean;
|
463
|
+
isSelected: boolean;
|
464
|
+
componentId: string;
|
465
|
+
componentType: string;
|
219
466
|
}>;
|
220
|
-
|
221
|
-
|
467
|
+
puck: RenderFunc;
|
468
|
+
}>;
|
469
|
+
type FieldRenderFunctions<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
470
|
+
type: string;
|
471
|
+
} = Field | G["UserField"]> = Omit<{
|
472
|
+
[Type in UserField["type"]]: React.FunctionComponent<FieldProps<ExtractField<UserField, Type>, any> & {
|
222
473
|
children: ReactNode;
|
223
474
|
name: string;
|
224
475
|
}>;
|
225
|
-
}
|
476
|
+
}, "custom">;
|
477
|
+
|
478
|
+
type DragAxis = "dynamic" | "y" | "x";
|
226
479
|
|
227
480
|
type iconTypes = "Smartphone" | "Monitor" | "Tablet";
|
228
481
|
type Viewport = {
|
@@ -232,9 +485,24 @@ type Viewport = {
|
|
232
485
|
icon?: iconTypes | ReactNode;
|
233
486
|
};
|
234
487
|
|
235
|
-
type
|
236
|
-
|
488
|
+
type Permissions = {
|
489
|
+
drag: boolean;
|
490
|
+
duplicate: boolean;
|
491
|
+
delete: boolean;
|
492
|
+
edit: boolean;
|
493
|
+
insert: boolean;
|
494
|
+
} & Record<string, boolean>;
|
495
|
+
type Plugin<UserConfig extends Config = Config> = {
|
496
|
+
overrides?: Partial<Overrides<UserConfig>>;
|
497
|
+
fieldTransforms?: FieldTransforms<UserConfig>;
|
237
498
|
};
|
499
|
+
type Slot<Props extends {
|
500
|
+
[key: string]: DefaultComponentProps;
|
501
|
+
} = {
|
502
|
+
[key: string]: DefaultComponentProps;
|
503
|
+
}> = {
|
504
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
505
|
+
}[keyof Props][];
|
238
506
|
|
239
507
|
declare const headingAnalyzer: Plugin;
|
240
508
|
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ReactElement, ReactNode } from 'react';
|
1
|
+
import { ReactElement, CSSProperties, ReactNode, JSX } from 'react';
|
2
2
|
|
3
3
|
type ItemSelector = {
|
4
4
|
index: number;
|
@@ -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,26 +41,30 @@ type RadioField = BaseField & {
|
|
39
41
|
type: "radio";
|
40
42
|
options: FieldOptions;
|
41
43
|
};
|
42
|
-
type ArrayField<Props extends
|
44
|
+
type ArrayField<Props extends {
|
43
45
|
[key: string]: any;
|
44
|
-
}
|
46
|
+
}[] = {
|
45
47
|
[key: string]: any;
|
46
|
-
}
|
48
|
+
}[], UserField extends {} = {}> = BaseField & {
|
47
49
|
type: "array";
|
48
50
|
arrayFields: {
|
49
|
-
[SubPropName in keyof Props[0]]:
|
51
|
+
[SubPropName in keyof Props[0]]: UserField extends {
|
52
|
+
type: PropertyKey;
|
53
|
+
} ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
|
50
54
|
};
|
51
55
|
defaultItemProps?: Props[0];
|
52
56
|
getItemSummary?: (item: Props[0], index?: number) => string;
|
53
57
|
max?: number;
|
54
58
|
min?: number;
|
55
|
-
}
|
59
|
+
};
|
56
60
|
type ObjectField<Props extends any = {
|
57
61
|
[key: string]: any;
|
58
|
-
}> = BaseField & {
|
62
|
+
}, UserField extends {} = {}> = BaseField & {
|
59
63
|
type: "object";
|
60
64
|
objectFields: {
|
61
|
-
[SubPropName in keyof Props]:
|
65
|
+
[SubPropName in keyof Props]: UserField extends {
|
66
|
+
type: PropertyKey;
|
67
|
+
} ? Field<Props[SubPropName]> | UserField : Field<Props[SubPropName]>;
|
62
68
|
};
|
63
69
|
};
|
64
70
|
type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
|
@@ -107,13 +113,21 @@ type CustomFieldRender<Value extends any> = (props: {
|
|
107
113
|
type CustomField<Value extends any> = BaseField & {
|
108
114
|
type: "custom";
|
109
115
|
render: CustomFieldRender<Value>;
|
116
|
+
contentEditable?: boolean;
|
110
117
|
};
|
111
118
|
type SlotField = BaseField & {
|
112
119
|
type: "slot";
|
113
120
|
allow?: string[];
|
114
121
|
disallow?: string[];
|
115
122
|
};
|
116
|
-
type Field<ValueType = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType
|
123
|
+
type Field<ValueType = any, UserField extends {} = {}> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<ValueType extends {
|
124
|
+
[key: string]: any;
|
125
|
+
}[] ? ValueType : {}[], UserField> | ObjectField<ValueType, UserField> | ExternalField<ValueType> | ExternalFieldWithAdaptor<ValueType> | CustomField<ValueType> | SlotField;
|
126
|
+
type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps, UserField extends {} = {}> = {
|
127
|
+
[PropName in keyof Omit<ComponentProps, "editMode">]: UserField extends {
|
128
|
+
type: PropertyKey;
|
129
|
+
} ? Field<ComponentProps[PropName], UserField> | UserField : Field<ComponentProps[PropName]>;
|
130
|
+
};
|
117
131
|
type FieldProps<F = Field<any>, ValueType = any> = {
|
118
132
|
field: F;
|
119
133
|
value: ValueType;
|
@@ -122,6 +136,164 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
122
136
|
readOnly?: boolean;
|
123
137
|
};
|
124
138
|
|
139
|
+
type DropZoneProps = {
|
140
|
+
zone: string;
|
141
|
+
allow?: string[];
|
142
|
+
disallow?: string[];
|
143
|
+
style?: CSSProperties;
|
144
|
+
minEmptyHeight?: number;
|
145
|
+
className?: string;
|
146
|
+
collisionAxis?: DragAxis;
|
147
|
+
};
|
148
|
+
|
149
|
+
type PuckContext = {
|
150
|
+
renderDropZone: React.FC<DropZoneProps>;
|
151
|
+
metadata: Metadata;
|
152
|
+
isEditing: boolean;
|
153
|
+
dragRef: ((element: Element | null) => void) | null;
|
154
|
+
};
|
155
|
+
type DefaultRootFieldProps = {
|
156
|
+
title?: string;
|
157
|
+
};
|
158
|
+
type DefaultComponentProps = {
|
159
|
+
[key: string]: any;
|
160
|
+
};
|
161
|
+
|
162
|
+
type WithId<Props> = Props & {
|
163
|
+
id: string;
|
164
|
+
};
|
165
|
+
type WithPuckProps<Props> = Props & {
|
166
|
+
puck: PuckContext;
|
167
|
+
editMode?: boolean;
|
168
|
+
};
|
169
|
+
type AsFieldProps<Props> = Omit<Props, "children" | "puck" | "editMode">;
|
170
|
+
type WithChildren<Props> = Props & {
|
171
|
+
children: ReactNode;
|
172
|
+
};
|
173
|
+
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]> = {
|
174
|
+
UserConfig: UserConfig;
|
175
|
+
UserParams: UserParams;
|
176
|
+
UserProps: UserParams["props"];
|
177
|
+
UserRootProps: UserParams["rootProps"] & DefaultRootFieldProps;
|
178
|
+
UserData: UserData;
|
179
|
+
UserAppState: UserAppState;
|
180
|
+
UserPublicAppState: UserPublicAppState;
|
181
|
+
UserComponentData: UserComponentData;
|
182
|
+
UserField: UserParams["field"];
|
183
|
+
};
|
184
|
+
type ExtractField<UserField extends {
|
185
|
+
type: PropertyKey;
|
186
|
+
}, T extends UserField["type"]> = Extract<UserField, {
|
187
|
+
type: T;
|
188
|
+
}>;
|
189
|
+
|
190
|
+
type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
|
191
|
+
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
192
|
+
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
193
|
+
}>>) => JSX.Element;
|
194
|
+
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
195
|
+
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
196
|
+
props?: Partial<Props>;
|
197
|
+
};
|
198
|
+
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.
|
199
|
+
UserField extends BaseField = {}> = {
|
200
|
+
render: PuckComponent<RenderProps>;
|
201
|
+
label?: string;
|
202
|
+
defaultProps?: FieldProps;
|
203
|
+
fields?: Fields<FieldProps, UserField>;
|
204
|
+
permissions?: Partial<Permissions>;
|
205
|
+
inline?: boolean;
|
206
|
+
resolveFields?: (data: DataShape, params: {
|
207
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
208
|
+
id: string;
|
209
|
+
}>;
|
210
|
+
fields: Fields<FieldProps>;
|
211
|
+
lastFields: Fields<FieldProps>;
|
212
|
+
lastData: DataShape | null;
|
213
|
+
appState: AppState;
|
214
|
+
parent: ComponentData | null;
|
215
|
+
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
216
|
+
resolveData?: (data: DataShape, params: {
|
217
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
218
|
+
id: string;
|
219
|
+
}>;
|
220
|
+
lastData: DataShape | null;
|
221
|
+
metadata: Metadata;
|
222
|
+
trigger: ResolveDataTrigger;
|
223
|
+
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
224
|
+
resolvePermissions?: (data: DataShape, params: {
|
225
|
+
changed: Partial<Record<keyof FieldProps, boolean> & {
|
226
|
+
id: string;
|
227
|
+
}>;
|
228
|
+
lastPermissions: Partial<Permissions>;
|
229
|
+
permissions: Partial<Permissions>;
|
230
|
+
appState: AppState;
|
231
|
+
lastData: DataShape | null;
|
232
|
+
}) => Promise<Partial<Permissions>> | Partial<Permissions>;
|
233
|
+
metadata?: Metadata;
|
234
|
+
};
|
235
|
+
type RootConfigInternal<RootProps extends DefaultComponentProps = DefaultComponentProps, UserField extends BaseField = {}> = Partial<ComponentConfigInternal<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>, UserField>>;
|
236
|
+
type Category<ComponentName> = {
|
237
|
+
components?: ComponentName[];
|
238
|
+
title?: string;
|
239
|
+
visible?: boolean;
|
240
|
+
defaultExpanded?: boolean;
|
241
|
+
};
|
242
|
+
type ConfigInternal<Props extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultComponentProps, CategoryName extends string = string, UserField extends {} = {}> = {
|
243
|
+
categories?: Record<CategoryName, Category<keyof Props>> & {
|
244
|
+
other?: Category<keyof Props>;
|
245
|
+
};
|
246
|
+
components: {
|
247
|
+
[ComponentName in keyof Props]: Omit<ComponentConfigInternal<Props[ComponentName], Props[ComponentName], Omit<ComponentData<Props[ComponentName]>, "type">, UserField>, "type">;
|
248
|
+
};
|
249
|
+
root?: RootConfigInternal<RootProps, UserField>;
|
250
|
+
};
|
251
|
+
type DefaultComponents = Record<string, any>;
|
252
|
+
type Config<PropsOrParams extends LeftOrExactRight<PropsOrParams, DefaultComponents, ConfigParams> = DefaultComponents | ConfigParams, RootProps extends DefaultComponentProps = DefaultComponentProps, 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>;
|
253
|
+
type ExtractConfigParams<UserConfig extends ConfigInternal> = UserConfig extends ConfigInternal<infer PropsOrParams, infer RootProps, infer CategoryName, infer UserField> ? {
|
254
|
+
props: PropsOrParams;
|
255
|
+
rootProps: RootProps & DefaultRootFieldProps;
|
256
|
+
categoryNames: CategoryName;
|
257
|
+
field: UserField extends {
|
258
|
+
type: string;
|
259
|
+
} ? UserField : Field;
|
260
|
+
} : never;
|
261
|
+
|
262
|
+
type BaseData<Props extends {
|
263
|
+
[key: string]: any;
|
264
|
+
} = {
|
265
|
+
[key: string]: any;
|
266
|
+
}> = {
|
267
|
+
readOnly?: Partial<Record<keyof Props, boolean>>;
|
268
|
+
};
|
269
|
+
type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
|
270
|
+
props: Props;
|
271
|
+
};
|
272
|
+
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
273
|
+
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
274
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, Components extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
|
275
|
+
type: Name;
|
276
|
+
props: WithDeepSlots<WithId<Props>, Content<Components>>;
|
277
|
+
} & BaseData<Props>;
|
278
|
+
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
279
|
+
type: Name;
|
280
|
+
props: Props & {
|
281
|
+
id?: string;
|
282
|
+
};
|
283
|
+
} & BaseData<Props>;
|
284
|
+
type ComponentDataMap<Components extends DefaultComponents = DefaultComponents> = {
|
285
|
+
[K in keyof Components]: ComponentData<Components[K], K extends string ? K : never, Components>;
|
286
|
+
}[keyof Components];
|
287
|
+
type Content<PropsMap extends {
|
288
|
+
[key: string]: DefaultComponentProps;
|
289
|
+
} = {
|
290
|
+
[key: string]: DefaultComponentProps;
|
291
|
+
}> = ComponentDataMap<PropsMap>[];
|
292
|
+
type Data<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
293
|
+
root: WithDeepSlots<RootData<RootProps>, Content<Components>>;
|
294
|
+
content: Content<Components>;
|
295
|
+
zones?: Record<string, Content<Components>>;
|
296
|
+
};
|
125
297
|
type Metadata = {
|
126
298
|
[key: string]: any;
|
127
299
|
};
|
@@ -137,6 +309,8 @@ type ArrayState = {
|
|
137
309
|
type UiState = {
|
138
310
|
leftSideBarVisible: boolean;
|
139
311
|
rightSideBarVisible: boolean;
|
312
|
+
leftSideBarWidth?: number | null;
|
313
|
+
rightSideBarWidth?: number | null;
|
140
314
|
itemSelector: ItemSelector | null;
|
141
315
|
arrayState: Record<string, ArrayState | undefined>;
|
142
316
|
previewMode: "interactive" | "edit";
|
@@ -159,19 +333,89 @@ type UiState = {
|
|
159
333
|
focus?: string | null;
|
160
334
|
};
|
161
335
|
};
|
336
|
+
type AppState<UserData extends Data = Data> = {
|
337
|
+
data: UserData;
|
338
|
+
ui: UiState;
|
339
|
+
};
|
340
|
+
|
341
|
+
type ZoneType = "root" | "dropzone" | "slot";
|
342
|
+
type PuckNodeData = {
|
343
|
+
data: ComponentData;
|
344
|
+
flatData: ComponentData;
|
345
|
+
parentId: string | null;
|
346
|
+
zone: string;
|
347
|
+
path: string[];
|
348
|
+
};
|
349
|
+
type PuckZoneData = {
|
350
|
+
contentIds: string[];
|
351
|
+
type: ZoneType;
|
352
|
+
};
|
353
|
+
type NodeIndex = Record<string, PuckNodeData>;
|
354
|
+
type ZoneIndex = Record<string, PuckZoneData>;
|
355
|
+
type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
356
|
+
indexes: {
|
357
|
+
nodes: NodeIndex;
|
358
|
+
zones: ZoneIndex;
|
359
|
+
};
|
360
|
+
};
|
361
|
+
type BuiltinTypes = Date | RegExp | Error | Function | symbol | null | undefined;
|
362
|
+
/**
|
363
|
+
* Recursively walk T and replace Slots with SlotComponents
|
364
|
+
*/
|
365
|
+
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 ? {
|
366
|
+
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
367
|
+
} : T;
|
368
|
+
type ConfigParams<Components extends DefaultComponents = DefaultComponents, RootProps extends DefaultComponentProps = DefaultComponentProps, CategoryNames extends string[] = string[], UserFields extends FieldsExtension = FieldsExtension> = {
|
369
|
+
components?: Components;
|
370
|
+
root?: RootProps;
|
371
|
+
categories?: CategoryNames;
|
372
|
+
fields?: AssertHasValue<UserFields>;
|
373
|
+
};
|
374
|
+
type FieldsExtension = {
|
375
|
+
[Type in string]: {
|
376
|
+
type: Type;
|
377
|
+
};
|
378
|
+
};
|
379
|
+
type Exact<T, Target> = Record<Exclude<keyof T, keyof Target>, never>;
|
380
|
+
type LeftOrExactRight<Union, Left, Right> = (Left & Union extends Right ? Exact<Union, Right> : Left) | (Right & Exact<Union, Right>);
|
381
|
+
type AssertHasValue<T, True = T, False = never> = [keyof T] extends [
|
382
|
+
never
|
383
|
+
] ? False : True;
|
384
|
+
|
385
|
+
type MapFnParams<ThisField = Field> = {
|
386
|
+
value: any;
|
387
|
+
parentId: string;
|
388
|
+
propName: string;
|
389
|
+
field: ThisField;
|
390
|
+
propPath: string;
|
391
|
+
};
|
392
|
+
|
393
|
+
type FieldTransformFnParams<T> = Omit<MapFnParams<T>, "parentId"> & {
|
394
|
+
isReadOnly: boolean;
|
395
|
+
componentId: string;
|
396
|
+
};
|
397
|
+
type FieldTransformFn<T> = (params: FieldTransformFnParams<T>) => any;
|
398
|
+
type FieldTransforms<UserConfig extends Config = Config<{
|
399
|
+
fields: {};
|
400
|
+
}>, // Setting fields: {} helps TS choose default field types
|
401
|
+
G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
402
|
+
type: string;
|
403
|
+
} = Field | G["UserField"]> = Partial<{
|
404
|
+
[Type in UserField["type"]]: FieldTransformFn<ExtractField<UserField, Type>>;
|
405
|
+
}>;
|
162
406
|
|
163
407
|
type RenderFunc<Props extends {
|
164
408
|
[key: string]: any;
|
165
409
|
} = {
|
166
410
|
children: ReactNode;
|
167
411
|
}> = (props: Props) => ReactElement;
|
168
|
-
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "
|
412
|
+
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "drawer", "drawerItem", "componentOverlay", "outline", "puck", "preview"];
|
169
413
|
type OverrideKey = (typeof overrideKeys)[number];
|
170
414
|
type OverridesGeneric<Shape extends {
|
171
415
|
[key in OverrideKey]: any;
|
172
416
|
}> = Shape;
|
173
|
-
type Overrides = OverridesGeneric<{
|
174
|
-
fieldTypes: Partial<FieldRenderFunctions
|
417
|
+
type Overrides<UserConfig extends Config = Config> = OverridesGeneric<{
|
418
|
+
fieldTypes: Partial<FieldRenderFunctions<UserConfig>>;
|
175
419
|
header: RenderFunc<{
|
176
420
|
actions: ReactNode;
|
177
421
|
children: ReactNode;
|
@@ -203,26 +447,35 @@ type Overrides = OverridesGeneric<{
|
|
203
447
|
children: ReactNode;
|
204
448
|
name: string;
|
205
449
|
}>;
|
450
|
+
drawer: RenderFunc;
|
451
|
+
drawerItem: RenderFunc<{
|
452
|
+
children: ReactNode;
|
453
|
+
name: string;
|
454
|
+
}>;
|
206
455
|
iframe: RenderFunc<{
|
207
456
|
children: ReactNode;
|
208
457
|
document?: Document;
|
209
458
|
}>;
|
210
459
|
outline: RenderFunc;
|
211
|
-
|
212
|
-
}>;
|
213
|
-
type FieldRenderFunctions = Omit<{
|
214
|
-
[Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
|
215
|
-
type: Type;
|
216
|
-
}>, any> & {
|
460
|
+
componentOverlay: RenderFunc<{
|
217
461
|
children: ReactNode;
|
218
|
-
|
462
|
+
hover: boolean;
|
463
|
+
isSelected: boolean;
|
464
|
+
componentId: string;
|
465
|
+
componentType: string;
|
219
466
|
}>;
|
220
|
-
|
221
|
-
|
467
|
+
puck: RenderFunc;
|
468
|
+
}>;
|
469
|
+
type FieldRenderFunctions<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>, UserField extends {
|
470
|
+
type: string;
|
471
|
+
} = Field | G["UserField"]> = Omit<{
|
472
|
+
[Type in UserField["type"]]: React.FunctionComponent<FieldProps<ExtractField<UserField, Type>, any> & {
|
222
473
|
children: ReactNode;
|
223
474
|
name: string;
|
224
475
|
}>;
|
225
|
-
}
|
476
|
+
}, "custom">;
|
477
|
+
|
478
|
+
type DragAxis = "dynamic" | "y" | "x";
|
226
479
|
|
227
480
|
type iconTypes = "Smartphone" | "Monitor" | "Tablet";
|
228
481
|
type Viewport = {
|
@@ -232,9 +485,24 @@ type Viewport = {
|
|
232
485
|
icon?: iconTypes | ReactNode;
|
233
486
|
};
|
234
487
|
|
235
|
-
type
|
236
|
-
|
488
|
+
type Permissions = {
|
489
|
+
drag: boolean;
|
490
|
+
duplicate: boolean;
|
491
|
+
delete: boolean;
|
492
|
+
edit: boolean;
|
493
|
+
insert: boolean;
|
494
|
+
} & Record<string, boolean>;
|
495
|
+
type Plugin<UserConfig extends Config = Config> = {
|
496
|
+
overrides?: Partial<Overrides<UserConfig>>;
|
497
|
+
fieldTransforms?: FieldTransforms<UserConfig>;
|
237
498
|
};
|
499
|
+
type Slot<Props extends {
|
500
|
+
[key: string]: DefaultComponentProps;
|
501
|
+
} = {
|
502
|
+
[key: string]: DefaultComponentProps;
|
503
|
+
}> = {
|
504
|
+
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
505
|
+
}[keyof Props][];
|
238
506
|
|
239
507
|
declare const headingAnalyzer: Plugin;
|
240
508
|
|
package/dist/index.js
CHANGED
@@ -521,7 +521,7 @@ function forRelatedZones(item, data, cb, path = []) {
|
|
521
521
|
});
|
522
522
|
}
|
523
523
|
|
524
|
-
// ../core/lib/data/map-
|
524
|
+
// ../core/lib/data/map-fields.ts
|
525
525
|
init_react_import();
|
526
526
|
|
527
527
|
// ../core/lib/data/default-slots.ts
|
@@ -531,14 +531,14 @@ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
|
531
531
|
value
|
532
532
|
);
|
533
533
|
|
534
|
-
// ../core/lib/data/map-
|
534
|
+
// ../core/lib/data/map-fields.ts
|
535
535
|
var isPromise = (v) => !!v && typeof v.then === "function";
|
536
536
|
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
537
537
|
var containsPromise = (arr) => arr.some(isPromise);
|
538
538
|
var walkField = ({
|
539
539
|
value,
|
540
540
|
fields,
|
541
|
-
|
541
|
+
mappers,
|
542
542
|
propKey = "",
|
543
543
|
propPath = "",
|
544
544
|
id = "",
|
@@ -546,7 +546,9 @@ var walkField = ({
|
|
546
546
|
recurseSlots = false
|
547
547
|
}) => {
|
548
548
|
var _a, _b, _c;
|
549
|
-
|
549
|
+
const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
|
550
|
+
const map = mappers[fieldType];
|
551
|
+
if (map && fieldType === "slot") {
|
550
552
|
const content = value || [];
|
551
553
|
const mappedContent = recurseSlots ? content.map((el) => {
|
552
554
|
var _a2;
|
@@ -558,7 +560,7 @@ var walkField = ({
|
|
558
560
|
return walkField({
|
559
561
|
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
560
562
|
fields: fields2,
|
561
|
-
|
563
|
+
mappers,
|
562
564
|
id: el.props.id,
|
563
565
|
config,
|
564
566
|
recurseSlots
|
@@ -567,7 +569,21 @@ var walkField = ({
|
|
567
569
|
if (containsPromise(mappedContent)) {
|
568
570
|
return Promise.all(mappedContent);
|
569
571
|
}
|
570
|
-
return map(
|
572
|
+
return map({
|
573
|
+
value: mappedContent,
|
574
|
+
parentId: id,
|
575
|
+
propName: propKey,
|
576
|
+
field: fields[propKey],
|
577
|
+
propPath
|
578
|
+
});
|
579
|
+
} else if (map && fields[propKey]) {
|
580
|
+
return map({
|
581
|
+
value,
|
582
|
+
parentId: id,
|
583
|
+
propName: propKey,
|
584
|
+
field: fields[propKey],
|
585
|
+
propPath
|
586
|
+
});
|
571
587
|
}
|
572
588
|
if (value && typeof value === "object") {
|
573
589
|
if (Array.isArray(value)) {
|
@@ -577,7 +593,7 @@ var walkField = ({
|
|
577
593
|
(el, idx) => walkField({
|
578
594
|
value: el,
|
579
595
|
fields: arrayFields,
|
580
|
-
|
596
|
+
mappers,
|
581
597
|
propKey,
|
582
598
|
propPath: `${propPath}[${idx}]`,
|
583
599
|
id,
|
@@ -596,7 +612,7 @@ var walkField = ({
|
|
596
612
|
return walkObject({
|
597
613
|
value,
|
598
614
|
fields: objectFields,
|
599
|
-
|
615
|
+
mappers,
|
600
616
|
id,
|
601
617
|
getPropPath: (k) => `${propPath}.${k}`,
|
602
618
|
config,
|
@@ -609,7 +625,7 @@ var walkField = ({
|
|
609
625
|
var walkObject = ({
|
610
626
|
value,
|
611
627
|
fields,
|
612
|
-
|
628
|
+
mappers,
|
613
629
|
id,
|
614
630
|
getPropPath,
|
615
631
|
config,
|
@@ -619,7 +635,7 @@ var walkObject = ({
|
|
619
635
|
const opts = {
|
620
636
|
value: v,
|
621
637
|
fields,
|
622
|
-
|
638
|
+
mappers,
|
623
639
|
propKey: k,
|
624
640
|
propPath: getPropPath(k),
|
625
641
|
id,
|
@@ -641,14 +657,14 @@ var walkObject = ({
|
|
641
657
|
}
|
642
658
|
return flatten(newProps);
|
643
659
|
};
|
644
|
-
function
|
660
|
+
function mapFields(item, mappers, config, recurseSlots = false) {
|
645
661
|
var _a, _b, _c, _d, _e;
|
646
662
|
const itemType = "type" in item ? item.type : "root";
|
647
663
|
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
648
664
|
const newProps = walkObject({
|
649
665
|
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
650
666
|
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
651
|
-
|
667
|
+
mappers,
|
652
668
|
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
653
669
|
getPropPath: (k) => k,
|
654
670
|
config,
|
@@ -671,7 +687,7 @@ var import_flat = __toESM(require_flat());
|
|
671
687
|
// ../core/lib/data/strip-slots.ts
|
672
688
|
init_react_import();
|
673
689
|
var stripSlots = (data, config) => {
|
674
|
-
return
|
690
|
+
return mapFields(data, { slot: () => null }, config);
|
675
691
|
};
|
676
692
|
|
677
693
|
// ../core/lib/data/flatten-node.ts
|
@@ -724,18 +740,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
724
740
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
725
741
|
if (!mappedItem) return item;
|
726
742
|
const id = mappedItem.props.id;
|
727
|
-
const newProps = __spreadProps(__spreadValues({},
|
743
|
+
const newProps = __spreadProps(__spreadValues({}, mapFields(
|
728
744
|
mappedItem,
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
745
|
+
{
|
746
|
+
slot: ({ value, parentId: parentId2, propPath }) => {
|
747
|
+
const content = value;
|
748
|
+
const zoneCompound = `${parentId2}:${propPath}`;
|
749
|
+
const [_2, newContent2] = processContent(
|
750
|
+
path,
|
751
|
+
zoneCompound,
|
752
|
+
content,
|
753
|
+
"slot",
|
754
|
+
parentId2
|
755
|
+
);
|
756
|
+
return newContent2;
|
757
|
+
}
|
739
758
|
},
|
740
759
|
config
|
741
760
|
).props), {
|
@@ -910,11 +929,14 @@ init_react_import();
|
|
910
929
|
function walkTree(data, config, callbackFn) {
|
911
930
|
var _a, _b;
|
912
931
|
const walkItem = (item) => {
|
913
|
-
return
|
932
|
+
return mapFields(
|
914
933
|
item,
|
915
|
-
|
916
|
-
|
917
|
-
|
934
|
+
{
|
935
|
+
slot: ({ value, parentId, propName }) => {
|
936
|
+
var _a2;
|
937
|
+
const content = value;
|
938
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
939
|
+
}
|
918
940
|
},
|
919
941
|
config,
|
920
942
|
true
|
@@ -1834,24 +1856,27 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1834
1856
|
resolvedItem.readOnly = readOnly;
|
1835
1857
|
}
|
1836
1858
|
}
|
1837
|
-
let itemWithResolvedChildren = yield
|
1859
|
+
let itemWithResolvedChildren = yield mapFields(
|
1838
1860
|
resolvedItem,
|
1839
|
-
|
1840
|
-
|
1841
|
-
content
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1861
|
+
{
|
1862
|
+
slot: (_02) => __async(void 0, [_02], function* ({ value }) {
|
1863
|
+
const content = value;
|
1864
|
+
return yield Promise.all(
|
1865
|
+
content.map(
|
1866
|
+
(childItem) => __async(void 0, null, function* () {
|
1867
|
+
return (yield resolveComponentData(
|
1868
|
+
childItem,
|
1869
|
+
config,
|
1870
|
+
metadata,
|
1871
|
+
onResolveStart,
|
1872
|
+
onResolveEnd,
|
1873
|
+
trigger
|
1874
|
+
)).node;
|
1875
|
+
})
|
1876
|
+
)
|
1877
|
+
);
|
1878
|
+
})
|
1879
|
+
},
|
1855
1880
|
config
|
1856
1881
|
);
|
1857
1882
|
if (shouldRunResolver && onResolveEnd) {
|
@@ -1933,7 +1958,8 @@ var createAppStore = (initialAppStore) => create()(
|
|
1933
1958
|
},
|
1934
1959
|
status: "LOADING",
|
1935
1960
|
iframe: {},
|
1936
|
-
metadata: {}
|
1961
|
+
metadata: {},
|
1962
|
+
fieldTransforms: {}
|
1937
1963
|
}, initialAppStore), {
|
1938
1964
|
fields: createFieldsSlice(set, get),
|
1939
1965
|
history: createHistorySlice(set, get),
|
@@ -2154,6 +2180,12 @@ init_react_import();
|
|
2154
2180
|
// ../core/lib/data/replace.ts
|
2155
2181
|
init_react_import();
|
2156
2182
|
|
2183
|
+
// ../core/lib/use-reset-auto-zoom.ts
|
2184
|
+
init_react_import();
|
2185
|
+
|
2186
|
+
// ../core/lib/get-zoom-config.ts
|
2187
|
+
init_react_import();
|
2188
|
+
|
2157
2189
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
2158
2190
|
init_react_import();
|
2159
2191
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
package/dist/index.mjs
CHANGED
@@ -509,7 +509,7 @@ function forRelatedZones(item, data, cb, path = []) {
|
|
509
509
|
});
|
510
510
|
}
|
511
511
|
|
512
|
-
// ../core/lib/data/map-
|
512
|
+
// ../core/lib/data/map-fields.ts
|
513
513
|
init_react_import();
|
514
514
|
|
515
515
|
// ../core/lib/data/default-slots.ts
|
@@ -519,14 +519,14 @@ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
|
519
519
|
value
|
520
520
|
);
|
521
521
|
|
522
|
-
// ../core/lib/data/map-
|
522
|
+
// ../core/lib/data/map-fields.ts
|
523
523
|
var isPromise = (v) => !!v && typeof v.then === "function";
|
524
524
|
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
525
525
|
var containsPromise = (arr) => arr.some(isPromise);
|
526
526
|
var walkField = ({
|
527
527
|
value,
|
528
528
|
fields,
|
529
|
-
|
529
|
+
mappers,
|
530
530
|
propKey = "",
|
531
531
|
propPath = "",
|
532
532
|
id = "",
|
@@ -534,7 +534,9 @@ var walkField = ({
|
|
534
534
|
recurseSlots = false
|
535
535
|
}) => {
|
536
536
|
var _a, _b, _c;
|
537
|
-
|
537
|
+
const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
|
538
|
+
const map = mappers[fieldType];
|
539
|
+
if (map && fieldType === "slot") {
|
538
540
|
const content = value || [];
|
539
541
|
const mappedContent = recurseSlots ? content.map((el) => {
|
540
542
|
var _a2;
|
@@ -546,7 +548,7 @@ var walkField = ({
|
|
546
548
|
return walkField({
|
547
549
|
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
548
550
|
fields: fields2,
|
549
|
-
|
551
|
+
mappers,
|
550
552
|
id: el.props.id,
|
551
553
|
config,
|
552
554
|
recurseSlots
|
@@ -555,7 +557,21 @@ var walkField = ({
|
|
555
557
|
if (containsPromise(mappedContent)) {
|
556
558
|
return Promise.all(mappedContent);
|
557
559
|
}
|
558
|
-
return map(
|
560
|
+
return map({
|
561
|
+
value: mappedContent,
|
562
|
+
parentId: id,
|
563
|
+
propName: propKey,
|
564
|
+
field: fields[propKey],
|
565
|
+
propPath
|
566
|
+
});
|
567
|
+
} else if (map && fields[propKey]) {
|
568
|
+
return map({
|
569
|
+
value,
|
570
|
+
parentId: id,
|
571
|
+
propName: propKey,
|
572
|
+
field: fields[propKey],
|
573
|
+
propPath
|
574
|
+
});
|
559
575
|
}
|
560
576
|
if (value && typeof value === "object") {
|
561
577
|
if (Array.isArray(value)) {
|
@@ -565,7 +581,7 @@ var walkField = ({
|
|
565
581
|
(el, idx) => walkField({
|
566
582
|
value: el,
|
567
583
|
fields: arrayFields,
|
568
|
-
|
584
|
+
mappers,
|
569
585
|
propKey,
|
570
586
|
propPath: `${propPath}[${idx}]`,
|
571
587
|
id,
|
@@ -584,7 +600,7 @@ var walkField = ({
|
|
584
600
|
return walkObject({
|
585
601
|
value,
|
586
602
|
fields: objectFields,
|
587
|
-
|
603
|
+
mappers,
|
588
604
|
id,
|
589
605
|
getPropPath: (k) => `${propPath}.${k}`,
|
590
606
|
config,
|
@@ -597,7 +613,7 @@ var walkField = ({
|
|
597
613
|
var walkObject = ({
|
598
614
|
value,
|
599
615
|
fields,
|
600
|
-
|
616
|
+
mappers,
|
601
617
|
id,
|
602
618
|
getPropPath,
|
603
619
|
config,
|
@@ -607,7 +623,7 @@ var walkObject = ({
|
|
607
623
|
const opts = {
|
608
624
|
value: v,
|
609
625
|
fields,
|
610
|
-
|
626
|
+
mappers,
|
611
627
|
propKey: k,
|
612
628
|
propPath: getPropPath(k),
|
613
629
|
id,
|
@@ -629,14 +645,14 @@ var walkObject = ({
|
|
629
645
|
}
|
630
646
|
return flatten(newProps);
|
631
647
|
};
|
632
|
-
function
|
648
|
+
function mapFields(item, mappers, config, recurseSlots = false) {
|
633
649
|
var _a, _b, _c, _d, _e;
|
634
650
|
const itemType = "type" in item ? item.type : "root";
|
635
651
|
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
636
652
|
const newProps = walkObject({
|
637
653
|
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
638
654
|
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
639
|
-
|
655
|
+
mappers,
|
640
656
|
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
641
657
|
getPropPath: (k) => k,
|
642
658
|
config,
|
@@ -659,7 +675,7 @@ var import_flat = __toESM(require_flat());
|
|
659
675
|
// ../core/lib/data/strip-slots.ts
|
660
676
|
init_react_import();
|
661
677
|
var stripSlots = (data, config) => {
|
662
|
-
return
|
678
|
+
return mapFields(data, { slot: () => null }, config);
|
663
679
|
};
|
664
680
|
|
665
681
|
// ../core/lib/data/flatten-node.ts
|
@@ -712,18 +728,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
712
728
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
713
729
|
if (!mappedItem) return item;
|
714
730
|
const id = mappedItem.props.id;
|
715
|
-
const newProps = __spreadProps(__spreadValues({},
|
731
|
+
const newProps = __spreadProps(__spreadValues({}, mapFields(
|
716
732
|
mappedItem,
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
733
|
+
{
|
734
|
+
slot: ({ value, parentId: parentId2, propPath }) => {
|
735
|
+
const content = value;
|
736
|
+
const zoneCompound = `${parentId2}:${propPath}`;
|
737
|
+
const [_2, newContent2] = processContent(
|
738
|
+
path,
|
739
|
+
zoneCompound,
|
740
|
+
content,
|
741
|
+
"slot",
|
742
|
+
parentId2
|
743
|
+
);
|
744
|
+
return newContent2;
|
745
|
+
}
|
727
746
|
},
|
728
747
|
config
|
729
748
|
).props), {
|
@@ -898,11 +917,14 @@ init_react_import();
|
|
898
917
|
function walkTree(data, config, callbackFn) {
|
899
918
|
var _a, _b;
|
900
919
|
const walkItem = (item) => {
|
901
|
-
return
|
920
|
+
return mapFields(
|
902
921
|
item,
|
903
|
-
|
904
|
-
|
905
|
-
|
922
|
+
{
|
923
|
+
slot: ({ value, parentId, propName }) => {
|
924
|
+
var _a2;
|
925
|
+
const content = value;
|
926
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
927
|
+
}
|
906
928
|
},
|
907
929
|
config,
|
908
930
|
true
|
@@ -1822,24 +1844,27 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1822
1844
|
resolvedItem.readOnly = readOnly;
|
1823
1845
|
}
|
1824
1846
|
}
|
1825
|
-
let itemWithResolvedChildren = yield
|
1847
|
+
let itemWithResolvedChildren = yield mapFields(
|
1826
1848
|
resolvedItem,
|
1827
|
-
|
1828
|
-
|
1829
|
-
content
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1849
|
+
{
|
1850
|
+
slot: (_02) => __async(void 0, [_02], function* ({ value }) {
|
1851
|
+
const content = value;
|
1852
|
+
return yield Promise.all(
|
1853
|
+
content.map(
|
1854
|
+
(childItem) => __async(void 0, null, function* () {
|
1855
|
+
return (yield resolveComponentData(
|
1856
|
+
childItem,
|
1857
|
+
config,
|
1858
|
+
metadata,
|
1859
|
+
onResolveStart,
|
1860
|
+
onResolveEnd,
|
1861
|
+
trigger
|
1862
|
+
)).node;
|
1863
|
+
})
|
1864
|
+
)
|
1865
|
+
);
|
1866
|
+
})
|
1867
|
+
},
|
1843
1868
|
config
|
1844
1869
|
);
|
1845
1870
|
if (shouldRunResolver && onResolveEnd) {
|
@@ -1921,7 +1946,8 @@ var createAppStore = (initialAppStore) => create()(
|
|
1921
1946
|
},
|
1922
1947
|
status: "LOADING",
|
1923
1948
|
iframe: {},
|
1924
|
-
metadata: {}
|
1949
|
+
metadata: {},
|
1950
|
+
fieldTransforms: {}
|
1925
1951
|
}, initialAppStore), {
|
1926
1952
|
fields: createFieldsSlice(set, get),
|
1927
1953
|
history: createHistorySlice(set, get),
|
@@ -2142,6 +2168,12 @@ init_react_import();
|
|
2142
2168
|
// ../core/lib/data/replace.ts
|
2143
2169
|
init_react_import();
|
2144
2170
|
|
2171
|
+
// ../core/lib/use-reset-auto-zoom.ts
|
2172
|
+
init_react_import();
|
2173
|
+
|
2174
|
+
// ../core/lib/get-zoom-config.ts
|
2175
|
+
init_react_import();
|
2176
|
+
|
2145
2177
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
2146
2178
|
init_react_import();
|
2147
2179
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@measured/puck-plugin-heading-analyzer",
|
3
|
-
"version": "0.20.0-canary.
|
3
|
+
"version": "0.20.0-canary.29cd4d52",
|
4
4
|
"author": "Chris Villa <chris@puckeditor.com>",
|
5
5
|
"repository": "measuredco/puck",
|
6
6
|
"bugs": "https://github.com/measuredco/puck/issues",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"dist"
|
26
26
|
],
|
27
27
|
"devDependencies": {
|
28
|
-
"@measured/puck": "^0.20.0-canary.
|
28
|
+
"@measured/puck": "^0.20.0-canary.29cd4d52",
|
29
29
|
"@types/react": "^19.0.1",
|
30
30
|
"@types/react-dom": "^19.0.2",
|
31
31
|
"eslint": "^7.32.0",
|