@measured/puck 0.19.0-canary.a931e6b → 0.19.0-canary.a967ca42

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 CHANGED
@@ -1,9 +1,110 @@
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 History, h as ComponentData, i as Fields, A as AppState, j as ComponentConfig } from './resolve-all-data-3XjIPfNh.mjs';
2
- export { K as Adaptor, G as ArrayField, r as ArrayState, a2 as AsFieldProps, B as BaseData, y as BaseField, w as ComponentDataMap, x as Content, W as CustomField, $ as DefaultComponentProps, Y as DefaultRootFieldProps, _ as DefaultRootProps, Z as DefaultRootRenderProps, k as Direction, l as DragAxis, Q as ExternalField, L as ExternalFieldWithAdaptor, a4 as ExtractPropsFromConfig, a5 as ExtractRootPropsFromConfig, p as FieldRenderFunctions, q as ItemWithId, v as MappedItem, N as NumberField, J as ObjectField, n as OverrideKey, s as PuckComponent, X as PuckContext, E as RadioField, u as RootData, R as RootDataWithProps, t as RootDataWithoutProps, S as SelectField, T as TextField, z as TextareaField, m as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, o as overrideKeys, a7 as resolveAllData, a6 as transformProps } from './resolve-all-data-3XjIPfNh.mjs';
1
+ import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-DOB5QZVq.mjs';
2
+ export { _ as Adaptor, Y as ArrayField, t as ArrayState, ab as AsFieldProps, B as BaseData, K as BaseField, G as ComponentDataMap, z as ComponentDataOptionalId, J as Content, a2 as CustomField, a1 as CustomFieldRender, a8 as DefaultComponentProps, a5 as DefaultRootFieldProps, a7 as DefaultRootProps, a6 as DefaultRootRenderProps, m as Direction, n as DragAxis, a0 as ExternalField, $ as ExternalFieldWithAdaptor, ad as ExtractPropsFromConfig, ae as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, E as MappedItem, N as NumberField, Z as ObjectField, q as OverrideKey, u as PuckComponent, a4 as PuckContext, X as RadioField, v as RootConfig, y as RootData, x as RootDataWithoutProps, Q as SelectField, S as Slot, a3 as SlotField, T as TextField, L as TextareaField, o as Viewport, ac as WithChildren, a9 as WithId, aa as WithPuckProps, W as WithSlotProps, af as migrate, p as overrideKeys, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DOB5QZVq.mjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
6
6
 
7
+ type HistorySlice<D = any> = {
8
+ index: number;
9
+ hasPast: () => boolean;
10
+ hasFuture: () => boolean;
11
+ histories: History<D>[];
12
+ record: (data: D) => void;
13
+ back: VoidFunction;
14
+ forward: VoidFunction;
15
+ currentHistory: () => History;
16
+ nextHistory: () => History<D> | null;
17
+ prevHistory: () => History<D> | null;
18
+ setHistories: (histories: History[]) => void;
19
+ setHistoryIndex: (index: number) => void;
20
+ initialAppState: D;
21
+ };
22
+
23
+ type NodeMethods = {
24
+ sync: () => void;
25
+ };
26
+ type PuckNodeInstance = {
27
+ id: string;
28
+ methods: NodeMethods;
29
+ element: HTMLElement | null;
30
+ };
31
+ type NodesSlice = {
32
+ nodes: Record<string, PuckNodeInstance | undefined>;
33
+ registerNode: (id: string, node: Partial<PuckNodeInstance>) => void;
34
+ unregisterNode: (id: string, node?: Partial<PuckNodeInstance>) => void;
35
+ };
36
+
37
+ type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
38
+ item?: G["UserComponentData"] | null;
39
+ type?: keyof G["UserProps"];
40
+ root?: boolean;
41
+ };
42
+ type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
43
+ type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
44
+ type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
45
+ type Cache = Record<string, {
46
+ lastPermissions: Partial<Permissions>;
47
+ lastData: ComponentData | null;
48
+ }>;
49
+ type PermissionsSlice = {
50
+ cache: Cache;
51
+ globalPermissions: Permissions;
52
+ resolvedPermissions: Record<string, Partial<Permissions> | undefined>;
53
+ getPermissions: GetPermissions<Config>;
54
+ resolvePermissions: ResolvePermissions<Config>;
55
+ refreshPermissions: RefreshPermissions<Config>;
56
+ };
57
+
58
+ type ComponentOrRootData = Omit<ComponentData<any>, "type">;
59
+ type FieldsSlice = {
60
+ fields: Fields | Partial<Fields>;
61
+ loading: boolean;
62
+ lastResolvedData: Partial<ComponentOrRootData>;
63
+ id: string | undefined;
64
+ };
65
+
66
+ type Status = "LOADING" | "MOUNTED" | "READY";
67
+ type ZoomConfig = {
68
+ autoZoom: number;
69
+ rootHeight: number;
70
+ zoom: number;
71
+ };
72
+ type ComponentState = Record<string, {
73
+ loadingCount: number;
74
+ }>;
75
+ type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
76
+ state: G["UserAppState"];
77
+ dispatch: (action: PuckAction) => void;
78
+ config: UserConfig;
79
+ componentState: ComponentState;
80
+ setComponentState: (componentState: ComponentState) => void;
81
+ setComponentLoading: (id: string, loading?: boolean, defer?: number) => () => void;
82
+ unsetComponentLoading: (id: string) => void;
83
+ pendingLoadTimeouts: Record<string, NodeJS.Timeout>;
84
+ resolveComponentData: <T extends ComponentData | RootDataWithProps>(componentData: T, trigger: ResolveDataTrigger) => Promise<{
85
+ node: T;
86
+ didChange: boolean;
87
+ }>;
88
+ resolveAndCommitData: () => void;
89
+ plugins: Plugin[];
90
+ overrides: Partial<Overrides>;
91
+ viewports: Viewports;
92
+ zoomConfig: ZoomConfig;
93
+ setZoomConfig: (zoomConfig: ZoomConfig) => void;
94
+ status: Status;
95
+ setStatus: (status: Status) => void;
96
+ iframe: IframeConfig;
97
+ selectedItem?: G["UserData"]["content"][0] | null;
98
+ setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
99
+ getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
100
+ onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
101
+ metadata: Metadata;
102
+ fields: FieldsSlice;
103
+ history: HistorySlice;
104
+ nodes: NodesSlice;
105
+ permissions: PermissionsSlice;
106
+ };
107
+
7
108
  declare const ActionBar: {
8
109
  ({ label, children, }: {
9
110
  label?: string;
@@ -42,7 +143,7 @@ declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }:
42
143
  className?: string;
43
144
  }) => react_jsx_runtime.JSX.Element;
44
145
  type FieldNoLabel<Props extends any = any> = Omit<Field<Props>, "label">;
45
- declare function AutoField<ValueType = any, FieldType extends FieldNoLabel<ValueType> = FieldNoLabel<ValueType>>(props: FieldProps<FieldType, ValueType>): react_jsx_runtime.JSX.Element;
146
+ declare function AutoField<ValueType = any, FieldType extends FieldNoLabel<ValueType> = FieldNoLabel<ValueType>>(props: FieldProps<FieldType, ValueType>): react_jsx_runtime.JSX.Element | null;
46
147
 
47
148
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, ...props }: {
48
149
  children: ReactNode;
@@ -146,119 +247,19 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
146
247
  metadata?: Metadata;
147
248
  }): react_jsx_runtime.JSX.Element;
148
249
 
149
- declare function migrate(data: Data): Data;
150
-
151
- type HistorySlice<D = any> = {
152
- index: number;
153
- hasPast: () => boolean;
154
- hasFuture: () => boolean;
155
- histories: History<D>[];
156
- record: (data: D) => void;
157
- back: VoidFunction;
158
- forward: VoidFunction;
159
- currentHistory: () => History;
160
- nextHistory: () => History<D> | null;
161
- prevHistory: () => History<D> | null;
162
- setHistories: (histories: History[]) => void;
163
- setHistoryIndex: (index: number) => void;
164
- initialAppState: D;
165
- };
166
-
167
- type NodeMethods = {
168
- sync: () => void;
169
- };
170
- type PuckNode = {
171
- id: string;
172
- methods: NodeMethods;
173
- data: ComponentData;
174
- parentId: string | null;
175
- zone: string;
176
- path: string[];
177
- index: number;
178
- element: HTMLElement | null;
179
- };
180
- type NodesSlice = {
181
- nodes: Record<string, PuckNode | undefined>;
182
- registerNode: (id: string, node: Partial<PuckNode>) => void;
183
- unregisterNode: (id: string, node?: Partial<PuckNode>) => void;
184
- };
185
-
186
- type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
187
- item?: G["UserComponentData"] | null;
188
- type?: keyof G["UserProps"];
189
- root?: boolean;
190
- };
191
- type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
192
- type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
193
- type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
194
- type Cache = Record<string, {
195
- lastPermissions: Partial<Permissions>;
196
- lastData: ComponentData | null;
197
- }>;
198
- type PermissionsSlice = {
199
- cache: Cache;
200
- globalPermissions: Permissions;
201
- resolvedPermissions: Record<string, Partial<Permissions> | undefined>;
202
- getPermissions: GetPermissions<Config>;
203
- resolvePermissions: ResolvePermissions<Config>;
204
- refreshPermissions: RefreshPermissions<Config>;
205
- };
206
-
207
- type ComponentOrRootData = Omit<ComponentData<any>, "type">;
208
- type FieldsSlice = {
209
- fields: Fields | Partial<Fields>;
210
- loading: boolean;
211
- lastResolvedData: Partial<ComponentOrRootData>;
212
- };
213
-
214
- type Status = "LOADING" | "MOUNTED" | "READY";
215
- type ZoomConfig = {
216
- autoZoom: number;
217
- rootHeight: number;
218
- zoom: number;
219
- };
220
- type ComponentState = Record<string, {
221
- loadingCount: number;
222
- }>;
223
- type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
224
- state: G["UserAppState"];
225
- dispatch: (action: PuckAction) => void;
226
- config: UserConfig;
227
- componentState: ComponentState;
228
- setComponentState: (componentState: ComponentState) => void;
229
- setComponentLoading: (id: string) => void;
230
- unsetComponentLoading: (id: string) => void;
231
- resolveDataRuns: number;
232
- resolveData: (newAppState: AppState) => void;
233
- plugins: Plugin[];
234
- overrides: Partial<Overrides>;
235
- viewports: Viewports;
236
- zoomConfig: ZoomConfig;
237
- setZoomConfig: (zoomConfig: ZoomConfig) => void;
238
- status: Status;
239
- setStatus: (status: Status) => void;
240
- iframe: IframeConfig;
241
- selectedItem?: G["UserData"]["content"][0] | null;
242
- setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
243
- getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
244
- onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
245
- metadata: Metadata;
246
- fields: FieldsSlice;
247
- history: HistorySlice;
248
- nodes: NodesSlice;
249
- permissions: PermissionsSlice;
250
- };
251
-
252
250
  type WithGet<T> = T & {
253
251
  get: () => T;
254
252
  };
255
253
  type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
256
254
  appState: AppState;
257
- config: Config;
255
+ config: UserConfig;
258
256
  dispatch: AppStore["dispatch"];
259
257
  getPermissions: GetPermissions<UserConfig>;
260
258
  refreshPermissions: RefreshPermissions<UserConfig>;
261
259
  selectedItem: G["UserComponentData"] | null;
260
+ getItemBySelector: (selector: ItemSelector) => ComponentData | undefined;
261
+ getItemById: (id: string) => ComponentData | undefined;
262
+ getSelectorForId: (id: string) => Required<ItemSelector> | undefined;
262
263
  history: {
263
264
  back: HistorySlice["back"];
264
265
  forward: HistorySlice["forward"];
@@ -270,7 +271,8 @@ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<User
270
271
  hasFuture: boolean;
271
272
  };
272
273
  };
273
- type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<UserConfig>>;
274
+ type PuckApi<UserConfig extends Config = Config> = UsePuckData<UserConfig>;
275
+ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConfig>>;
274
276
  /**
275
277
  * createUsePuck
276
278
  *
@@ -280,7 +282,13 @@ type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<User
280
282
  *
281
283
  * @returns a typed usePuck function
282
284
  */
283
- declare function createUsePuck<UserConfig extends Config = Config>(): <T = UsePuckData<UserConfig, UserGenerics<UserConfig>>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
285
+ declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
284
286
  declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
287
+ /**
288
+ * Get the latest state without relying on a render
289
+ *
290
+ * @returns PuckApi
291
+ */
292
+ declare function useGetPuck(): () => UsePuckStore<Config>;
285
293
 
286
- export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, 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, usePuck };
294
+ export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, renderContext, useGetPuck, usePuck };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,110 @@
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 History, h as ComponentData, i as Fields, A as AppState, j as ComponentConfig } from './resolve-all-data-3XjIPfNh.js';
2
- export { K as Adaptor, G as ArrayField, r as ArrayState, a2 as AsFieldProps, B as BaseData, y as BaseField, w as ComponentDataMap, x as Content, W as CustomField, $ as DefaultComponentProps, Y as DefaultRootFieldProps, _ as DefaultRootProps, Z as DefaultRootRenderProps, k as Direction, l as DragAxis, Q as ExternalField, L as ExternalFieldWithAdaptor, a4 as ExtractPropsFromConfig, a5 as ExtractRootPropsFromConfig, p as FieldRenderFunctions, q as ItemWithId, v as MappedItem, N as NumberField, J as ObjectField, n as OverrideKey, s as PuckComponent, X as PuckContext, E as RadioField, u as RootData, R as RootDataWithProps, t as RootDataWithoutProps, S as SelectField, T as TextField, z as TextareaField, m as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, o as overrideKeys, a7 as resolveAllData, a6 as transformProps } from './resolve-all-data-3XjIPfNh.js';
1
+ import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-DOB5QZVq.js';
2
+ export { _ as Adaptor, Y as ArrayField, t as ArrayState, ab as AsFieldProps, B as BaseData, K as BaseField, G as ComponentDataMap, z as ComponentDataOptionalId, J as Content, a2 as CustomField, a1 as CustomFieldRender, a8 as DefaultComponentProps, a5 as DefaultRootFieldProps, a7 as DefaultRootProps, a6 as DefaultRootRenderProps, m as Direction, n as DragAxis, a0 as ExternalField, $ as ExternalFieldWithAdaptor, ad as ExtractPropsFromConfig, ae as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, E as MappedItem, N as NumberField, Z as ObjectField, q as OverrideKey, u as PuckComponent, a4 as PuckContext, X as RadioField, v as RootConfig, y as RootData, x as RootDataWithoutProps, Q as SelectField, S as Slot, a3 as SlotField, T as TextField, L as TextareaField, o as Viewport, ac as WithChildren, a9 as WithId, aa as WithPuckProps, W as WithSlotProps, af as migrate, p as overrideKeys, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DOB5QZVq.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
6
6
 
7
+ type HistorySlice<D = any> = {
8
+ index: number;
9
+ hasPast: () => boolean;
10
+ hasFuture: () => boolean;
11
+ histories: History<D>[];
12
+ record: (data: D) => void;
13
+ back: VoidFunction;
14
+ forward: VoidFunction;
15
+ currentHistory: () => History;
16
+ nextHistory: () => History<D> | null;
17
+ prevHistory: () => History<D> | null;
18
+ setHistories: (histories: History[]) => void;
19
+ setHistoryIndex: (index: number) => void;
20
+ initialAppState: D;
21
+ };
22
+
23
+ type NodeMethods = {
24
+ sync: () => void;
25
+ };
26
+ type PuckNodeInstance = {
27
+ id: string;
28
+ methods: NodeMethods;
29
+ element: HTMLElement | null;
30
+ };
31
+ type NodesSlice = {
32
+ nodes: Record<string, PuckNodeInstance | undefined>;
33
+ registerNode: (id: string, node: Partial<PuckNodeInstance>) => void;
34
+ unregisterNode: (id: string, node?: Partial<PuckNodeInstance>) => void;
35
+ };
36
+
37
+ type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
38
+ item?: G["UserComponentData"] | null;
39
+ type?: keyof G["UserProps"];
40
+ root?: boolean;
41
+ };
42
+ type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
43
+ type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
44
+ type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
45
+ type Cache = Record<string, {
46
+ lastPermissions: Partial<Permissions>;
47
+ lastData: ComponentData | null;
48
+ }>;
49
+ type PermissionsSlice = {
50
+ cache: Cache;
51
+ globalPermissions: Permissions;
52
+ resolvedPermissions: Record<string, Partial<Permissions> | undefined>;
53
+ getPermissions: GetPermissions<Config>;
54
+ resolvePermissions: ResolvePermissions<Config>;
55
+ refreshPermissions: RefreshPermissions<Config>;
56
+ };
57
+
58
+ type ComponentOrRootData = Omit<ComponentData<any>, "type">;
59
+ type FieldsSlice = {
60
+ fields: Fields | Partial<Fields>;
61
+ loading: boolean;
62
+ lastResolvedData: Partial<ComponentOrRootData>;
63
+ id: string | undefined;
64
+ };
65
+
66
+ type Status = "LOADING" | "MOUNTED" | "READY";
67
+ type ZoomConfig = {
68
+ autoZoom: number;
69
+ rootHeight: number;
70
+ zoom: number;
71
+ };
72
+ type ComponentState = Record<string, {
73
+ loadingCount: number;
74
+ }>;
75
+ type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
76
+ state: G["UserAppState"];
77
+ dispatch: (action: PuckAction) => void;
78
+ config: UserConfig;
79
+ componentState: ComponentState;
80
+ setComponentState: (componentState: ComponentState) => void;
81
+ setComponentLoading: (id: string, loading?: boolean, defer?: number) => () => void;
82
+ unsetComponentLoading: (id: string) => void;
83
+ pendingLoadTimeouts: Record<string, NodeJS.Timeout>;
84
+ resolveComponentData: <T extends ComponentData | RootDataWithProps>(componentData: T, trigger: ResolveDataTrigger) => Promise<{
85
+ node: T;
86
+ didChange: boolean;
87
+ }>;
88
+ resolveAndCommitData: () => void;
89
+ plugins: Plugin[];
90
+ overrides: Partial<Overrides>;
91
+ viewports: Viewports;
92
+ zoomConfig: ZoomConfig;
93
+ setZoomConfig: (zoomConfig: ZoomConfig) => void;
94
+ status: Status;
95
+ setStatus: (status: Status) => void;
96
+ iframe: IframeConfig;
97
+ selectedItem?: G["UserData"]["content"][0] | null;
98
+ setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
99
+ getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
100
+ onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
101
+ metadata: Metadata;
102
+ fields: FieldsSlice;
103
+ history: HistorySlice;
104
+ nodes: NodesSlice;
105
+ permissions: PermissionsSlice;
106
+ };
107
+
7
108
  declare const ActionBar: {
8
109
  ({ label, children, }: {
9
110
  label?: string;
@@ -42,7 +143,7 @@ declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }:
42
143
  className?: string;
43
144
  }) => react_jsx_runtime.JSX.Element;
44
145
  type FieldNoLabel<Props extends any = any> = Omit<Field<Props>, "label">;
45
- declare function AutoField<ValueType = any, FieldType extends FieldNoLabel<ValueType> = FieldNoLabel<ValueType>>(props: FieldProps<FieldType, ValueType>): react_jsx_runtime.JSX.Element;
146
+ declare function AutoField<ValueType = any, FieldType extends FieldNoLabel<ValueType> = FieldNoLabel<ValueType>>(props: FieldProps<FieldType, ValueType>): react_jsx_runtime.JSX.Element | null;
46
147
 
47
148
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, ...props }: {
48
149
  children: ReactNode;
@@ -146,119 +247,19 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
146
247
  metadata?: Metadata;
147
248
  }): react_jsx_runtime.JSX.Element;
148
249
 
149
- declare function migrate(data: Data): Data;
150
-
151
- type HistorySlice<D = any> = {
152
- index: number;
153
- hasPast: () => boolean;
154
- hasFuture: () => boolean;
155
- histories: History<D>[];
156
- record: (data: D) => void;
157
- back: VoidFunction;
158
- forward: VoidFunction;
159
- currentHistory: () => History;
160
- nextHistory: () => History<D> | null;
161
- prevHistory: () => History<D> | null;
162
- setHistories: (histories: History[]) => void;
163
- setHistoryIndex: (index: number) => void;
164
- initialAppState: D;
165
- };
166
-
167
- type NodeMethods = {
168
- sync: () => void;
169
- };
170
- type PuckNode = {
171
- id: string;
172
- methods: NodeMethods;
173
- data: ComponentData;
174
- parentId: string | null;
175
- zone: string;
176
- path: string[];
177
- index: number;
178
- element: HTMLElement | null;
179
- };
180
- type NodesSlice = {
181
- nodes: Record<string, PuckNode | undefined>;
182
- registerNode: (id: string, node: Partial<PuckNode>) => void;
183
- unregisterNode: (id: string, node?: Partial<PuckNode>) => void;
184
- };
185
-
186
- type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
187
- item?: G["UserComponentData"] | null;
188
- type?: keyof G["UserProps"];
189
- root?: boolean;
190
- };
191
- type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
192
- type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
193
- type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
194
- type Cache = Record<string, {
195
- lastPermissions: Partial<Permissions>;
196
- lastData: ComponentData | null;
197
- }>;
198
- type PermissionsSlice = {
199
- cache: Cache;
200
- globalPermissions: Permissions;
201
- resolvedPermissions: Record<string, Partial<Permissions> | undefined>;
202
- getPermissions: GetPermissions<Config>;
203
- resolvePermissions: ResolvePermissions<Config>;
204
- refreshPermissions: RefreshPermissions<Config>;
205
- };
206
-
207
- type ComponentOrRootData = Omit<ComponentData<any>, "type">;
208
- type FieldsSlice = {
209
- fields: Fields | Partial<Fields>;
210
- loading: boolean;
211
- lastResolvedData: Partial<ComponentOrRootData>;
212
- };
213
-
214
- type Status = "LOADING" | "MOUNTED" | "READY";
215
- type ZoomConfig = {
216
- autoZoom: number;
217
- rootHeight: number;
218
- zoom: number;
219
- };
220
- type ComponentState = Record<string, {
221
- loadingCount: number;
222
- }>;
223
- type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
224
- state: G["UserAppState"];
225
- dispatch: (action: PuckAction) => void;
226
- config: UserConfig;
227
- componentState: ComponentState;
228
- setComponentState: (componentState: ComponentState) => void;
229
- setComponentLoading: (id: string) => void;
230
- unsetComponentLoading: (id: string) => void;
231
- resolveDataRuns: number;
232
- resolveData: (newAppState: AppState) => void;
233
- plugins: Plugin[];
234
- overrides: Partial<Overrides>;
235
- viewports: Viewports;
236
- zoomConfig: ZoomConfig;
237
- setZoomConfig: (zoomConfig: ZoomConfig) => void;
238
- status: Status;
239
- setStatus: (status: Status) => void;
240
- iframe: IframeConfig;
241
- selectedItem?: G["UserData"]["content"][0] | null;
242
- setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
243
- getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
244
- onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
245
- metadata: Metadata;
246
- fields: FieldsSlice;
247
- history: HistorySlice;
248
- nodes: NodesSlice;
249
- permissions: PermissionsSlice;
250
- };
251
-
252
250
  type WithGet<T> = T & {
253
251
  get: () => T;
254
252
  };
255
253
  type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
256
254
  appState: AppState;
257
- config: Config;
255
+ config: UserConfig;
258
256
  dispatch: AppStore["dispatch"];
259
257
  getPermissions: GetPermissions<UserConfig>;
260
258
  refreshPermissions: RefreshPermissions<UserConfig>;
261
259
  selectedItem: G["UserComponentData"] | null;
260
+ getItemBySelector: (selector: ItemSelector) => ComponentData | undefined;
261
+ getItemById: (id: string) => ComponentData | undefined;
262
+ getSelectorForId: (id: string) => Required<ItemSelector> | undefined;
262
263
  history: {
263
264
  back: HistorySlice["back"];
264
265
  forward: HistorySlice["forward"];
@@ -270,7 +271,8 @@ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<User
270
271
  hasFuture: boolean;
271
272
  };
272
273
  };
273
- type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<UserConfig>>;
274
+ type PuckApi<UserConfig extends Config = Config> = UsePuckData<UserConfig>;
275
+ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConfig>>;
274
276
  /**
275
277
  * createUsePuck
276
278
  *
@@ -280,7 +282,13 @@ type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<User
280
282
  *
281
283
  * @returns a typed usePuck function
282
284
  */
283
- declare function createUsePuck<UserConfig extends Config = Config>(): <T = UsePuckData<UserConfig, UserGenerics<UserConfig>>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
285
+ declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
284
286
  declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
287
+ /**
288
+ * Get the latest state without relying on a render
289
+ *
290
+ * @returns PuckApi
291
+ */
292
+ declare function useGetPuck(): () => UsePuckStore<Config>;
285
293
 
286
- export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, 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, usePuck };
294
+ export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, renderContext, useGetPuck, usePuck };