@measured/puck 0.16.0-canary.4ee30eb → 0.16.0-canary.53c8bfc

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,7 +68,7 @@ type ObjectField<Props extends {
68
68
  [key: string]: any;
69
69
  }> = BaseField & {
70
70
  type: "object";
71
- objectFields: {
71
+ objectFields: Props extends any[] ? never : {
72
72
  [SubPropName in keyof Props]: Field<Props[SubPropName]>;
73
73
  };
74
74
  };
@@ -166,6 +166,7 @@ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultCompo
166
166
  label?: string;
167
167
  defaultProps?: DefaultProps;
168
168
  fields?: Fields<ComponentProps>;
169
+ permissions?: Partial<Permissions>;
169
170
  resolveFields?: (data: DataShape, params: {
170
171
  changed: Partial<Record<keyof ComponentProps, boolean>>;
171
172
  fields: Fields<ComponentProps>;
@@ -183,6 +184,12 @@ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultCompo
183
184
  props?: Partial<ComponentProps>;
184
185
  readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
185
186
  };
187
+ resolvePermissions?: (data: DataShape, params: {
188
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
189
+ lastPermissions: Partial<Permissions> | undefined;
190
+ initialPermissions: Partial<Permissions>;
191
+ appState: AppState;
192
+ }) => Partial<Permissions>;
186
193
  };
187
194
  type Category<ComponentName> = {
188
195
  components?: ComponentName[];
@@ -258,5 +265,12 @@ type AppState = {
258
265
  data: Data;
259
266
  ui: UiState;
260
267
  };
268
+ type Permissions = {
269
+ drag: boolean;
270
+ duplicate: boolean;
271
+ delete: boolean;
272
+ edit: boolean;
273
+ insert: boolean;
274
+ } & Record<string, boolean>;
261
275
 
262
- export { AppState as A, BaseData as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, PuckComponent as P, RootDataWithProps as R, SelectField as S, TextField as T, UiState as U, Viewports as V, FieldProps as a, DefaultRootProps as b, DropZoneProps as c, DefaultComponentProps as d, RootData as e, ComponentData as f, Content as g, PuckContext as h, ComponentConfig as i, RootDataWithoutProps as j, ItemWithId as k, ArrayState as l, BaseField as m, TextareaField as n, RadioField as o, ArrayField as p, Adaptor as q, ExternalField as r, CustomField as s, Fields as t };
276
+ export type { AppState as A, BaseData as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, Permissions as P, RootData as R, SelectField as S, TextField as T, UiState as U, Viewports as V, FieldProps as a, DropZoneProps as b, DefaultComponentProps as c, DefaultRootProps as d, RootDataWithProps as e, ComponentData as f, Content as g, PuckComponent as h, PuckContext as i, ComponentConfig as j, RootDataWithoutProps as k, ItemWithId as l, ArrayState as m, BaseField as n, TextareaField as o, RadioField as p, ArrayField as q, Adaptor as r, ExternalField as s, CustomField as t, Fields as u };
@@ -0,0 +1,276 @@
1
+ import { CSSProperties, ReactNode, ReactElement } 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 iconTypes = "Smartphone" | "Monitor" | "Tablet";
16
+ type Viewport = {
17
+ width: number;
18
+ height?: number | "auto";
19
+ label?: string;
20
+ icon?: iconTypes | ReactNode;
21
+ };
22
+ type Viewports = Viewport[];
23
+
24
+ type FieldOption = {
25
+ label: string;
26
+ value: string | number | boolean;
27
+ };
28
+ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
29
+ type BaseField = {
30
+ label?: string;
31
+ };
32
+ type TextField = BaseField & {
33
+ type: "text";
34
+ };
35
+ type NumberField = BaseField & {
36
+ type: "number";
37
+ min?: number;
38
+ max?: number;
39
+ };
40
+ type TextareaField = BaseField & {
41
+ type: "textarea";
42
+ };
43
+ type SelectField = BaseField & {
44
+ type: "select";
45
+ options: FieldOptions;
46
+ };
47
+ type RadioField = BaseField & {
48
+ type: "radio";
49
+ options: FieldOptions;
50
+ };
51
+ type ArrayField<Props extends {
52
+ [key: string]: any;
53
+ } = {
54
+ [key: string]: any;
55
+ }> = BaseField & {
56
+ type: "array";
57
+ arrayFields: {
58
+ [SubPropName in keyof Props[0]]: Field<Props[0][SubPropName]>;
59
+ };
60
+ defaultItemProps?: Props[0];
61
+ getItemSummary?: (item: Props[0], index?: number) => string;
62
+ max?: number;
63
+ min?: number;
64
+ };
65
+ type ObjectField<Props extends {
66
+ [key: string]: any;
67
+ } = {
68
+ [key: string]: any;
69
+ }> = BaseField & {
70
+ type: "object";
71
+ objectFields: Props extends any[] ? never : {
72
+ [SubPropName in keyof Props]: Field<Props[SubPropName]>;
73
+ };
74
+ };
75
+ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
76
+ name: string;
77
+ fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
78
+ mapProp?: (value: TableShape) => PropShape;
79
+ };
80
+ type ExternalFieldWithAdaptor<Props extends {
81
+ [key: string]: any;
82
+ } = {
83
+ [key: string]: any;
84
+ }> = BaseField & {
85
+ type: "external";
86
+ placeholder?: string;
87
+ adaptor: Adaptor<any, any, Props>;
88
+ adaptorParams?: object;
89
+ getItemSummary: (item: Props, index?: number) => string;
90
+ };
91
+ type ExternalField<Props extends {
92
+ [key: string]: any;
93
+ } = {
94
+ [key: string]: any;
95
+ }> = BaseField & {
96
+ type: "external";
97
+ placeholder?: string;
98
+ fetchList: (params: {
99
+ query: string;
100
+ filters: Record<string, any>;
101
+ }) => Promise<any[] | null>;
102
+ mapProp?: (value: any) => Props;
103
+ mapRow?: (value: any) => Record<string, string | number>;
104
+ getItemSummary?: (item: Props, index?: number) => string;
105
+ showSearch?: boolean;
106
+ initialQuery?: string;
107
+ filterFields?: Record<string, Field>;
108
+ initialFilters?: Record<string, any>;
109
+ };
110
+ type CustomField<Props extends any = {}> = BaseField & {
111
+ type: "custom";
112
+ render: (props: {
113
+ field: CustomField<Props>;
114
+ name: string;
115
+ id: string;
116
+ value: Props;
117
+ onChange: (value: Props) => void;
118
+ readOnly?: boolean;
119
+ }) => ReactElement;
120
+ };
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>;
130
+ type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
131
+ [PropName in keyof Omit<Required<ComponentProps>, "children" | "editMode">]: Field<ComponentProps[PropName]>;
132
+ };
133
+ type FieldProps<ValueType = any, F = Field<any>> = {
134
+ field: F;
135
+ value: ValueType;
136
+ id?: string;
137
+ onChange: (value: ValueType, uiState?: Partial<UiState>) => void;
138
+ readOnly?: boolean;
139
+ };
140
+
141
+ type WithPuckProps<Props> = Props & {
142
+ id: string;
143
+ };
144
+ type DefaultRootProps = {
145
+ title?: string;
146
+ [key: string]: any;
147
+ };
148
+ type DefaultComponentProps = {
149
+ [key: string]: any;
150
+ editMode?: boolean;
151
+ };
152
+ type Content<Props extends {
153
+ [key: string]: any;
154
+ } = {
155
+ [key: string]: any;
156
+ }> = ComponentData<Props>[];
157
+ type PuckComponent<Props> = (props: WithPuckProps<Props & {
158
+ puck: PuckContext;
159
+ }>) => JSX.Element;
160
+ type PuckContext = {
161
+ renderDropZone: React.FC<DropZoneProps>;
162
+ isEditing: boolean;
163
+ };
164
+ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultComponentProps, DefaultProps = ComponentProps, DataShape = Omit<ComponentData<ComponentProps>, "type">> = {
165
+ render: PuckComponent<ComponentProps>;
166
+ label?: string;
167
+ defaultProps?: DefaultProps;
168
+ fields?: Fields<ComponentProps>;
169
+ permissions?: Partial<Permissions>;
170
+ resolveFields?: (data: DataShape, params: {
171
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
172
+ fields: Fields<ComponentProps>;
173
+ lastFields: Fields<ComponentProps>;
174
+ lastData: DataShape;
175
+ appState: AppState;
176
+ }) => Promise<Fields<ComponentProps>> | Fields<ComponentProps>;
177
+ resolveData?: (data: DataShape, params: {
178
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
179
+ lastData: DataShape;
180
+ }) => Promise<{
181
+ props?: Partial<ComponentProps>;
182
+ readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
183
+ }> | {
184
+ props?: Partial<ComponentProps>;
185
+ readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
186
+ };
187
+ resolvePermissions?: (data: DataShape, params: {
188
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
189
+ lastPermissions: Partial<Permissions> | undefined;
190
+ initialPermissions: Partial<Permissions>;
191
+ appState: AppState;
192
+ }) => Partial<Permissions>;
193
+ };
194
+ type Category<ComponentName> = {
195
+ components?: ComponentName[];
196
+ title?: string;
197
+ visible?: boolean;
198
+ defaultExpanded?: boolean;
199
+ };
200
+ type Config<Props extends Record<string, any> = Record<string, any>, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = string> = {
201
+ categories?: Record<CategoryName, Category<keyof Props>> & {
202
+ other?: Category<keyof Props>;
203
+ };
204
+ components: {
205
+ [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
206
+ };
207
+ root?: Partial<ComponentConfig<RootProps & {
208
+ children?: ReactNode;
209
+ }, Partial<RootProps & {
210
+ children?: ReactNode;
211
+ }>, RootData>>;
212
+ };
213
+ type BaseData<Props extends {
214
+ [key: string]: any;
215
+ } = {
216
+ [key: string]: any;
217
+ }> = {
218
+ readOnly?: Partial<Record<keyof Props, boolean>>;
219
+ };
220
+ type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps> = {
221
+ type: keyof Props;
222
+ props: WithPuckProps<Props>;
223
+ } & BaseData<Props>;
224
+ type RootDataWithProps<Props extends DefaultRootProps = DefaultRootProps> = BaseData<Props> & {
225
+ props: Props;
226
+ };
227
+ type RootDataWithoutProps<Props extends DefaultRootProps = DefaultRootProps> = Props;
228
+ type RootData<Props extends DefaultRootProps = DefaultRootProps> = Partial<RootDataWithProps<Props>> & Partial<RootDataWithoutProps<Props>>;
229
+ type MappedItem = ComponentData;
230
+ type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = {
231
+ root: RootData<RootProps>;
232
+ content: Content<WithPuckProps<Props>>;
233
+ zones?: Record<string, Content<WithPuckProps<Props>>>;
234
+ };
235
+ type ItemWithId = {
236
+ _arrayId: string;
237
+ _originalIndex: number;
238
+ };
239
+ type ArrayState = {
240
+ items: ItemWithId[];
241
+ openId: string;
242
+ };
243
+ type UiState = {
244
+ leftSideBarVisible: boolean;
245
+ rightSideBarVisible: boolean;
246
+ itemSelector: ItemSelector | null;
247
+ arrayState: Record<string, ArrayState | undefined>;
248
+ componentList: Record<string, {
249
+ components?: string[];
250
+ title?: string;
251
+ visible?: boolean;
252
+ expanded?: boolean;
253
+ }>;
254
+ isDragging: boolean;
255
+ viewports: {
256
+ current: {
257
+ width: number;
258
+ height: number | "auto";
259
+ };
260
+ controlsVisible: boolean;
261
+ options: Viewport[];
262
+ };
263
+ };
264
+ type AppState = {
265
+ data: Data;
266
+ ui: UiState;
267
+ };
268
+ type Permissions = {
269
+ drag: boolean;
270
+ duplicate: boolean;
271
+ delete: boolean;
272
+ edit: boolean;
273
+ insert: boolean;
274
+ } & Record<string, boolean>;
275
+
276
+ export type { AppState as A, BaseData as B, Config as C, Data as D, ExternalFieldWithAdaptor as E, Field as F, ItemSelector as I, MappedItem as M, NumberField as N, ObjectField as O, Permissions as P, RootData as R, SelectField as S, TextField as T, UiState as U, Viewports as V, FieldProps as a, DropZoneProps as b, DefaultComponentProps as c, DefaultRootProps as d, RootDataWithProps as e, ComponentData as f, Content as g, PuckComponent as h, PuckContext as i, ComponentConfig as j, RootDataWithoutProps as k, ItemWithId as l, ArrayState as m, BaseField as n, TextareaField as o, RadioField as p, ArrayField as q, Adaptor as r, ExternalField as s, CustomField as t, Fields as u };
@@ -0,0 +1,113 @@
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 = __spreadValues({}, data);
98
+ newData.zones = data.zones || {};
99
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
100
+ return newData;
101
+ };
102
+
103
+ export {
104
+ __spreadValues,
105
+ __spreadProps,
106
+ __objRest,
107
+ __commonJS,
108
+ __toESM,
109
+ __async,
110
+ init_react_import,
111
+ rootDroppableId,
112
+ setupZone
113
+ };