@measured/puck 0.19.0-canary.32a6f78 → 0.19.0-canary.46835fd
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/{chunk-FNRHXUGA.mjs → chunk-7N5DRY4G.mjs} +49 -9
- package/dist/index.css +13 -0
- package/dist/index.d.mts +123 -36
- package/dist/index.d.ts +123 -36
- package/dist/index.js +4100 -3857
- package/dist/index.mjs +5080 -4878
- package/dist/{resolve-all-data-D43Z4niC.d.mts → resolve-all-data-3XjIPfNh.d.mts} +14 -1
- package/dist/{resolve-all-data-D43Z4niC.d.ts → resolve-all-data-3XjIPfNh.d.ts} +14 -1
- package/dist/rsc.d.mts +3 -3
- package/dist/rsc.d.ts +3 -3
- package/dist/rsc.js +43 -6
- package/dist/rsc.mjs +10 -6
- package/package.json +5 -3
@@ -91,6 +91,49 @@ var init_react_import = __esm({
|
|
91
91
|
}
|
92
92
|
});
|
93
93
|
|
94
|
+
// lib/transform-props.ts
|
95
|
+
init_react_import();
|
96
|
+
|
97
|
+
// lib/default-data.ts
|
98
|
+
init_react_import();
|
99
|
+
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
100
|
+
root: data.root || {},
|
101
|
+
content: data.content || []
|
102
|
+
});
|
103
|
+
|
104
|
+
// lib/transform-props.ts
|
105
|
+
function transformProps(data, propTransforms) {
|
106
|
+
const mapItem = (item) => {
|
107
|
+
if (propTransforms[item.type]) {
|
108
|
+
return __spreadProps(__spreadValues({}, item), {
|
109
|
+
props: propTransforms[item.type](item.props)
|
110
|
+
});
|
111
|
+
}
|
112
|
+
return item;
|
113
|
+
};
|
114
|
+
const defaultedData = defaultData(data);
|
115
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
116
|
+
let newRoot = __spreadValues({}, defaultedData.root);
|
117
|
+
if (propTransforms["root"]) {
|
118
|
+
if (defaultedData.root.props) {
|
119
|
+
newRoot.props = propTransforms["root"](rootProps);
|
120
|
+
} else {
|
121
|
+
newRoot = propTransforms["root"](rootProps);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
const afterPropTransforms = __spreadProps(__spreadValues({}, defaultedData), {
|
125
|
+
root: newRoot,
|
126
|
+
content: defaultedData.content.map(mapItem),
|
127
|
+
zones: Object.keys(data.zones || {}).reduce(
|
128
|
+
(acc, zoneKey) => __spreadProps(__spreadValues({}, acc), {
|
129
|
+
[zoneKey]: data.zones[zoneKey].map(mapItem)
|
130
|
+
}),
|
131
|
+
{}
|
132
|
+
)
|
133
|
+
});
|
134
|
+
return afterPropTransforms;
|
135
|
+
}
|
136
|
+
|
94
137
|
// lib/resolve-all-data.ts
|
95
138
|
init_react_import();
|
96
139
|
|
@@ -187,13 +230,6 @@ function resolveRootData(data, config, metadata) {
|
|
187
230
|
});
|
188
231
|
}
|
189
232
|
|
190
|
-
// lib/default-data.ts
|
191
|
-
init_react_import();
|
192
|
-
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
193
|
-
root: data.root || {},
|
194
|
-
content: data.content || []
|
195
|
-
});
|
196
|
-
|
197
233
|
// lib/resolve-all-data.ts
|
198
234
|
function resolveAllData(_0, _1) {
|
199
235
|
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
@@ -232,7 +268,9 @@ function resolveAllData(_0, _1) {
|
|
232
268
|
|
233
269
|
// lib/root-droppable-id.ts
|
234
270
|
init_react_import();
|
235
|
-
var
|
271
|
+
var rootAreaId = "root";
|
272
|
+
var rootZone = "default-zone";
|
273
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
236
274
|
|
237
275
|
// lib/setup-zone.ts
|
238
276
|
init_react_import();
|
@@ -258,11 +296,13 @@ export {
|
|
258
296
|
__privateSet,
|
259
297
|
__async,
|
260
298
|
init_react_import,
|
299
|
+
rootAreaId,
|
300
|
+
rootZone,
|
261
301
|
rootDroppableId,
|
262
302
|
setupZone,
|
263
303
|
getChanged,
|
264
304
|
resolveComponentData,
|
265
305
|
resolveRootData,
|
266
|
-
|
306
|
+
transformProps,
|
267
307
|
resolveAllData
|
268
308
|
};
|
package/dist/index.css
CHANGED
@@ -612,6 +612,19 @@ textarea._Input-input_g5w3n_26 {
|
|
612
612
|
}
|
613
613
|
}
|
614
614
|
|
615
|
+
/* components/Sortable/styles.css */
|
616
|
+
[data-dnd-placeholder] * {
|
617
|
+
opacity: 0 !important;
|
618
|
+
}
|
619
|
+
[data-dnd-placeholder] {
|
620
|
+
background: var(--puck-color-azure-09) !important;
|
621
|
+
border: none !important;
|
622
|
+
color: #00000000 !important;
|
623
|
+
opacity: 0.3 !important;
|
624
|
+
outline: none !important;
|
625
|
+
transition: none !important;
|
626
|
+
}
|
627
|
+
|
615
628
|
/* css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css/#css-module-data */
|
616
629
|
._ExternalInput-actions_91ls0_1 {
|
617
630
|
display: flex;
|
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,
|
2
|
-
export {
|
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';
|
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
|
-
|
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
|
-
}
|
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>;
|
@@ -142,58 +148,139 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
|
|
142
148
|
|
143
149
|
declare function migrate(data: Data): Data;
|
144
150
|
|
145
|
-
type
|
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;
|
155
|
-
|
156
|
-
type HistoryStore<D = any> = {
|
151
|
+
type HistorySlice<D = any> = {
|
157
152
|
index: number;
|
158
|
-
hasPast: boolean;
|
159
|
-
hasFuture: boolean;
|
153
|
+
hasPast: () => boolean;
|
154
|
+
hasFuture: () => boolean;
|
160
155
|
histories: History<D>[];
|
161
156
|
record: (data: D) => void;
|
162
157
|
back: VoidFunction;
|
163
158
|
forward: VoidFunction;
|
164
|
-
currentHistory: History;
|
165
|
-
nextHistory: History<D> | null;
|
166
|
-
prevHistory: History<D> | null;
|
159
|
+
currentHistory: () => History;
|
160
|
+
nextHistory: () => History<D> | null;
|
161
|
+
prevHistory: () => History<D> | null;
|
167
162
|
setHistories: (histories: History[]) => void;
|
168
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;
|
169
184
|
};
|
170
185
|
|
171
186
|
type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
|
172
|
-
item?: G["UserComponentData"];
|
187
|
+
item?: G["UserComponentData"] | null;
|
173
188
|
type?: keyof G["UserProps"];
|
174
189
|
root?: boolean;
|
175
190
|
};
|
176
|
-
type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) =>
|
191
|
+
type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
|
192
|
+
type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
|
177
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
|
+
};
|
178
206
|
|
179
|
-
|
180
|
-
|
181
|
-
|
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"];
|
182
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
|
+
type WithGet<T> = T & {
|
253
|
+
get: () => T;
|
254
|
+
};
|
255
|
+
type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
|
256
|
+
appState: AppState;
|
257
|
+
config: Config;
|
258
|
+
dispatch: AppStore["dispatch"];
|
183
259
|
getPermissions: GetPermissions<UserConfig>;
|
184
260
|
refreshPermissions: RefreshPermissions<UserConfig>;
|
261
|
+
selectedItem: G["UserComponentData"] | null;
|
185
262
|
history: {
|
186
|
-
back:
|
187
|
-
forward:
|
188
|
-
setHistories:
|
189
|
-
setHistoryIndex:
|
263
|
+
back: HistorySlice["back"];
|
264
|
+
forward: HistorySlice["forward"];
|
265
|
+
setHistories: HistorySlice["setHistories"];
|
266
|
+
setHistoryIndex: HistorySlice["setHistoryIndex"];
|
267
|
+
histories: HistorySlice["histories"];
|
268
|
+
index: HistorySlice["index"];
|
190
269
|
hasPast: boolean;
|
191
270
|
hasFuture: boolean;
|
192
|
-
histories: History<any>[];
|
193
|
-
index: number;
|
194
|
-
historyStore: HistoryStore | undefined;
|
195
271
|
};
|
196
|
-
selectedItem: ComponentDataMap<ExtractPropsFromConfig<UserConfig>> | null;
|
197
272
|
};
|
273
|
+
type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<UserConfig>>;
|
274
|
+
/**
|
275
|
+
* createUsePuck
|
276
|
+
*
|
277
|
+
* Create a typed usePuck hook, which is necessary because the user may provide a generic type but not
|
278
|
+
* a selector type, and TS does not currently support partial inference.
|
279
|
+
* Related: https://github.com/microsoft/TypeScript/issues/26242
|
280
|
+
*
|
281
|
+
* @returns a typed usePuck function
|
282
|
+
*/
|
283
|
+
declare function createUsePuck<UserConfig extends Config = Config>(): <T = UsePuckData<UserConfig, UserGenerics<UserConfig>>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
|
284
|
+
declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
|
198
285
|
|
199
|
-
export { Action, ActionBar, AppState, AutoField, Button,
|
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 };
|
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,
|
2
|
-
export {
|
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';
|
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
|
-
|
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
|
-
}
|
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>;
|
@@ -142,58 +148,139 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
|
|
142
148
|
|
143
149
|
declare function migrate(data: Data): Data;
|
144
150
|
|
145
|
-
type
|
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;
|
155
|
-
|
156
|
-
type HistoryStore<D = any> = {
|
151
|
+
type HistorySlice<D = any> = {
|
157
152
|
index: number;
|
158
|
-
hasPast: boolean;
|
159
|
-
hasFuture: boolean;
|
153
|
+
hasPast: () => boolean;
|
154
|
+
hasFuture: () => boolean;
|
160
155
|
histories: History<D>[];
|
161
156
|
record: (data: D) => void;
|
162
157
|
back: VoidFunction;
|
163
158
|
forward: VoidFunction;
|
164
|
-
currentHistory: History;
|
165
|
-
nextHistory: History<D> | null;
|
166
|
-
prevHistory: History<D> | null;
|
159
|
+
currentHistory: () => History;
|
160
|
+
nextHistory: () => History<D> | null;
|
161
|
+
prevHistory: () => History<D> | null;
|
167
162
|
setHistories: (histories: History[]) => void;
|
168
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;
|
169
184
|
};
|
170
185
|
|
171
186
|
type PermissionsArgs<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
|
172
|
-
item?: G["UserComponentData"];
|
187
|
+
item?: G["UserComponentData"] | null;
|
173
188
|
type?: keyof G["UserProps"];
|
174
189
|
root?: boolean;
|
175
190
|
};
|
176
|
-
type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) =>
|
191
|
+
type GetPermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>) => Permissions;
|
192
|
+
type ResolvePermissions<UserConfig extends Config = Config> = (params?: PermissionsArgs<UserConfig>, force?: boolean) => void;
|
177
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
|
+
};
|
178
206
|
|
179
|
-
|
180
|
-
|
181
|
-
|
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"];
|
182
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
|
+
type WithGet<T> = T & {
|
253
|
+
get: () => T;
|
254
|
+
};
|
255
|
+
type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
|
256
|
+
appState: AppState;
|
257
|
+
config: Config;
|
258
|
+
dispatch: AppStore["dispatch"];
|
183
259
|
getPermissions: GetPermissions<UserConfig>;
|
184
260
|
refreshPermissions: RefreshPermissions<UserConfig>;
|
261
|
+
selectedItem: G["UserComponentData"] | null;
|
185
262
|
history: {
|
186
|
-
back:
|
187
|
-
forward:
|
188
|
-
setHistories:
|
189
|
-
setHistoryIndex:
|
263
|
+
back: HistorySlice["back"];
|
264
|
+
forward: HistorySlice["forward"];
|
265
|
+
setHistories: HistorySlice["setHistories"];
|
266
|
+
setHistoryIndex: HistorySlice["setHistoryIndex"];
|
267
|
+
histories: HistorySlice["histories"];
|
268
|
+
index: HistorySlice["index"];
|
190
269
|
hasPast: boolean;
|
191
270
|
hasFuture: boolean;
|
192
|
-
histories: History<any>[];
|
193
|
-
index: number;
|
194
|
-
historyStore: HistoryStore | undefined;
|
195
271
|
};
|
196
|
-
selectedItem: ComponentDataMap<ExtractPropsFromConfig<UserConfig>> | null;
|
197
272
|
};
|
273
|
+
type UsePuckStore<UserConfig extends Config = Config> = WithGet<UsePuckData<UserConfig>>;
|
274
|
+
/**
|
275
|
+
* createUsePuck
|
276
|
+
*
|
277
|
+
* Create a typed usePuck hook, which is necessary because the user may provide a generic type but not
|
278
|
+
* a selector type, and TS does not currently support partial inference.
|
279
|
+
* Related: https://github.com/microsoft/TypeScript/issues/26242
|
280
|
+
*
|
281
|
+
* @returns a typed usePuck function
|
282
|
+
*/
|
283
|
+
declare function createUsePuck<UserConfig extends Config = Config>(): <T = UsePuckData<UserConfig, UserGenerics<UserConfig>>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
|
284
|
+
declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
|
198
285
|
|
199
|
-
export { Action, ActionBar, AppState, AutoField, Button,
|
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 };
|