@measured/puck 0.19.0-canary.32a6f78 → 0.19.0-canary.4b545576

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,8 +1,108 @@
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-D43Z4niC.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-D43Z4niC.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 RootData, m as Content, n as ItemSelector } from './resolve-all-data-BFRAghCj.js';
2
+ export { X as Adaptor, Q as ArrayField, v as ArrayState, a7 as AsFieldProps, B as BaseData, G as BaseField, E as ComponentDataMap, _ as CustomField, a4 as DefaultComponentProps, a1 as DefaultRootFieldProps, a3 as DefaultRootProps, a2 as DefaultRootRenderProps, o as Direction, p as DragAxis, Z as ExternalField, Y as ExternalFieldWithAdaptor, a9 as ExtractPropsFromConfig, aa as ExtractRootPropsFromConfig, t as FieldRenderFunctions, u as ItemWithId, z as MappedItem, N as NumberField, W as ObjectField, s as OverrideKey, w as PuckComponent, a0 as PuckContext, L as RadioField, x as RootConfig, y as RootDataWithoutProps, K as SelectField, S as Slot, $ as SlotField, T as TextField, J as TextareaField, q as Viewport, a8 as WithChildren, a5 as WithId, a6 as WithPuckProps, r as overrideKeys, ac as resolveAllData, ab as transformProps } from './resolve-all-data-BFRAghCj.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
+
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
+ };
64
+
65
+ type Status = "LOADING" | "MOUNTED" | "READY";
66
+ type ZoomConfig = {
67
+ autoZoom: number;
68
+ rootHeight: number;
69
+ zoom: number;
70
+ };
71
+ type ComponentState = Record<string, {
72
+ loadingCount: number;
73
+ }>;
74
+ type AppStore<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
75
+ state: G["UserAppState"];
76
+ dispatch: (action: PuckAction) => void;
77
+ config: UserConfig;
78
+ componentState: ComponentState;
79
+ setComponentState: (componentState: ComponentState) => void;
80
+ setComponentLoading: (id: string, loading?: boolean, defer?: number) => () => void;
81
+ unsetComponentLoading: (id: string) => void;
82
+ pendingLoadTimeouts: Record<string, NodeJS.Timeout>;
83
+ resolveComponentData: <T extends ComponentData | RootDataWithProps>(componentData: T, trigger: ResolveDataTrigger) => Promise<{
84
+ node: T;
85
+ didChange: boolean;
86
+ }>;
87
+ resolveAndCommitData: () => void;
88
+ plugins: Plugin[];
89
+ overrides: Partial<Overrides>;
90
+ viewports: Viewports;
91
+ zoomConfig: ZoomConfig;
92
+ setZoomConfig: (zoomConfig: ZoomConfig) => void;
93
+ status: Status;
94
+ setStatus: (status: Status) => void;
95
+ iframe: IframeConfig;
96
+ selectedItem?: G["UserData"]["content"][0] | null;
97
+ setUi: (ui: Partial<UiState>, recordHistory?: boolean) => void;
98
+ getComponentConfig: (type?: string) => ComponentConfig | null | undefined;
99
+ onAction?: (action: PuckAction, newState: AppState, state: AppState) => void;
100
+ metadata: Metadata;
101
+ fields: FieldsSlice;
102
+ history: HistorySlice;
103
+ nodes: NodesSlice;
104
+ permissions: PermissionsSlice;
105
+ };
6
106
 
7
107
  declare const ActionBar: {
8
108
  ({ label, children, }: {
@@ -42,7 +142,7 @@ declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }:
42
142
  className?: string;
43
143
  }) => react_jsx_runtime.JSX.Element;
44
144
  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;
145
+ declare function AutoField<ValueType = any, FieldType extends FieldNoLabel<ValueType> = FieldNoLabel<ValueType>>(props: FieldProps<FieldType, ValueType>): react_jsx_runtime.JSX.Element | null;
46
146
 
47
147
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, loading: loadingProp, ...props }: {
48
148
  children: ReactNode;
@@ -93,7 +193,7 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
93
193
  title: string;
94
194
  }) => react_jsx_runtime.JSX.Element;
95
195
 
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, }: {
196
+ type PuckProps<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
97
197
  children?: ReactNode;
98
198
  config: UserConfig;
99
199
  data: Partial<G["UserData"] | Data>;
@@ -122,7 +222,8 @@ declare function Puck<UserConfig extends Config = Config, G extends UserGenerics
122
222
  };
123
223
  initialHistory?: InitialHistory;
124
224
  metadata?: Metadata;
125
- }): react_jsx_runtime.JSX.Element;
225
+ };
226
+ declare function Puck<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(props: PuckProps<UserConfig>): react_jsx_runtime.JSX.Element;
126
227
  declare namespace Puck {
127
228
  var Components: () => react_jsx_runtime.JSX.Element;
128
229
  var Fields: ({ wrapFields }: {
@@ -134,66 +235,61 @@ declare namespace Puck {
134
235
  }) => react_jsx_runtime.JSX.Element;
135
236
  }
136
237
 
238
+ declare const renderContext: react__default.Context<{
239
+ config: Config;
240
+ data: Data;
241
+ metadata: Metadata;
242
+ }>;
137
243
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
138
244
  config: UserConfig;
139
245
  data: Partial<G["UserData"] | Data>;
140
246
  metadata?: Metadata;
141
247
  }): react_jsx_runtime.JSX.Element;
142
248
 
143
- declare function migrate(data: Data): Data;
144
-
145
- type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
146
- [ComponentName in keyof Props]: (props: Props[ComponentName] & {
147
- [key: string]: any;
148
- }) => Props[ComponentName];
149
- } & {
150
- root: (props: RootProps & {
151
- [key: string]: any;
152
- }) => RootProps;
153
- }>;
154
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
249
+ declare function migrate(data: Data, config?: Config): Data;
155
250
 
156
- type HistoryStore<D = any> = {
157
- index: number;
158
- hasPast: boolean;
159
- hasFuture: boolean;
160
- histories: History<D>[];
161
- record: (data: D) => void;
162
- back: VoidFunction;
163
- forward: VoidFunction;
164
- currentHistory: History;
165
- nextHistory: History<D> | null;
166
- prevHistory: History<D> | null;
167
- setHistories: (histories: History[]) => void;
168
- setHistoryIndex: (index: number) => void;
251
+ type MapSlotOptions = {
252
+ parentId: string;
253
+ propName: string;
169
254
  };
255
+ declare function mapSlotsPublic<T extends ComponentData | RootData>(item: T, config: Config, map: (data: Content, options: MapSlotOptions) => Content): T;
170
256
 
171
- type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
172
- item?: G["UserComponentData"];
173
- type?: keyof G["UserProps"];
174
- root?: boolean;
257
+ type WithGet<T> = T & {
258
+ get: () => T;
175
259
  };
176
- type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Partial<Permissions>;
177
- type RefreshPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
178
-
179
- declare const usePuck: <UserConfig extends Config = Config>() => {
180
- appState: AppState<Data<ExtractPropsFromConfig<UserConfig>, ExtractRootPropsFromConfig<UserConfig>>>;
181
- config: UserConfig;
182
- dispatch: (action: PuckAction) => void;
260
+ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
261
+ appState: AppState;
262
+ config: Config;
263
+ dispatch: AppStore["dispatch"];
183
264
  getPermissions: GetPermissions<UserConfig>;
184
265
  refreshPermissions: RefreshPermissions<UserConfig>;
266
+ selectedItem: G["UserComponentData"] | null;
267
+ getItemBySelector: (selector: ItemSelector) => ComponentData | undefined;
268
+ getItemById: (id: string) => ComponentData | undefined;
269
+ getSelectorForId: (id: string) => Required<ItemSelector> | undefined;
185
270
  history: {
186
- back: VoidFunction;
187
- forward: VoidFunction;
188
- setHistories: (histories: History[]) => void;
189
- setHistoryIndex: (index: number) => void;
271
+ back: HistorySlice["back"];
272
+ forward: HistorySlice["forward"];
273
+ setHistories: HistorySlice["setHistories"];
274
+ setHistoryIndex: HistorySlice["setHistoryIndex"];
275
+ histories: HistorySlice["histories"];
276
+ index: HistorySlice["index"];
190
277
  hasPast: boolean;
191
278
  hasFuture: boolean;
192
- histories: History<any>[];
193
- index: number;
194
- historyStore: HistoryStore | undefined;
195
279
  };
196
- selectedItem: ComponentDataMap<ExtractPropsFromConfig<UserConfig>> | null;
197
280
  };
281
+ type PuckApi<UserConfig extends Config = Config> = UsePuckData<UserConfig>;
282
+ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConfig>>;
283
+ /**
284
+ * createUsePuck
285
+ *
286
+ * Create a typed usePuck hook, which is necessary because the user may provide a generic type but not
287
+ * a selector type, and TS does not currently support partial inference.
288
+ * Related: https://github.com/microsoft/TypeScript/issues/26242
289
+ *
290
+ * @returns a typed usePuck function
291
+ */
292
+ declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
293
+ declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
198
294
 
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 };
295
+ export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Content, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootData, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, mapSlotsPublic as mapSlots, migrate, renderContext, usePuck };