@measured/puck 0.16.0-canary.a43914d → 0.16.0-canary.acdb11d

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,443 @@
1
+ import { CSSProperties, ReactElement, ReactNode } from 'react';
2
+
3
+ type ItemSelector = {
4
+ index: number;
5
+ zone?: string;
6
+ };
7
+
8
+ type DropZoneProps = {
9
+ zone: string;
10
+ allow?: string[];
11
+ disallow?: string[];
12
+ style?: CSSProperties;
13
+ };
14
+
15
+ type FieldOption = {
16
+ label: string;
17
+ value: string | number | boolean;
18
+ };
19
+ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
20
+ type BaseField = {
21
+ label?: string;
22
+ };
23
+ type TextField = BaseField & {
24
+ type: "text";
25
+ };
26
+ type NumberField = BaseField & {
27
+ type: "number";
28
+ min?: number;
29
+ max?: number;
30
+ };
31
+ type TextareaField = BaseField & {
32
+ type: "textarea";
33
+ };
34
+ type SelectField = BaseField & {
35
+ type: "select";
36
+ options: FieldOptions;
37
+ };
38
+ type RadioField = BaseField & {
39
+ type: "radio";
40
+ options: FieldOptions;
41
+ };
42
+ type ArrayField<Props extends {
43
+ [key: string]: any;
44
+ } = {
45
+ [key: string]: any;
46
+ }> = BaseField & {
47
+ type: "array";
48
+ arrayFields: {
49
+ [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
50
+ };
51
+ defaultItemProps?: Props[0];
52
+ getItemSummary?: (item: Props[0], index?: number) => string;
53
+ max?: number;
54
+ min?: number;
55
+ };
56
+ type ObjectField<Props extends {
57
+ [key: string]: any;
58
+ } = {
59
+ [key: string]: any;
60
+ }> = BaseField & {
61
+ type: "object";
62
+ objectFields: Props extends any[] ? never : {
63
+ [SubPropName in keyof Props]: Field<Props[SubPropName]>;
64
+ };
65
+ };
66
+ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
67
+ name: string;
68
+ fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
69
+ mapProp?: (value: TableShape) => PropShape;
70
+ };
71
+ type ExternalFieldWithAdaptor<Props extends {
72
+ [key: string]: any;
73
+ } = {
74
+ [key: string]: any;
75
+ }> = BaseField & {
76
+ type: "external";
77
+ placeholder?: string;
78
+ adaptor: Adaptor<any, any, Props>;
79
+ adaptorParams?: object;
80
+ getItemSummary: (item: Props, index?: number) => string;
81
+ };
82
+ type ExternalField<Props extends {
83
+ [key: string]: any;
84
+ } = {
85
+ [key: string]: any;
86
+ }> = BaseField & {
87
+ type: "external";
88
+ placeholder?: string;
89
+ fetchList: (params: {
90
+ query: string;
91
+ filters: Record<string, any>;
92
+ }) => Promise<any[] | null>;
93
+ mapProp?: (value: any) => Props;
94
+ mapRow?: (value: any) => Record<string, string | number>;
95
+ getItemSummary?: (item: Props, index?: number) => string;
96
+ showSearch?: boolean;
97
+ initialQuery?: string;
98
+ filterFields?: Record<string, Field>;
99
+ initialFilters?: Record<string, any>;
100
+ };
101
+ type CustomField<Props extends any = {}> = BaseField & {
102
+ type: "custom";
103
+ render: (props: {
104
+ field: CustomField<Props>;
105
+ name: string;
106
+ id: string;
107
+ value: Props;
108
+ onChange: (value: Props) => void;
109
+ readOnly?: boolean;
110
+ }) => ReactElement;
111
+ };
112
+ type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
113
+ [key: string]: any;
114
+ } ? Props : any> | ObjectField<Props extends {
115
+ [key: string]: any;
116
+ } ? Props : any> | ExternalField<Props extends {
117
+ [key: string]: any;
118
+ } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
119
+ [key: string]: any;
120
+ } ? Props : any> | CustomField<Props>;
121
+ type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
122
+ [PropName in keyof Omit<ComponentProps, "editMode">]: Field<ComponentProps[PropName]>;
123
+ };
124
+ type FieldProps<ValueType = any, F = Field<any>> = {
125
+ field: F;
126
+ value: ValueType;
127
+ id?: string;
128
+ onChange: (value: ValueType, uiState?: Partial<UiState>) => void;
129
+ readOnly?: boolean;
130
+ };
131
+
132
+ type PuckComponent<Props> = (props: WithId<WithPuckProps<Props>>) => JSX.Element;
133
+ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
134
+ render: PuckComponent<RenderProps>;
135
+ label?: string;
136
+ defaultProps?: FieldProps;
137
+ fields?: Fields<FieldProps>;
138
+ permissions?: Partial<Permissions>;
139
+ resolveFields?: (data: DataShape, params: {
140
+ changed: Partial<Record<keyof FieldProps, boolean>>;
141
+ fields: Fields<FieldProps>;
142
+ lastFields: Fields<FieldProps>;
143
+ lastData: DataShape | null;
144
+ appState: AppState;
145
+ }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
146
+ resolveData?: (data: DataShape, params: {
147
+ changed: Partial<Record<keyof FieldProps, boolean>>;
148
+ lastData: DataShape | null;
149
+ }) => Promise<{
150
+ props?: Partial<FieldProps>;
151
+ readOnly?: Partial<Record<keyof FieldProps, boolean>>;
152
+ }> | {
153
+ props?: Partial<FieldProps>;
154
+ readOnly?: Partial<Record<keyof FieldProps, boolean>>;
155
+ };
156
+ resolvePermissions?: (data: DataShape, params: {
157
+ changed: Partial<Record<keyof FieldProps, boolean>>;
158
+ lastPermissions: Partial<Permissions>;
159
+ permissions: Partial<Permissions>;
160
+ appState: AppState;
161
+ lastData: DataShape | null;
162
+ }) => Promise<Partial<Permissions>> | Partial<Permissions>;
163
+ };
164
+ type Category<ComponentName> = {
165
+ components?: ComponentName[];
166
+ title?: string;
167
+ visible?: boolean;
168
+ defaultExpanded?: boolean;
169
+ };
170
+ type Config<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = any, CategoryName extends string = string> = {
171
+ categories?: Record<CategoryName, Category<keyof Props>> & {
172
+ other?: Category<keyof Props>;
173
+ };
174
+ components: {
175
+ [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
176
+ };
177
+ root?: Partial<ComponentConfig<DefaultRootRenderProps<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
178
+ };
179
+
180
+ type WithId<Props> = Props & {
181
+ id: string;
182
+ };
183
+ type WithPuckProps<Props> = Props & {
184
+ puck: PuckContext;
185
+ editMode?: boolean;
186
+ };
187
+ type AsFieldProps<Props> = Omit<Props, "children" | "puck" | "editMode">;
188
+ type WithChildren<Props> = Props & {
189
+ children: ReactNode;
190
+ };
191
+ type ExtractPropsFromConfig<UserConfig> = UserConfig extends Config<infer P, any, any> ? P : never;
192
+ type ExtractRootPropsFromConfig<UserConfig> = UserConfig extends Config<any, infer P, any> ? P : never;
193
+ type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends AppState<UserData> = AppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
194
+ UserConfig: UserConfig;
195
+ UserProps: UserProps;
196
+ UserRootProps: UserRootProps;
197
+ UserData: UserData;
198
+ UserAppState: UserAppState;
199
+ UserComponentData: UserComponentData;
200
+ };
201
+
202
+ type PuckContext = {
203
+ renderDropZone: React.FC<DropZoneProps>;
204
+ isEditing: boolean;
205
+ };
206
+ type DefaultRootFieldProps = {
207
+ title?: string;
208
+ };
209
+ type DefaultRootRenderProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = WithPuckProps<WithChildren<Props>>;
210
+ type DefaultRootProps = DefaultRootRenderProps;
211
+ type DefaultComponentProps = {
212
+ [key: string]: any;
213
+ };
214
+
215
+ type BaseData<Props extends {
216
+ [key: string]: any;
217
+ } = {
218
+ [key: string]: any;
219
+ }> = {
220
+ readOnly?: Partial<Record<keyof Props, boolean>>;
221
+ };
222
+ type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
223
+ props: Props;
224
+ };
225
+ type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
226
+ type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
227
+ type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
228
+ type: Name;
229
+ props: WithId<Props>;
230
+ } & BaseData<Props>;
231
+ type MappedItem = ComponentData;
232
+ type ComponentDataMap<Props extends Record<string, DefaultComponentProps> = DefaultComponentProps> = {
233
+ [K in keyof Props]: ComponentData<Props[K], K extends string ? K : never>;
234
+ }[keyof Props];
235
+ type Content<PropsMap extends {
236
+ [key: string]: any;
237
+ } = {
238
+ [key: string]: any;
239
+ }> = ComponentDataMap<PropsMap>[];
240
+ type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
241
+ root: RootData<RootProps>;
242
+ content: Content<Props>;
243
+ zones?: Record<string, Content<Props>>;
244
+ };
245
+
246
+ type ItemWithId = {
247
+ _arrayId: string;
248
+ _originalIndex: number;
249
+ };
250
+ type ArrayState = {
251
+ items: ItemWithId[];
252
+ openId: string;
253
+ };
254
+ type UiState = {
255
+ leftSideBarVisible: boolean;
256
+ rightSideBarVisible: boolean;
257
+ itemSelector: ItemSelector | null;
258
+ arrayState: Record<string, ArrayState | undefined>;
259
+ componentList: Record<string, {
260
+ components?: string[];
261
+ title?: string;
262
+ visible?: boolean;
263
+ expanded?: boolean;
264
+ }>;
265
+ isDragging: boolean;
266
+ viewports: {
267
+ current: {
268
+ width: number;
269
+ height: number | "auto";
270
+ };
271
+ controlsVisible: boolean;
272
+ options: Viewport[];
273
+ };
274
+ };
275
+ type AppState<UserData extends Data = Data> = {
276
+ data: UserData;
277
+ ui: UiState;
278
+ };
279
+
280
+ type RenderFunc<Props extends {
281
+ [key: string]: any;
282
+ } = {
283
+ children: ReactNode;
284
+ }> = (props: Props) => ReactElement;
285
+ declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
286
+ type OverrideKey = (typeof overrideKeys)[number];
287
+ type OverridesGeneric<Shape extends {
288
+ [key in OverrideKey]: any;
289
+ }> = Shape;
290
+ type Overrides = OverridesGeneric<{
291
+ fieldTypes: Partial<FieldRenderFunctions>;
292
+ header: RenderFunc<{
293
+ actions: ReactNode;
294
+ children: ReactNode;
295
+ }>;
296
+ actionBar: RenderFunc<{
297
+ label?: string;
298
+ children: ReactNode;
299
+ }>;
300
+ headerActions: RenderFunc<{
301
+ children: ReactNode;
302
+ }>;
303
+ preview: RenderFunc;
304
+ fields: RenderFunc<{
305
+ children: ReactNode;
306
+ isLoading: boolean;
307
+ itemSelector?: ItemSelector | null;
308
+ }>;
309
+ fieldLabel: RenderFunc<{
310
+ children?: ReactNode;
311
+ icon?: ReactNode;
312
+ label: string;
313
+ el?: "label" | "div";
314
+ readOnly?: boolean;
315
+ className?: string;
316
+ }>;
317
+ components: RenderFunc;
318
+ componentItem: RenderFunc<{
319
+ children: ReactNode;
320
+ name: string;
321
+ }>;
322
+ iframe: RenderFunc<{
323
+ children: ReactNode;
324
+ document?: Document;
325
+ }>;
326
+ outline: RenderFunc;
327
+ puck: RenderFunc;
328
+ }>;
329
+ type FieldRenderFunctions = Omit<{
330
+ [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
331
+ type: Type;
332
+ }>> & {
333
+ children: ReactNode;
334
+ name: string;
335
+ }>;
336
+ }, "custom"> & {
337
+ [key: string]: React.FunctionComponent<FieldProps<any> & {
338
+ children: ReactNode;
339
+ name: string;
340
+ }>;
341
+ };
342
+
343
+ type iconTypes = "Smartphone" | "Monitor" | "Tablet";
344
+ type Viewport = {
345
+ width: number;
346
+ height?: number | "auto";
347
+ label?: string;
348
+ icon?: iconTypes | ReactNode;
349
+ };
350
+ type Viewports = Viewport[];
351
+
352
+ type Permissions = {
353
+ drag: boolean;
354
+ duplicate: boolean;
355
+ delete: boolean;
356
+ edit: boolean;
357
+ insert: boolean;
358
+ } & Record<string, boolean>;
359
+ type IframeConfig = {
360
+ enabled?: boolean;
361
+ waitForStyles?: boolean;
362
+ };
363
+ type OnAction<UserData extends Data = Data> = (action: PuckAction, appState: AppState<UserData>, prevAppState: AppState<UserData>) => void;
364
+ type Plugin = {
365
+ overrides: Partial<Overrides>;
366
+ };
367
+ type History<D = any> = {
368
+ state: D;
369
+ id?: string;
370
+ };
371
+ type InitialHistoryAppend<AS = Partial<AppState>> = {
372
+ histories: History<AS>[];
373
+ index?: number;
374
+ appendData?: true;
375
+ };
376
+ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
377
+ histories: [History<AS>, ...History<AS>[]];
378
+ index?: number;
379
+ appendData?: false;
380
+ };
381
+ type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
382
+
383
+ type InsertAction = {
384
+ type: "insert";
385
+ componentType: string;
386
+ destinationIndex: number;
387
+ destinationZone: string;
388
+ id?: string;
389
+ };
390
+ type DuplicateAction = {
391
+ type: "duplicate";
392
+ sourceIndex: number;
393
+ sourceZone: string;
394
+ };
395
+ type ReplaceAction = {
396
+ type: "replace";
397
+ destinationIndex: number;
398
+ destinationZone: string;
399
+ data: any;
400
+ };
401
+ type ReorderAction = {
402
+ type: "reorder";
403
+ sourceIndex: number;
404
+ destinationIndex: number;
405
+ destinationZone: string;
406
+ };
407
+ type MoveAction = {
408
+ type: "move";
409
+ sourceIndex: number;
410
+ sourceZone: string;
411
+ destinationIndex: number;
412
+ destinationZone: string;
413
+ };
414
+ type RemoveAction = {
415
+ type: "remove";
416
+ index: number;
417
+ zone: string;
418
+ };
419
+ type SetUiAction = {
420
+ type: "setUi";
421
+ ui: Partial<UiState> | ((previous: UiState) => Partial<UiState>);
422
+ };
423
+ type SetDataAction = {
424
+ type: "setData";
425
+ data: Partial<Data> | ((previous: Data) => Partial<Data>);
426
+ };
427
+ type SetAction<UserData extends Data = Data> = {
428
+ type: "set";
429
+ state: Partial<AppState<UserData>> | ((previous: AppState<UserData>) => Partial<AppState<UserData>>);
430
+ };
431
+ type RegisterZoneAction = {
432
+ type: "registerZone";
433
+ zone: string;
434
+ };
435
+ type UnregisterZoneAction = {
436
+ type: "unregisterZone";
437
+ zone: string;
438
+ };
439
+ type PuckAction = {
440
+ recordHistory?: boolean;
441
+ } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
442
+
443
+ export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type Data as D, type ExtractPropsFromConfig as E, type Field as F, type RadioField as G, type History as H, type ItemSelector as I, type ArrayField as J, type ObjectField as K, type Adaptor as L, type MappedItem as M, type NumberField as N, type OnAction as O, type PuckAction as P, type ExternalFieldWithAdaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalField as W, type CustomField as X, type Fields as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type FieldProps as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, type DropZoneProps as b, type UiState as c, type Permissions as d, type Plugin as e, type Overrides as f, type IframeConfig as g, type InitialHistory as h, type DefaultComponentProps as i, type DefaultRootFieldProps as j, type ComponentData as k, type ExtractRootPropsFromConfig as l, type ComponentDataMap as m, type Viewport as n, overrideKeys as o, type OverrideKey as p, type FieldRenderFunctions as q, type ItemWithId as r, type ArrayState as s, type PuckComponent as t, type ComponentConfig as u, type RootDataWithoutProps as v, type RootData as w, type Content as x, type BaseField as y, type TextareaField as z };
@@ -0,0 +1,114 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
36
+ var __esm = (fn, res) => function __init() {
37
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
38
+ };
39
+ var __commonJS = (cb, mod) => function __require() {
40
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
+ };
42
+ var __copyProps = (to, from, except, desc) => {
43
+ if (from && typeof from === "object" || typeof from === "function") {
44
+ for (let key of __getOwnPropNames(from))
45
+ if (!__hasOwnProp.call(to, key) && key !== except)
46
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
+ }
48
+ return to;
49
+ };
50
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
+ mod
57
+ ));
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
78
+
79
+ // ../tsup-config/react-import.js
80
+ import React from "react";
81
+ var init_react_import = __esm({
82
+ "../tsup-config/react-import.js"() {
83
+ "use strict";
84
+ }
85
+ });
86
+
87
+ // lib/root-droppable-id.ts
88
+ init_react_import();
89
+ var rootDroppableId = "default-zone";
90
+
91
+ // lib/setup-zone.ts
92
+ init_react_import();
93
+ var setupZone = (data, zoneKey) => {
94
+ if (zoneKey === rootDroppableId) {
95
+ return data;
96
+ }
97
+ const newData = __spreadProps(__spreadValues({}, data), {
98
+ zones: data.zones || {}
99
+ });
100
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
101
+ return newData;
102
+ };
103
+
104
+ export {
105
+ __spreadValues,
106
+ __spreadProps,
107
+ __objRest,
108
+ __commonJS,
109
+ __toESM,
110
+ __async,
111
+ init_react_import,
112
+ rootDroppableId,
113
+ setupZone
114
+ };