@measured/puck 0.16.0-canary.0c7fc83 → 0.16.0-canary.39e7f40
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 +94 -88
- package/dist/index.js +48 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { U as UiState, D as Data, A as AppState, F as Field, a as FieldProps, C as Config, b as DefaultRootProps,
|
1
|
+
import { U as UiState, D as Data, A as AppState, I as ItemSelector, F as Field, a as FieldProps, C as Config, b as DefaultRootProps, c as DropZoneProps, V as Viewports, d as DefaultComponentProps, M as MappedItem, R as RootDataWithProps, e as RootData, f as ComponentData } from './Config-041c35a2.js';
|
2
2
|
export { q as Adaptor, p as ArrayField, l as ArrayState, B as BaseData, m as BaseField, i as ComponentConfig, g as Content, s as CustomField, r as ExternalField, E as ExternalFieldWithAdaptor, t as Fields, k as ItemWithId, N as NumberField, O as ObjectField, P as PuckComponent, h as PuckContext, o as RadioField, j as RootDataWithoutProps, S as SelectField, T as TextField, n as TextareaField } from './Config-041c35a2.js';
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
3
|
import * as react from 'react';
|
5
4
|
import { ReactNode, ReactElement, CSSProperties, SyntheticEvent } from 'react';
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
6
6
|
import { DragStart, DragUpdate } from '@measured/dnd';
|
7
7
|
|
8
8
|
type InsertAction = {
|
@@ -64,6 +64,65 @@ type PuckAction = {
|
|
64
64
|
recordHistory?: boolean;
|
65
65
|
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
|
66
66
|
|
67
|
+
type RenderFunc<Props extends {
|
68
|
+
[key: string]: any;
|
69
|
+
} = {
|
70
|
+
children: ReactNode;
|
71
|
+
}> = (props: Props) => ReactElement;
|
72
|
+
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
|
73
|
+
type OverrideKey = (typeof overrideKeys)[number];
|
74
|
+
type OverridesGeneric<Shape extends {
|
75
|
+
[key in OverrideKey]: any;
|
76
|
+
}> = Shape;
|
77
|
+
type Overrides = OverridesGeneric<{
|
78
|
+
fieldTypes: Partial<FieldRenderFunctions>;
|
79
|
+
header: RenderFunc<{
|
80
|
+
actions: ReactNode;
|
81
|
+
children: ReactNode;
|
82
|
+
}>;
|
83
|
+
headerActions: RenderFunc<{
|
84
|
+
children: ReactNode;
|
85
|
+
}>;
|
86
|
+
preview: RenderFunc;
|
87
|
+
fields: RenderFunc<{
|
88
|
+
children: ReactNode;
|
89
|
+
isLoading: boolean;
|
90
|
+
itemSelector?: ItemSelector | null;
|
91
|
+
}>;
|
92
|
+
fieldLabel: RenderFunc<{
|
93
|
+
children?: ReactNode;
|
94
|
+
icon?: ReactNode;
|
95
|
+
label: string;
|
96
|
+
el?: "label" | "div";
|
97
|
+
readOnly?: boolean;
|
98
|
+
className?: string;
|
99
|
+
}>;
|
100
|
+
components: RenderFunc;
|
101
|
+
componentItem: RenderFunc<{
|
102
|
+
children: ReactNode;
|
103
|
+
name: string;
|
104
|
+
}>;
|
105
|
+
outline: RenderFunc;
|
106
|
+
puck: RenderFunc;
|
107
|
+
}>;
|
108
|
+
type FieldRenderFunctions = Omit<{
|
109
|
+
[Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
|
110
|
+
type: Type;
|
111
|
+
}>> & {
|
112
|
+
children: ReactNode;
|
113
|
+
name: string;
|
114
|
+
}>;
|
115
|
+
}, "custom"> & {
|
116
|
+
[key: string]: React.FunctionComponent<FieldProps<any> & {
|
117
|
+
children: ReactNode;
|
118
|
+
name: string;
|
119
|
+
}>;
|
120
|
+
};
|
121
|
+
|
122
|
+
type Plugin = {
|
123
|
+
overrides: Partial<Overrides>;
|
124
|
+
};
|
125
|
+
|
67
126
|
declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }: {
|
68
127
|
children?: ReactNode;
|
69
128
|
icon?: ReactNode;
|
@@ -129,6 +188,25 @@ declare const Drawer: {
|
|
129
188
|
}) => react_jsx_runtime.JSX.Element;
|
130
189
|
};
|
131
190
|
|
191
|
+
type History<D = any> = {
|
192
|
+
id: string;
|
193
|
+
data: D;
|
194
|
+
};
|
195
|
+
type HistoryStore<D = any> = {
|
196
|
+
index: number;
|
197
|
+
hasPast: boolean;
|
198
|
+
hasFuture: boolean;
|
199
|
+
histories: History<D>[];
|
200
|
+
record: (data: D) => void;
|
201
|
+
back: VoidFunction;
|
202
|
+
forward: VoidFunction;
|
203
|
+
currentHistory: History;
|
204
|
+
nextHistory: History<D> | null;
|
205
|
+
prevHistory: History<D> | null;
|
206
|
+
setHistories: (histories: History[]) => void;
|
207
|
+
setHistoryIndex: (index: number) => void;
|
208
|
+
};
|
209
|
+
|
132
210
|
type PathData = Record<string, {
|
133
211
|
path: string[];
|
134
212
|
label: string;
|
@@ -181,87 +259,11 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
|
|
181
259
|
title: string;
|
182
260
|
}) => react_jsx_runtime.JSX.Element;
|
183
261
|
|
184
|
-
type RenderFunc<Props extends {
|
185
|
-
[key: string]: any;
|
186
|
-
} = {
|
187
|
-
children: ReactNode;
|
188
|
-
}> = (props: Props) => ReactElement;
|
189
|
-
declare const overrideKeys: readonly ["header", "headerActions", "fields", "fieldLabel", "components", "componentItem", "outline", "puck", "preview"];
|
190
|
-
type OverrideKey = (typeof overrideKeys)[number];
|
191
|
-
type OverridesGeneric<Shape extends {
|
192
|
-
[key in OverrideKey]: any;
|
193
|
-
}> = Shape;
|
194
|
-
type Overrides = OverridesGeneric<{
|
195
|
-
fieldTypes: Partial<FieldRenderFunctions>;
|
196
|
-
header: RenderFunc<{
|
197
|
-
actions: ReactNode;
|
198
|
-
children: ReactNode;
|
199
|
-
}>;
|
200
|
-
headerActions: RenderFunc<{
|
201
|
-
children: ReactNode;
|
202
|
-
}>;
|
203
|
-
preview: RenderFunc;
|
204
|
-
fields: RenderFunc<{
|
205
|
-
children: ReactNode;
|
206
|
-
isLoading: boolean;
|
207
|
-
itemSelector?: ItemSelector | null;
|
208
|
-
}>;
|
209
|
-
fieldLabel: RenderFunc<{
|
210
|
-
children?: ReactNode;
|
211
|
-
icon?: ReactNode;
|
212
|
-
label: string;
|
213
|
-
el?: "label" | "div";
|
214
|
-
readOnly?: boolean;
|
215
|
-
className?: string;
|
216
|
-
}>;
|
217
|
-
components: RenderFunc;
|
218
|
-
componentItem: RenderFunc<{
|
219
|
-
children: ReactNode;
|
220
|
-
name: string;
|
221
|
-
}>;
|
222
|
-
outline: RenderFunc;
|
223
|
-
puck: RenderFunc;
|
224
|
-
}>;
|
225
|
-
type FieldRenderFunctions = Omit<{
|
226
|
-
[Type in Field["type"]]: React.FunctionComponent<FieldProps<Extract<Field, {
|
227
|
-
type: Type;
|
228
|
-
}>> & {
|
229
|
-
children: ReactNode;
|
230
|
-
name: string;
|
231
|
-
}>;
|
232
|
-
}, "custom"> & {
|
233
|
-
[key: string]: React.FunctionComponent<FieldProps<any> & {
|
234
|
-
children: ReactNode;
|
235
|
-
name: string;
|
236
|
-
}>;
|
237
|
-
};
|
238
|
-
|
239
|
-
type Plugin = {
|
240
|
-
overrides: Partial<Overrides>;
|
241
|
-
};
|
242
|
-
|
243
|
-
type History<D = any> = {
|
244
|
-
id: string;
|
245
|
-
data: D;
|
246
|
-
};
|
247
|
-
type HistoryStore<D = any> = {
|
248
|
-
index: number;
|
249
|
-
currentHistory: History;
|
250
|
-
hasPast: boolean;
|
251
|
-
hasFuture: boolean;
|
252
|
-
record: (data: D) => void;
|
253
|
-
back: VoidFunction;
|
254
|
-
forward: VoidFunction;
|
255
|
-
nextHistory: History<D> | null;
|
256
|
-
prevHistory: History<D> | null;
|
257
|
-
histories: History<D>[];
|
258
|
-
};
|
259
|
-
|
260
262
|
type IframeConfig = {
|
261
263
|
enabled?: boolean;
|
262
264
|
};
|
263
265
|
|
264
|
-
declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd,
|
266
|
+
declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
|
265
267
|
children?: ReactNode;
|
266
268
|
config: UserConfig;
|
267
269
|
data: Partial<Data>;
|
@@ -286,7 +288,7 @@ declare function Puck<UserConfig extends Config = Config>({ children, config, da
|
|
286
288
|
dnd?: {
|
287
289
|
disableAutoScroll?: boolean;
|
288
290
|
};
|
289
|
-
|
291
|
+
initialHistory?: {
|
290
292
|
histories: History<any>[];
|
291
293
|
index: number;
|
292
294
|
};
|
@@ -324,20 +326,24 @@ declare function resolveAllData(data: Partial<Data>, config: Config, onResolveSt
|
|
324
326
|
zones: Record<string, MappedItem[]>;
|
325
327
|
}>;
|
326
328
|
|
327
|
-
type PuckHistory = {
|
328
|
-
back: VoidFunction;
|
329
|
-
forward: VoidFunction;
|
330
|
-
historyStore: HistoryStore;
|
331
|
-
};
|
332
|
-
|
333
329
|
declare const usePuck: () => {
|
334
330
|
appState: AppState;
|
335
331
|
config: Config<Record<string, any>, DefaultRootProps, string>;
|
336
332
|
dispatch: (action: PuckAction) => void;
|
337
|
-
history:
|
333
|
+
history: {
|
334
|
+
back: VoidFunction;
|
335
|
+
forward: VoidFunction;
|
336
|
+
setHistories: (histories: History<any>[]) => void;
|
337
|
+
setHistoryIndex: (index: number) => void;
|
338
|
+
hasPast: boolean;
|
339
|
+
hasFuture: boolean;
|
340
|
+
histories: History<any>[];
|
341
|
+
index: number;
|
342
|
+
historyStore: HistoryStore<any> | undefined;
|
343
|
+
};
|
338
344
|
selectedItem: ComponentData<DefaultComponentProps & {
|
339
345
|
id: string;
|
340
346
|
}> | null;
|
341
347
|
};
|
342
348
|
|
343
|
-
export { AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, FieldPropsInternal, IconButton, MappedItem, Puck, PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };
|
349
|
+
export { AppState, AutoField, AutoFieldPrivate, Button, ComponentData, Config, Data, DefaultComponentProps, DefaultRootProps, Drawer, DropZone, DropZoneProvider, Field, FieldLabel, FieldLabelInternal, FieldProps, FieldPropsInternal, History, IconButton, MappedItem, Plugin, Puck, PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, migrate, resolveAllData, transformProps, usePuck };
|
package/dist/index.js
CHANGED
@@ -29167,6 +29167,9 @@ init_react_import();
|
|
29167
29167
|
// types/Config.tsx
|
29168
29168
|
init_react_import();
|
29169
29169
|
|
29170
|
+
// types/Plugin.ts
|
29171
|
+
init_react_import();
|
29172
|
+
|
29170
29173
|
// types/Fields.ts
|
29171
29174
|
init_react_import();
|
29172
29175
|
|
@@ -33266,13 +33269,33 @@ function usePuckHistory({
|
|
33266
33269
|
historyStore.forward();
|
33267
33270
|
}
|
33268
33271
|
};
|
33272
|
+
const setHistories = (histories) => {
|
33273
|
+
var _a;
|
33274
|
+
dispatch({
|
33275
|
+
type: "set",
|
33276
|
+
state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.data) || initialAppState
|
33277
|
+
});
|
33278
|
+
historyStore.setHistories(histories);
|
33279
|
+
};
|
33280
|
+
const setHistoryIndex = (index) => {
|
33281
|
+
var _a;
|
33282
|
+
if (historyStore.histories.length > index) {
|
33283
|
+
dispatch({
|
33284
|
+
type: "set",
|
33285
|
+
state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.data) || initialAppState
|
33286
|
+
});
|
33287
|
+
historyStore.setHistoryIndex(index);
|
33288
|
+
}
|
33289
|
+
};
|
33269
33290
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+z", back, { preventDefault: true });
|
33270
33291
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
|
33271
33292
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
|
33272
33293
|
return {
|
33273
33294
|
back,
|
33274
33295
|
forward,
|
33275
|
-
historyStore
|
33296
|
+
historyStore,
|
33297
|
+
setHistories,
|
33298
|
+
setHistoryIndex
|
33276
33299
|
};
|
33277
33300
|
}
|
33278
33301
|
|
@@ -33281,13 +33304,17 @@ init_react_import();
|
|
33281
33304
|
var import_react27 = require("react");
|
33282
33305
|
var import_use_debounce3 = require("use-debounce");
|
33283
33306
|
var EMPTY_HISTORY_INDEX = -1;
|
33284
|
-
function useHistoryStore(
|
33307
|
+
function useHistoryStore(initialHistory) {
|
33285
33308
|
var _a, _b;
|
33286
33309
|
const [histories, setHistories] = (0, import_react27.useState)(
|
33287
|
-
(_a =
|
33310
|
+
(_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
|
33288
33311
|
);
|
33312
|
+
const updateHistories = (histories2) => {
|
33313
|
+
setHistories(histories2);
|
33314
|
+
setIndex(histories2.length - 1);
|
33315
|
+
};
|
33289
33316
|
const [index, setIndex] = (0, import_react27.useState)(
|
33290
|
-
(_b =
|
33317
|
+
(_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
|
33291
33318
|
);
|
33292
33319
|
const hasPast = index > EMPTY_HISTORY_INDEX;
|
33293
33320
|
const hasFuture = index < histories.length - 1;
|
@@ -33299,11 +33326,7 @@ function useHistoryStore(initialHistories) {
|
|
33299
33326
|
data,
|
33300
33327
|
id: generateId("history")
|
33301
33328
|
};
|
33302
|
-
|
33303
|
-
const newVal = [...prev.slice(0, index + 1), history];
|
33304
|
-
setIndex(newVal.length - 1);
|
33305
|
-
return newVal;
|
33306
|
-
});
|
33329
|
+
updateHistories([...histories.slice(0, index + 1), history]);
|
33307
33330
|
}, 250);
|
33308
33331
|
const back = () => {
|
33309
33332
|
setIndex(index - 1);
|
@@ -33321,7 +33344,9 @@ function useHistoryStore(initialHistories) {
|
|
33321
33344
|
forward,
|
33322
33345
|
nextHistory,
|
33323
33346
|
prevHistory,
|
33324
|
-
histories
|
33347
|
+
histories,
|
33348
|
+
setHistories: updateHistories,
|
33349
|
+
setHistoryIndex: setIndex
|
33325
33350
|
};
|
33326
33351
|
}
|
33327
33352
|
|
@@ -33766,10 +33791,10 @@ function Puck({
|
|
33766
33791
|
enabled: true
|
33767
33792
|
},
|
33768
33793
|
dnd,
|
33769
|
-
|
33794
|
+
initialHistory
|
33770
33795
|
}) {
|
33771
33796
|
var _a;
|
33772
|
-
const historyStore = useHistoryStore(
|
33797
|
+
const historyStore = useHistoryStore(initialHistory);
|
33773
33798
|
const [reducer] = (0, import_react30.useState)(
|
33774
33799
|
() => createReducer({ config, record: historyStore.record })
|
33775
33800
|
);
|
@@ -34325,7 +34350,17 @@ var usePuck = () => {
|
|
34325
34350
|
appState,
|
34326
34351
|
config,
|
34327
34352
|
dispatch,
|
34328
|
-
history
|
34353
|
+
history: {
|
34354
|
+
back: history.back,
|
34355
|
+
forward: history.forward,
|
34356
|
+
setHistories: history.setHistories,
|
34357
|
+
setHistoryIndex: history.setHistoryIndex,
|
34358
|
+
hasPast: history.historyStore.hasPast,
|
34359
|
+
hasFuture: history.historyStore.hasFuture,
|
34360
|
+
histories: history.historyStore.histories,
|
34361
|
+
index: history.historyStore.index,
|
34362
|
+
historyStore: history.historyStore
|
34363
|
+
},
|
34329
34364
|
selectedItem: selectedItem || null
|
34330
34365
|
};
|
34331
34366
|
};
|
package/package.json
CHANGED