@measured/puck 0.19.0-canary.0ea6ce4 → 0.19.0-canary.1fc19b5

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.
@@ -232,7 +232,9 @@ function resolveAllData(_0, _1) {
232
232
 
233
233
  // lib/root-droppable-id.ts
234
234
  init_react_import();
235
- var rootDroppableId = "default-zone";
235
+ var rootAreaId = "root";
236
+ var rootZone = "default-zone";
237
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
236
238
 
237
239
  // lib/setup-zone.ts
238
240
  init_react_import();
@@ -258,6 +260,8 @@ export {
258
260
  __privateSet,
259
261
  __async,
260
262
  init_react_import,
263
+ rootAreaId,
264
+ rootZone,
261
265
  rootDroppableId,
262
266
  setupZone,
263
267
  getChanged,
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { F as FieldProps, a as Field, D as DropZoneProps, C as Config, U as UserGenerics, b as Data, c as UiState, O as OnAction, P as Permissions, d as Plugin, e as Overrides, f as PuckAction, V as Viewports, I as IframeConfig, g as InitialHistory, M as Metadata, h as DefaultComponentProps, i as DefaultRootFieldProps, H as History, A as AppState, E as ExtractPropsFromConfig, j as ExtractRootPropsFromConfig, k as ComponentDataMap } from './resolve-all-data-D4okkICg.mjs';
2
- export { W as Adaptor, L as ArrayField, s as ArrayState, a4 as AsFieldProps, B as BaseData, G as BaseField, u as ComponentConfig, x as ComponentData, z as Content, Z as CustomField, a1 as DefaultRootProps, a0 as DefaultRootRenderProps, l as Direction, m as DragAxis, Y as ExternalField, X as ExternalFieldWithAdaptor, q as FieldRenderFunctions, _ as Fields, r as ItemWithId, y as MappedItem, N as NumberField, Q as ObjectField, p as OverrideKey, t as PuckComponent, $ as PuckContext, K as RadioField, w as RootData, R as RootDataWithProps, v as RootDataWithoutProps, S as SelectField, T as TextField, J as TextareaField, n as Viewport, a5 as WithChildren, a2 as WithId, a3 as WithPuckProps, o as overrideKeys, a6 as resolveAllData } from './resolve-all-data-D4okkICg.mjs';
1
+ import { F as FieldProps, a as Field, D as DropZoneProps, C as Config, U as UserGenerics, b as Data, c as UiState, O as OnAction, P as Permissions, d as Plugin, e as Overrides, f as PuckAction, V as Viewports, I as IframeConfig, g as InitialHistory, M as Metadata, h as DefaultComponentProps, i as DefaultRootFieldProps, H as History, j as ComponentData, k as Fields, A as AppState, l as ComponentConfig } from './resolve-all-data-wwgDuTnC.mjs';
2
+ export { Q as Adaptor, K as ArrayField, t as ArrayState, a2 as AsFieldProps, B as BaseData, E as BaseField, y as ComponentDataMap, z as Content, Y as CustomField, $ as DefaultRootProps, _ as DefaultRootRenderProps, m as Direction, n as DragAxis, X as ExternalField, W as ExternalFieldWithAdaptor, a4 as ExtractPropsFromConfig, a5 as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, x as MappedItem, N as NumberField, L as ObjectField, q as OverrideKey, u as PuckComponent, Z as PuckContext, J as RadioField, w as RootData, R as RootDataWithProps, v as RootDataWithoutProps, S as SelectField, T as TextField, G as TextareaField, o as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, p as overrideKeys, a6 as resolveAllData } from './resolve-all-data-wwgDuTnC.mjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
- import { ReactNode, SyntheticEvent, ReactElement } from 'react';
5
+ import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
6
6
 
7
7
  declare const ActionBar: {
8
8
  ({ label, children, }: {
@@ -93,7 +93,7 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
93
93
  title: string;
94
94
  }) => react_jsx_runtime.JSX.Element;
95
95
 
96
- declare function Puck<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, permissions, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe: _iframe, dnd, initialHistory: _initialHistory, metadata, }: {
96
+ type PuckProps<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
97
97
  children?: ReactNode;
98
98
  config: UserConfig;
99
99
  data: Partial<G["UserData"] | Data>;
@@ -122,7 +122,8 @@ declare function Puck<UserConfig extends Config = Config, G extends UserGenerics
122
122
  };
123
123
  initialHistory?: InitialHistory;
124
124
  metadata?: Metadata;
125
- }): react_jsx_runtime.JSX.Element;
125
+ };
126
+ declare function Puck<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(props: PuckProps<UserConfig>): react_jsx_runtime.JSX.Element;
126
127
  declare namespace Puck {
127
128
  var Components: () => react_jsx_runtime.JSX.Element;
128
129
  var Fields: ({ wrapFields }: {
@@ -134,6 +135,11 @@ declare namespace Puck {
134
135
  }) => react_jsx_runtime.JSX.Element;
135
136
  }
136
137
 
138
+ declare const renderContext: react__default.Context<{
139
+ config: Config;
140
+ data: Data;
141
+ metadata: Metadata;
142
+ }>;
137
143
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
138
144
  config: UserConfig;
139
145
  data: Partial<G["UserData"] | Data>;
@@ -153,47 +159,139 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
153
159
  }>;
154
160
  declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
155
161
 
156
- type HistoryStore<D = any> = {
162
+ type HistorySlice<D = any> = {
157
163
  index: number;
158
- hasPast: boolean;
159
- hasFuture: boolean;
164
+ hasPast: () => boolean;
165
+ hasFuture: () => boolean;
160
166
  histories: History<D>[];
161
167
  record: (data: D) => void;
162
168
  back: VoidFunction;
163
169
  forward: VoidFunction;
164
- currentHistory: History;
165
- nextHistory: History<D> | null;
166
- prevHistory: History<D> | null;
170
+ currentHistory: () => History;
171
+ nextHistory: () => History<D> | null;
172
+ prevHistory: () => History<D> | null;
167
173
  setHistories: (histories: History[]) => void;
168
174
  setHistoryIndex: (index: number) => void;
175
+ initialAppState: D;
176
+ };
177
+
178
+ type NodeMethods = {
179
+ sync: () => void;
180
+ };
181
+ type PuckNode = {
182
+ id: string;
183
+ methods: NodeMethods;
184
+ data: ComponentData;
185
+ parentId: string | null;
186
+ zone: string;
187
+ path: string[];
188
+ index: number;
189
+ element: HTMLElement | null;
190
+ };
191
+ type NodesSlice = {
192
+ nodes: Record<string, PuckNode | undefined>;
193
+ registerNode: (id: string, node: Partial<PuckNode>) => void;
194
+ unregisterNode: (id: string, node?: Partial<PuckNode>) => void;
169
195
  };
170
196
 
171
197
  type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
172
- item?: G["UserComponentData"];
198
+ item?: G["UserComponentData"] | null;
173
199
  type?: keyof G["UserProps"];
174
200
  root?: boolean;
175
201
  };
176
- type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Partial<Permissions>;
202
+ type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
203
+ type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
177
204
  type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
205
+ type Cache = Record<string, {
206
+ lastPermissions: Partial<Permissions>;
207
+ lastData: ComponentData | null;
208
+ }>;
209
+ type PermissionsSlice = {
210
+ cache: Cache;
211
+ globalPermissions: Permissions;
212
+ resolvedPermissions: Record<string, Partial<Permissions> | undefined>;
213
+ getPermissions: GetPermissions<Config>;
214
+ resolvePermissions: ResolvePermissions<Config>;
215
+ refreshPermissions: RefreshPermissions<Config>;
216
+ };
178
217
 
179
- declare const usePuck: <UserConfig extends Config = Config>() => {
180
- appState: AppState<Data<ExtractPropsFromConfig<UserConfig>, ExtractRootPropsFromConfig<UserConfig>>>;
181
- config: UserConfig;
218
+ type ComponentOrRootData = Omit<ComponentData<any>, "type">;
219
+ type FieldsSlice = {
220
+ fields: Fields | Partial<Fields>;
221
+ loading: boolean;
222
+ lastResolvedData: Partial<ComponentOrRootData>;
223
+ };
224
+
225
+ type Status = "LOADING" | "MOUNTED" | "READY";
226
+ type ZoomConfig = {
227
+ autoZoom: number;
228
+ rootHeight: number;
229
+ zoom: number;
230
+ };
231
+ type ComponentState = Record<string, {
232
+ loadingCount: number;
233
+ }>;
234
+ type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
235
+ state: G["UserAppState"];
182
236
  dispatch: (action: PuckAction) => void;
237
+ config: UserConfig;
238
+ componentState: ComponentState;
239
+ setComponentState: (componentState: ComponentState) => void;
240
+ setComponentLoading: (id: string) => void;
241
+ unsetComponentLoading: (id: string) => void;
242
+ resolveDataRuns: number;
243
+ resolveData: (newAppState: AppState) => void;
244
+ plugins: Plugin[];
245
+ overrides: Partial<Overrides>;
246
+ viewports: Viewports;
247
+ zoomConfig: ZoomConfig;
248
+ setZoomConfig: (zoomConfig: ZoomConfig) => void;
249
+ status: Status;
250
+ setStatus: (status: Status) => void;
251
+ iframe: IframeConfig;
252
+ selectedItem?: G["UserData"]["content"][0] | null;
253
+ setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
254
+ getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
255
+ onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
256
+ metadata: Metadata;
257
+ fields: FieldsSlice;
258
+ history: HistorySlice;
259
+ nodes: NodesSlice;
260
+ permissions: PermissionsSlice;
261
+ };
262
+
263
+ type WithGet<T> = T & {
264
+ get: () => T;
265
+ };
266
+ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
267
+ appState: AppState;
268
+ config: Config;
269
+ dispatch: AppStore["dispatch"];
183
270
  getPermissions: GetPermissions<UserConfig>;
184
271
  refreshPermissions: RefreshPermissions<UserConfig>;
272
+ selectedItem: G["UserComponentData"] | null;
185
273
  history: {
186
- back: VoidFunction;
187
- forward: VoidFunction;
188
- setHistories: (histories: History[]) => void;
189
- setHistoryIndex: (index: number) => void;
274
+ back: HistorySlice["back"];
275
+ forward: HistorySlice["forward"];
276
+ setHistories: HistorySlice["setHistories"];
277
+ setHistoryIndex: HistorySlice["setHistoryIndex"];
278
+ histories: HistorySlice["histories"];
279
+ index: HistorySlice["index"];
190
280
  hasPast: boolean;
191
281
  hasFuture: boolean;
192
- histories: History<any>[];
193
- index: number;
194
- historyStore: HistoryStore | undefined;
195
282
  };
196
- selectedItem: ComponentDataMap<ExtractPropsFromConfig<UserConfig>> | null;
197
283
  };
284
+ type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<UserConfig>>;
285
+ /**
286
+ * createUsePuck
287
+ *
288
+ * Create a typed usePuck hook, which is necessary because the user may provide a generic type but not
289
+ * a selector type, and TS does not currently support partial inference.
290
+ * Related: https://github.com/microsoft/TypeScript/issues/26242
291
+ *
292
+ * @returns a typed usePuck function
293
+ */
294
+ declare function createUsePuck<UserConfig extends Config = Config>(): <T = UsePuckData<UserConfig, UserGenerics<UserConfig>>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
295
+ declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
198
296
 
199
- export { Action, ActionBar, AppState, AutoField, Button, ComponentDataMap, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, ExtractPropsFromConfig, ExtractRootPropsFromConfig, Field, FieldLabel, FieldProps, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, UserGenerics, Viewports, migrate, transformProps, usePuck };
297
+ export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, migrate, renderContext, transformProps, usePuck };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { F as FieldProps, a as Field, D as DropZoneProps, C as Config, U as UserGenerics, b as Data, c as UiState, O as OnAction, P as Permissions, d as Plugin, e as Overrides, f as PuckAction, V as Viewports, I as IframeConfig, g as InitialHistory, M as Metadata, h as DefaultComponentProps, i as DefaultRootFieldProps, H as History, A as AppState, E as ExtractPropsFromConfig, j as ExtractRootPropsFromConfig, k as ComponentDataMap } from './resolve-all-data-D4okkICg.js';
2
- export { W as Adaptor, L as ArrayField, s as ArrayState, a4 as AsFieldProps, B as BaseData, G as BaseField, u as ComponentConfig, x as ComponentData, z as Content, Z as CustomField, a1 as DefaultRootProps, a0 as DefaultRootRenderProps, l as Direction, m as DragAxis, Y as ExternalField, X as ExternalFieldWithAdaptor, q as FieldRenderFunctions, _ as Fields, r as ItemWithId, y as MappedItem, N as NumberField, Q as ObjectField, p as OverrideKey, t as PuckComponent, $ as PuckContext, K as RadioField, w as RootData, R as RootDataWithProps, v as RootDataWithoutProps, S as SelectField, T as TextField, J as TextareaField, n as Viewport, a5 as WithChildren, a2 as WithId, a3 as WithPuckProps, o as overrideKeys, a6 as resolveAllData } from './resolve-all-data-D4okkICg.js';
1
+ import { F as FieldProps, a as Field, D as DropZoneProps, C as Config, U as UserGenerics, b as Data, c as UiState, O as OnAction, P as Permissions, d as Plugin, e as Overrides, f as PuckAction, V as Viewports, I as IframeConfig, g as InitialHistory, M as Metadata, h as DefaultComponentProps, i as DefaultRootFieldProps, H as History, j as ComponentData, k as Fields, A as AppState, l as ComponentConfig } from './resolve-all-data-wwgDuTnC.js';
2
+ export { Q as Adaptor, K as ArrayField, t as ArrayState, a2 as AsFieldProps, B as BaseData, E as BaseField, y as ComponentDataMap, z as Content, Y as CustomField, $ as DefaultRootProps, _ as DefaultRootRenderProps, m as Direction, n as DragAxis, X as ExternalField, W as ExternalFieldWithAdaptor, a4 as ExtractPropsFromConfig, a5 as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, x as MappedItem, N as NumberField, L as ObjectField, q as OverrideKey, u as PuckComponent, Z as PuckContext, J as RadioField, w as RootData, R as RootDataWithProps, v as RootDataWithoutProps, S as SelectField, T as TextField, G as TextareaField, o as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, p as overrideKeys, a6 as resolveAllData } from './resolve-all-data-wwgDuTnC.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
- import { ReactNode, SyntheticEvent, ReactElement } from 'react';
5
+ import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
6
6
 
7
7
  declare const ActionBar: {
8
8
  ({ label, children, }: {
@@ -93,7 +93,7 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
93
93
  title: string;
94
94
  }) => react_jsx_runtime.JSX.Element;
95
95
 
96
- declare function Puck<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, permissions, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe: _iframe, dnd, initialHistory: _initialHistory, metadata, }: {
96
+ type PuckProps<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
97
97
  children?: ReactNode;
98
98
  config: UserConfig;
99
99
  data: Partial<G["UserData"] | Data>;
@@ -122,7 +122,8 @@ declare function Puck<UserConfig extends Config = Config, G extends UserGenerics
122
122
  };
123
123
  initialHistory?: InitialHistory;
124
124
  metadata?: Metadata;
125
- }): react_jsx_runtime.JSX.Element;
125
+ };
126
+ declare function Puck<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(props: PuckProps<UserConfig>): react_jsx_runtime.JSX.Element;
126
127
  declare namespace Puck {
127
128
  var Components: () => react_jsx_runtime.JSX.Element;
128
129
  var Fields: ({ wrapFields }: {
@@ -134,6 +135,11 @@ declare namespace Puck {
134
135
  }) => react_jsx_runtime.JSX.Element;
135
136
  }
136
137
 
138
+ declare const renderContext: react__default.Context<{
139
+ config: Config;
140
+ data: Data;
141
+ metadata: Metadata;
142
+ }>;
137
143
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
138
144
  config: UserConfig;
139
145
  data: Partial<G["UserData"] | Data>;
@@ -153,47 +159,139 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
153
159
  }>;
154
160
  declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
155
161
 
156
- type HistoryStore<D = any> = {
162
+ type HistorySlice<D = any> = {
157
163
  index: number;
158
- hasPast: boolean;
159
- hasFuture: boolean;
164
+ hasPast: () => boolean;
165
+ hasFuture: () => boolean;
160
166
  histories: History<D>[];
161
167
  record: (data: D) => void;
162
168
  back: VoidFunction;
163
169
  forward: VoidFunction;
164
- currentHistory: History;
165
- nextHistory: History<D> | null;
166
- prevHistory: History<D> | null;
170
+ currentHistory: () => History;
171
+ nextHistory: () => History<D> | null;
172
+ prevHistory: () => History<D> | null;
167
173
  setHistories: (histories: History[]) => void;
168
174
  setHistoryIndex: (index: number) => void;
175
+ initialAppState: D;
176
+ };
177
+
178
+ type NodeMethods = {
179
+ sync: () => void;
180
+ };
181
+ type PuckNode = {
182
+ id: string;
183
+ methods: NodeMethods;
184
+ data: ComponentData;
185
+ parentId: string | null;
186
+ zone: string;
187
+ path: string[];
188
+ index: number;
189
+ element: HTMLElement | null;
190
+ };
191
+ type NodesSlice = {
192
+ nodes: Record<string, PuckNode | undefined>;
193
+ registerNode: (id: string, node: Partial<PuckNode>) => void;
194
+ unregisterNode: (id: string, node?: Partial<PuckNode>) => void;
169
195
  };
170
196
 
171
197
  type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
172
- item?: G["UserComponentData"];
198
+ item?: G["UserComponentData"] | null;
173
199
  type?: keyof G["UserProps"];
174
200
  root?: boolean;
175
201
  };
176
- type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Partial<Permissions>;
202
+ type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
203
+ type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
177
204
  type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
205
+ type Cache = Record<string, {
206
+ lastPermissions: Partial<Permissions>;
207
+ lastData: ComponentData | null;
208
+ }>;
209
+ type PermissionsSlice = {
210
+ cache: Cache;
211
+ globalPermissions: Permissions;
212
+ resolvedPermissions: Record<string, Partial<Permissions> | undefined>;
213
+ getPermissions: GetPermissions<Config>;
214
+ resolvePermissions: ResolvePermissions<Config>;
215
+ refreshPermissions: RefreshPermissions<Config>;
216
+ };
178
217
 
179
- declare const usePuck: <UserConfig extends Config = Config>() => {
180
- appState: AppState<Data<ExtractPropsFromConfig<UserConfig>, ExtractRootPropsFromConfig<UserConfig>>>;
181
- config: UserConfig;
218
+ type ComponentOrRootData = Omit<ComponentData<any>, "type">;
219
+ type FieldsSlice = {
220
+ fields: Fields | Partial<Fields>;
221
+ loading: boolean;
222
+ lastResolvedData: Partial<ComponentOrRootData>;
223
+ };
224
+
225
+ type Status = "LOADING" | "MOUNTED" | "READY";
226
+ type ZoomConfig = {
227
+ autoZoom: number;
228
+ rootHeight: number;
229
+ zoom: number;
230
+ };
231
+ type ComponentState = Record<string, {
232
+ loadingCount: number;
233
+ }>;
234
+ type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
235
+ state: G["UserAppState"];
182
236
  dispatch: (action: PuckAction) => void;
237
+ config: UserConfig;
238
+ componentState: ComponentState;
239
+ setComponentState: (componentState: ComponentState) => void;
240
+ setComponentLoading: (id: string) => void;
241
+ unsetComponentLoading: (id: string) => void;
242
+ resolveDataRuns: number;
243
+ resolveData: (newAppState: AppState) => void;
244
+ plugins: Plugin[];
245
+ overrides: Partial<Overrides>;
246
+ viewports: Viewports;
247
+ zoomConfig: ZoomConfig;
248
+ setZoomConfig: (zoomConfig: ZoomConfig) => void;
249
+ status: Status;
250
+ setStatus: (status: Status) => void;
251
+ iframe: IframeConfig;
252
+ selectedItem?: G["UserData"]["content"][0] | null;
253
+ setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
254
+ getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
255
+ onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
256
+ metadata: Metadata;
257
+ fields: FieldsSlice;
258
+ history: HistorySlice;
259
+ nodes: NodesSlice;
260
+ permissions: PermissionsSlice;
261
+ };
262
+
263
+ type WithGet<T> = T & {
264
+ get: () => T;
265
+ };
266
+ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
267
+ appState: AppState;
268
+ config: Config;
269
+ dispatch: AppStore["dispatch"];
183
270
  getPermissions: GetPermissions<UserConfig>;
184
271
  refreshPermissions: RefreshPermissions<UserConfig>;
272
+ selectedItem: G["UserComponentData"] | null;
185
273
  history: {
186
- back: VoidFunction;
187
- forward: VoidFunction;
188
- setHistories: (histories: History[]) => void;
189
- setHistoryIndex: (index: number) => void;
274
+ back: HistorySlice["back"];
275
+ forward: HistorySlice["forward"];
276
+ setHistories: HistorySlice["setHistories"];
277
+ setHistoryIndex: HistorySlice["setHistoryIndex"];
278
+ histories: HistorySlice["histories"];
279
+ index: HistorySlice["index"];
190
280
  hasPast: boolean;
191
281
  hasFuture: boolean;
192
- histories: History<any>[];
193
- index: number;
194
- historyStore: HistoryStore | undefined;
195
282
  };
196
- selectedItem: ComponentDataMap<ExtractPropsFromConfig<UserConfig>> | null;
197
283
  };
284
+ type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<UserConfig>>;
285
+ /**
286
+ * createUsePuck
287
+ *
288
+ * Create a typed usePuck hook, which is necessary because the user may provide a generic type but not
289
+ * a selector type, and TS does not currently support partial inference.
290
+ * Related: https://github.com/microsoft/TypeScript/issues/26242
291
+ *
292
+ * @returns a typed usePuck function
293
+ */
294
+ declare function createUsePuck<UserConfig extends Config = Config>(): <T = UsePuckData<UserConfig, UserGenerics<UserConfig>>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
295
+ declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
198
296
 
199
- export { Action, ActionBar, AppState, AutoField, Button, ComponentDataMap, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, ExtractPropsFromConfig, ExtractRootPropsFromConfig, Field, FieldLabel, FieldProps, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, UserGenerics, Viewports, migrate, transformProps, usePuck };
297
+ export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, DefaultComponentProps, DefaultRootFieldProps, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, Render, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, migrate, renderContext, transformProps, usePuck };