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

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.ts CHANGED
@@ -1,133 +1,10 @@
1
- import { U as UiState, D as Data, A as AppState, I as ItemSelector, F as Field, a as FieldProps, C as Config, b as DropZoneProps, P as Permissions, V as Viewports, c as DefaultComponentProps, d as DefaultRootProps, M as MappedItem, R as RootData, e as RootDataWithProps, f as ComponentData } from './Config-B7UadvMA.js';
2
- export { r as Adaptor, q as ArrayField, m as ArrayState, B as BaseData, n as BaseField, j as ComponentConfig, g as Content, t as CustomField, s as ExternalField, E as ExternalFieldWithAdaptor, u as Fields, l as ItemWithId, N as NumberField, O as ObjectField, h as PuckComponent, i as PuckContext, p as RadioField, k as RootDataWithoutProps, S as SelectField, T as TextField, o as TextareaField } from './Config-B7UadvMA.js';
3
- import * as react from 'react';
4
- import { ReactNode, ReactElement, SyntheticEvent, CSSProperties } from 'react';
1
+ import { F as Field, a as FieldProps, C as Config, D as Data, I as ItemSelector, P as PuckAction, b as DropZoneProps, E as ExtractPropsFromConfig, c as ExtractRootPropsFromConfig, U as UiState, O as OnAction, d as Permissions, e as Plugin, f as Overrides, A as AppState, V as Viewports, g as IframeConfig, h as InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, k as ComponentData, H as History } from './actions-BaAekM3E.js';
2
+ export { K as Adaptor, G as ArrayField, q as ArrayState, a1 as AsFieldProps, B as BaseData, x as BaseField, s as ComponentConfig, v as ComponentDataMap, w as Content, W as CustomField, _ as DefaultRootProps, Z as DefaultRootRenderProps, Q as ExternalField, L as ExternalFieldWithAdaptor, n as FieldRenderFunctions, X as Fields, p as ItemWithId, M as MappedItem, N as NumberField, J as ObjectField, m as OverrideKey, r as PuckComponent, Y as PuckContext, z as RadioField, u as RootData, R as RootDataWithProps, t as RootDataWithoutProps, S as SelectField, T as TextField, y as TextareaField, l as Viewport, a2 as WithChildren, $ as WithId, a0 as WithPuckProps, o as overrideKeys } from './actions-BaAekM3E.js';
5
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as react from 'react';
5
+ import { ReactNode, SyntheticEvent, ReactElement, CSSProperties } from 'react';
6
6
  import { DragStart, DragUpdate } from '@measured/dnd';
7
7
 
8
- type InsertAction = {
9
- type: "insert";
10
- componentType: string;
11
- destinationIndex: number;
12
- destinationZone: string;
13
- id?: string;
14
- };
15
- type DuplicateAction = {
16
- type: "duplicate";
17
- sourceIndex: number;
18
- sourceZone: string;
19
- };
20
- type ReplaceAction = {
21
- type: "replace";
22
- destinationIndex: number;
23
- destinationZone: string;
24
- data: any;
25
- };
26
- type ReorderAction = {
27
- type: "reorder";
28
- sourceIndex: number;
29
- destinationIndex: number;
30
- destinationZone: string;
31
- };
32
- type MoveAction = {
33
- type: "move";
34
- sourceIndex: number;
35
- sourceZone: string;
36
- destinationIndex: number;
37
- destinationZone: string;
38
- };
39
- type RemoveAction = {
40
- type: "remove";
41
- index: number;
42
- zone: string;
43
- };
44
- type SetUiAction = {
45
- type: "setUi";
46
- ui: Partial<UiState> | ((previous: UiState) => Partial<UiState>);
47
- };
48
- type SetDataAction = {
49
- type: "setData";
50
- data: Partial<Data> | ((previous: Data) => Partial<Data>);
51
- };
52
- type SetAction = {
53
- type: "set";
54
- state: Partial<AppState> | ((previous: AppState) => Partial<AppState>);
55
- };
56
- type RegisterZoneAction = {
57
- type: "registerZone";
58
- zone: string;
59
- };
60
- type UnregisterZoneAction = {
61
- type: "unregisterZone";
62
- zone: string;
63
- };
64
- type PuckAction = {
65
- recordHistory?: boolean;
66
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
67
-
68
- type RenderFunc<Props extends {
69
- [key: string]: any;
70
- } = {
71
- children: ReactNode;
72
- }> = (props: Props) => ReactElement;
73
- declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
74
- type OverrideKey = (typeof overrideKeys)[number];
75
- type OverridesGeneric<Shape extends {
76
- [key in OverrideKey]: any;
77
- }> = Shape;
78
- type Overrides = OverridesGeneric<{
79
- fieldTypes: Partial<FieldRenderFunctions>;
80
- header: RenderFunc<{
81
- actions: ReactNode;
82
- children: ReactNode;
83
- }>;
84
- actionBar: RenderFunc<{
85
- label?: string;
86
- children: ReactNode;
87
- }>;
88
- headerActions: RenderFunc<{
89
- children: ReactNode;
90
- }>;
91
- preview: RenderFunc;
92
- fields: RenderFunc<{
93
- children: ReactNode;
94
- isLoading: boolean;
95
- itemSelector?: ItemSelector | null;
96
- }>;
97
- fieldLabel: RenderFunc<{
98
- children?: ReactNode;
99
- icon?: ReactNode;
100
- label: string;
101
- el?: "label" | "div";
102
- readOnly?: boolean;
103
- className?: string;
104
- }>;
105
- components: RenderFunc;
106
- componentItem: RenderFunc<{
107
- children: ReactNode;
108
- name: string;
109
- }>;
110
- outline: RenderFunc;
111
- puck: RenderFunc;
112
- }>;
113
- type FieldRenderFunctions = Omit<{
114
- [Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
115
- type: Type;
116
- }>> & {
117
- children: ReactNode;
118
- name: string;
119
- }>;
120
- }, "custom"> & {
121
- [key: string]: React.FunctionComponent<FieldProps<any> & {
122
- children: ReactNode;
123
- name: string;
124
- }>;
125
- };
126
-
127
- type Plugin = {
128
- overrides: Partial<Overrides>;
129
- };
130
-
131
8
  declare const ActionBar: {
132
9
  ({ label, children, }: {
133
10
  label?: string;
@@ -198,7 +75,7 @@ declare const Drawer: {
198
75
  droppableId?: string;
199
76
  direction?: "vertical" | "horizontal";
200
77
  }): react_jsx_runtime.JSX.Element;
201
- Item: ({ name, children, id, label, index, }: {
78
+ Item: ({ name, children, id, label, index, isDragDisabled, }: {
202
79
  name: string;
203
80
  children?: (props: {
204
81
  children: ReactNode;
@@ -207,30 +84,10 @@ declare const Drawer: {
207
84
  id?: string;
208
85
  label?: string;
209
86
  index: number;
87
+ isDragDisabled?: boolean;
210
88
  }) => react_jsx_runtime.JSX.Element;
211
89
  };
212
90
 
213
- type History<D = any> = {
214
- id: string;
215
- data: D;
216
- };
217
- type HistoryStore<D = any> = {
218
- index: number;
219
- hasPast: boolean;
220
- hasFuture: boolean;
221
- histories: History<D>[];
222
- record: (data: D) => void;
223
- back: VoidFunction;
224
- forward: VoidFunction;
225
- currentHistory: History;
226
- nextHistory: History<D> | null;
227
- prevHistory: History<D> | null;
228
- setHistories: (histories: History[]) => void;
229
- setHistoryIndex: (index: number) => void;
230
- };
231
-
232
- type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
233
-
234
91
  type PathData = Record<string, {
235
92
  path: string[];
236
93
  label: string;
@@ -283,28 +140,24 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
283
140
  title: string;
284
141
  }) => react_jsx_runtime.JSX.Element;
285
142
 
286
- type IframeConfig = {
287
- enabled?: boolean;
288
- };
289
-
290
- declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, permissions, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
143
+ declare function Puck<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>>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, permissions, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe: _iframe, dnd, initialHistory: _initialHistory, }: {
291
144
  children?: ReactNode;
292
145
  config: UserConfig;
293
- data: Partial<Data>;
146
+ data: Partial<UserData>;
294
147
  ui?: Partial<UiState>;
295
- onChange?: (data: Data) => void;
296
- onPublish?: (data: Data) => void;
297
- onAction?: OnAction;
148
+ onChange?: (data: UserData) => void;
149
+ onPublish?: (data: UserData) => void;
150
+ onAction?: OnAction<UserData>;
298
151
  permissions?: Partial<Permissions>;
299
152
  plugins?: Plugin[];
300
153
  overrides?: Partial<Overrides>;
301
154
  renderHeader?: (props: {
302
155
  children: ReactNode;
303
156
  dispatch: (action: PuckAction) => void;
304
- state: AppState;
157
+ state: AppState<UserData>;
305
158
  }) => ReactElement;
306
159
  renderHeaderActions?: (props: {
307
- state: AppState;
160
+ state: AppState<UserData>;
308
161
  dispatch: (action: PuckAction) => void;
309
162
  }) => ReactElement;
310
163
  headerTitle?: string;
@@ -314,10 +167,7 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
314
167
  dnd?: {
315
168
  disableAutoScroll?: boolean;
316
169
  };
317
- initialHistory?: {
318
- histories: History<any>[];
319
- index: number;
320
- };
170
+ initialHistory?: InitialHistory;
321
171
  }): react_jsx_runtime.JSX.Element;
322
172
  declare namespace Puck {
323
173
  var Components: () => react_jsx_runtime.JSX.Element;
@@ -328,14 +178,14 @@ declare namespace Puck {
328
178
  }) => react_jsx_runtime.JSX.Element;
329
179
  }
330
180
 
331
- declare function Render<UserConfig extends Config = Config>({ config, data, }: {
181
+ declare function Render<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>>({ config, data }: {
332
182
  config: UserConfig;
333
- data: Partial<Data>;
183
+ data: Partial<UserData>;
334
184
  }): react_jsx_runtime.JSX.Element;
335
185
 
336
186
  declare function migrate(data: Data): Data;
337
187
 
338
- type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultRootProps = DefaultRootProps> = Partial<{
188
+ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
339
189
  [ComponentName in keyof Props]: (props: Props[ComponentName] & {
340
190
  [key: string]: any;
341
191
  }) => Props[ComponentName];
@@ -344,23 +194,39 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
344
194
  [key: string]: any;
345
195
  }) => RootProps;
346
196
  }>;
347
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultComponentProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
197
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
348
198
 
349
- declare function resolveAllData(data: Partial<Data>, config: Config, onResolveStart?: (item: MappedItem) => void, onResolveEnd?: (item: MappedItem) => void): Promise<{
350
- root: RootData<DefaultRootProps> | RootDataWithProps;
351
- content: any;
352
- zones: Record<string, MappedItem[]>;
353
- }>;
199
+ declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
200
+
201
+ type HistoryStore<D = any> = {
202
+ index: number;
203
+ hasPast: boolean;
204
+ hasFuture: boolean;
205
+ histories: History<D>[];
206
+ record: (data: D) => void;
207
+ back: VoidFunction;
208
+ forward: VoidFunction;
209
+ currentHistory: History;
210
+ nextHistory: History<D> | null;
211
+ prevHistory: History<D> | null;
212
+ setHistories: (histories: History[]) => void;
213
+ setHistoryIndex: (index: number) => void;
214
+ };
354
215
 
355
216
  declare const usePuck: () => {
356
217
  appState: AppState;
357
218
  config: Config;
358
219
  dispatch: (action: PuckAction) => void;
359
- getPermissions: (selectedItem?: ComponentData) => {
220
+ getPermissions: ({ item, type, }?: {
221
+ item?: ComponentData;
222
+ type?: keyof DefaultComponentProps;
223
+ }) => {
360
224
  [x: string]: boolean | undefined;
361
225
  drag?: boolean | undefined;
362
226
  duplicate?: boolean | undefined;
363
227
  delete?: boolean | undefined;
228
+ edit?: boolean | undefined;
229
+ insert?: boolean | undefined;
364
230
  };
365
231
  history: {
366
232
  back: VoidFunction;
@@ -373,9 +239,7 @@ declare const usePuck: () => {
373
239
  index: number;
374
240
  historyStore: HistoryStore | undefined;
375
241
  };
376
- selectedItem: ComponentData<DefaultComponentProps & {
377
- id: string;
378
- }> | null;
242
+ selectedItem: ComponentData<any, string> | null;
379
243
  };
380
244
 
381
- export { Action, ActionBar, AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, type FieldPropsInternal, type History, IconButton, MappedItem, Permissions, type Plugin, Puck, type PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };
245
+ export { Action, ActionBar, AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, DropZoneProvider, ExtractPropsFromConfig, ExtractRootPropsFromConfig, Field, FieldLabel, FieldLabelInternal, FieldProps, type FieldPropsInternal, History, IconButton, IframeConfig, InitialHistory, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, Viewports, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };