@payloadcms/next 3.0.0-beta.108 → 3.0.0-beta.109
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/prod/styles.css +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +23 -11
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/rest/routeError.d.ts +2 -7
- package/dist/routes/rest/routeError.d.ts.map +1 -1
- package/dist/routes/rest/routeError.js +33 -19
- package/dist/routes/rest/routeError.js.map +1 -1
- package/dist/utilities/getRequestTheme.d.ts.map +1 -1
- package/dist/utilities/getRequestTheme.js +3 -0
- package/dist/utilities/getRequestTheme.js.map +1 -1
- package/dist/views/Account/Settings/index.d.ts +2 -1
- package/dist/views/Account/Settings/index.d.ts.map +1 -1
- package/dist/views/Account/Settings/index.js +3 -2
- package/dist/views/Account/Settings/index.js.map +1 -1
- package/dist/views/Account/index.d.ts.map +1 -1
- package/dist/views/Account/index.js +3 -1
- package/dist/views/Account/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +31 -15
- package/dist/views/CreateFirstUser/index.client.js.map +1 -1
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +30 -65
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/ForgotPassword/index.js +2 -2
- package/dist/views/ForgotPassword/index.js.map +1 -1
- package/dist/views/LivePreview/index.client.d.ts.map +1 -1
- package/dist/views/LivePreview/index.client.js +214 -203
- package/dist/views/LivePreview/index.client.js.map +1 -1
- package/dist/views/Version/Restore/index.d.ts.map +1 -1
- package/dist/views/Version/Restore/index.js +8 -14
- package/dist/views/Version/Restore/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { DocumentControls, DocumentFields, Form, OperationProvider, SetViewActions, useAuth, useConfig, useDocumentEvents, useDocumentInfo, useTranslation } from '@payloadcms/ui';
|
|
6
|
-
import { getFormState } from '@payloadcms/ui/shared';
|
|
7
|
-
import
|
|
6
|
+
import { getFormState, handleBackToDashboard, handleGoBack, handleTakeOver } from '@payloadcms/ui/shared';
|
|
7
|
+
import { useRouter } from 'next/navigation.js';
|
|
8
|
+
import React, { Fragment, useCallback, useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { DocumentLocked } from '../../elements/DocumentLocked/index.js';
|
|
10
|
+
import { DocumentTakeOver } from '../../elements/DocumentTakeOver/index.js';
|
|
8
11
|
import { LeaveWithoutSaving } from '../../elements/LeaveWithoutSaving/index.js';
|
|
9
12
|
import { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js';
|
|
10
13
|
import { SetDocumentTitle } from '../Edit/Default/SetDocumentTitle/index.js';
|
|
@@ -13,17 +16,15 @@ import { LivePreviewProvider } from './Context/index.js';
|
|
|
13
16
|
import { LivePreview } from './Preview/index.js';
|
|
14
17
|
import { usePopupWindow } from './usePopupWindow.js';
|
|
15
18
|
const baseClass = 'live-preview';
|
|
16
|
-
const PreviewView =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
serverURL
|
|
26
|
-
} = t0;
|
|
19
|
+
const PreviewView = ({
|
|
20
|
+
apiRoute,
|
|
21
|
+
collectionConfig,
|
|
22
|
+
config,
|
|
23
|
+
fields,
|
|
24
|
+
globalConfig,
|
|
25
|
+
schemaPath,
|
|
26
|
+
serverURL
|
|
27
|
+
}) => {
|
|
27
28
|
const {
|
|
28
29
|
id,
|
|
29
30
|
action,
|
|
@@ -33,9 +34,11 @@ const PreviewView = t0 => {
|
|
|
33
34
|
BeforeDocument,
|
|
34
35
|
BeforeFields,
|
|
35
36
|
collectionSlug,
|
|
37
|
+
currentEditor,
|
|
36
38
|
disableActions,
|
|
37
39
|
disableLeaveWithoutSaving,
|
|
38
40
|
docPermissions,
|
|
41
|
+
documentIsLocked,
|
|
39
42
|
getDocPreferences,
|
|
40
43
|
globalSlug,
|
|
41
44
|
hasPublishPermission,
|
|
@@ -44,18 +47,24 @@ const PreviewView = t0 => {
|
|
|
44
47
|
initialState,
|
|
45
48
|
isEditing,
|
|
46
49
|
isInitializing,
|
|
47
|
-
onSave: onSaveFromProps
|
|
50
|
+
onSave: onSaveFromProps,
|
|
51
|
+
setCurrentEditor,
|
|
52
|
+
setDocumentIsLocked,
|
|
53
|
+
unlockDocument,
|
|
54
|
+
updateDocumentEditor
|
|
48
55
|
} = useDocumentInfo();
|
|
49
|
-
const operation = id ?
|
|
56
|
+
const operation = id ? 'update' : 'create';
|
|
50
57
|
const {
|
|
51
|
-
config:
|
|
58
|
+
config: {
|
|
59
|
+
admin: {
|
|
60
|
+
user: userSlug
|
|
61
|
+
},
|
|
62
|
+
routes: {
|
|
63
|
+
admin: adminRoute
|
|
64
|
+
}
|
|
65
|
+
}
|
|
52
66
|
} = useConfig();
|
|
53
|
-
const
|
|
54
|
-
admin: t2
|
|
55
|
-
} = t1;
|
|
56
|
-
const {
|
|
57
|
-
user: userSlug
|
|
58
|
-
} = t2;
|
|
67
|
+
const router = useRouter();
|
|
59
68
|
const {
|
|
60
69
|
t
|
|
61
70
|
} = useTranslation();
|
|
@@ -69,193 +78,195 @@ const PreviewView = t0 => {
|
|
|
69
78
|
const {
|
|
70
79
|
reportUpdate
|
|
71
80
|
} = useDocumentEvents();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
const docConfig = collectionConfig || globalConfig;
|
|
82
|
+
const lockDocumentsProp = docConfig?.lockDocuments !== undefined ? docConfig?.lockDocuments : true;
|
|
83
|
+
const isLockingEnabled = lockDocumentsProp !== false;
|
|
84
|
+
const [isReadOnlyForIncomingUser, setIsReadOnlyForIncomingUser] = useState(false);
|
|
85
|
+
const [showTakeOverModal, setShowTakeOverModal] = useState(false);
|
|
86
|
+
const documentLockStateRef = useRef({
|
|
87
|
+
hasShownLockedModal: false,
|
|
88
|
+
isLocked: false,
|
|
89
|
+
user: null
|
|
90
|
+
});
|
|
91
|
+
const [lastUpdateTime, setLastUpdateTime] = useState(Date.now());
|
|
92
|
+
const onSave = useCallback(json => {
|
|
93
|
+
reportUpdate({
|
|
94
|
+
id,
|
|
95
|
+
entitySlug: collectionSlug,
|
|
96
|
+
updatedAt: json?.result?.updatedAt || new Date().toISOString()
|
|
97
|
+
});
|
|
98
|
+
// If we're editing the doc of the logged-in user,
|
|
99
|
+
// Refresh the cookie to get new permissions
|
|
100
|
+
if (user && collectionSlug === userSlug && id === user.id) {
|
|
101
|
+
void refreshCookieAsync();
|
|
102
|
+
}
|
|
103
|
+
// Unlock the document after save
|
|
104
|
+
if ((id || globalSlug) && isLockingEnabled) {
|
|
105
|
+
setDocumentIsLocked(false);
|
|
106
|
+
}
|
|
107
|
+
if (typeof onSaveFromProps === 'function') {
|
|
108
|
+
void onSaveFromProps({
|
|
109
|
+
...json,
|
|
110
|
+
operation: id ? 'update' : 'create'
|
|
79
111
|
});
|
|
80
|
-
|
|
81
|
-
|
|
112
|
+
}
|
|
113
|
+
}, [collectionSlug, globalSlug, id, isLockingEnabled, onSaveFromProps, refreshCookieAsync, reportUpdate, setDocumentIsLocked, user, userSlug]);
|
|
114
|
+
const onChange = useCallback(async ({
|
|
115
|
+
formState: prevFormState
|
|
116
|
+
}) => {
|
|
117
|
+
const currentTime = Date.now();
|
|
118
|
+
const timeSinceLastUpdate = currentTime - lastUpdateTime;
|
|
119
|
+
const updateLastEdited = isLockingEnabled && timeSinceLastUpdate >= 10000 // 10 seconds
|
|
120
|
+
;
|
|
121
|
+
if (updateLastEdited) {
|
|
122
|
+
setLastUpdateTime(currentTime);
|
|
123
|
+
}
|
|
124
|
+
const docPreferences = await getDocPreferences();
|
|
125
|
+
const {
|
|
126
|
+
lockedState,
|
|
127
|
+
state
|
|
128
|
+
} = await getFormState({
|
|
129
|
+
apiRoute,
|
|
130
|
+
body: {
|
|
131
|
+
id,
|
|
132
|
+
collectionSlug,
|
|
133
|
+
docPreferences,
|
|
134
|
+
formState: prevFormState,
|
|
135
|
+
globalSlug,
|
|
136
|
+
operation,
|
|
137
|
+
returnLockStatus: isLockingEnabled ? true : false,
|
|
138
|
+
schemaPath,
|
|
139
|
+
updateLastEdited
|
|
140
|
+
},
|
|
141
|
+
serverURL
|
|
142
|
+
});
|
|
143
|
+
setDocumentIsLocked(true);
|
|
144
|
+
if (isLockingEnabled) {
|
|
145
|
+
const previousOwnerId = documentLockStateRef.current?.user?.id;
|
|
146
|
+
if (lockedState) {
|
|
147
|
+
if (!documentLockStateRef.current || lockedState.user.id !== previousOwnerId) {
|
|
148
|
+
if (previousOwnerId === user.id && lockedState.user.id !== user.id) {
|
|
149
|
+
setShowTakeOverModal(true);
|
|
150
|
+
documentLockStateRef.current.hasShownLockedModal = true;
|
|
151
|
+
}
|
|
152
|
+
documentLockStateRef.current = documentLockStateRef.current = {
|
|
153
|
+
hasShownLockedModal: documentLockStateRef.current?.hasShownLockedModal || false,
|
|
154
|
+
isLocked: true,
|
|
155
|
+
user: lockedState.user
|
|
156
|
+
};
|
|
157
|
+
setCurrentEditor(lockedState.user);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return state;
|
|
162
|
+
}, [collectionSlug, globalSlug, serverURL, apiRoute, id, isLockingEnabled, lastUpdateTime, operation, schemaPath, getDocPreferences, setCurrentEditor, setDocumentIsLocked, user]);
|
|
163
|
+
// Clean up when the component unmounts or when the document is unlocked
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
return () => {
|
|
166
|
+
if (!isLockingEnabled) {
|
|
167
|
+
return;
|
|
82
168
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
169
|
+
const currentPath = window.location.pathname;
|
|
170
|
+
const documentId = id || globalSlug;
|
|
171
|
+
// Routes where we do NOT want to unlock the document
|
|
172
|
+
const stayWithinDocumentPaths = ['preview', 'api', 'versions'];
|
|
173
|
+
const isStayingWithinDocument = stayWithinDocumentPaths.some(path => currentPath.includes(path));
|
|
174
|
+
// Unlock the document only if we're actually navigating away from the document
|
|
175
|
+
if (documentId && documentIsLocked && !isStayingWithinDocument) {
|
|
176
|
+
// Check if this user is still the current editor
|
|
177
|
+
if (documentLockStateRef.current?.user?.id === user.id) {
|
|
178
|
+
void unlockDocument(id, collectionSlug ?? globalSlug);
|
|
179
|
+
setDocumentIsLocked(false);
|
|
180
|
+
setCurrentEditor(null);
|
|
181
|
+
}
|
|
88
182
|
}
|
|
183
|
+
setShowTakeOverModal(false);
|
|
89
184
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
docPreferences,
|
|
116
|
-
formState: prevFormState,
|
|
117
|
-
operation,
|
|
118
|
-
schemaPath
|
|
185
|
+
}, [collectionSlug, globalSlug, id, unlockDocument, user.id, setCurrentEditor, isLockingEnabled, documentIsLocked, setDocumentIsLocked]);
|
|
186
|
+
const shouldShowDocumentLockedModal = documentIsLocked && currentEditor && currentEditor.id !== user.id && !isReadOnlyForIncomingUser && !showTakeOverModal &&
|
|
187
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
188
|
+
!documentLockStateRef.current?.hasShownLockedModal;
|
|
189
|
+
return /*#__PURE__*/_jsx(OperationProvider, {
|
|
190
|
+
operation: operation,
|
|
191
|
+
children: /*#__PURE__*/_jsxs(Form, {
|
|
192
|
+
action: action,
|
|
193
|
+
className: `${baseClass}__form`,
|
|
194
|
+
disabled: isReadOnlyForIncomingUser || !hasSavePermission,
|
|
195
|
+
initialState: initialState,
|
|
196
|
+
isInitializing: isInitializing,
|
|
197
|
+
method: id ? 'PATCH' : 'POST',
|
|
198
|
+
onChange: [onChange],
|
|
199
|
+
onSuccess: onSave,
|
|
200
|
+
children: [isLockingEnabled && shouldShowDocumentLockedModal && !isReadOnlyForIncomingUser && /*#__PURE__*/_jsx(DocumentLocked, {
|
|
201
|
+
handleGoBack: () => handleGoBack({
|
|
202
|
+
adminRoute,
|
|
203
|
+
collectionSlug,
|
|
204
|
+
router
|
|
205
|
+
}),
|
|
206
|
+
isActive: shouldShowDocumentLockedModal,
|
|
207
|
+
onReadOnly: () => {
|
|
208
|
+
setIsReadOnlyForIncomingUser(true);
|
|
209
|
+
setShowTakeOverModal(false);
|
|
119
210
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const t12 = previewWindowType === "popup" && `${baseClass}--detached`;
|
|
176
|
-
let t13;
|
|
177
|
-
if ($[49] !== t12) {
|
|
178
|
-
t13 = [baseClass, t12].filter(Boolean);
|
|
179
|
-
$[49] = t12;
|
|
180
|
-
$[50] = t13;
|
|
181
|
-
} else {
|
|
182
|
-
t13 = $[50];
|
|
183
|
-
}
|
|
184
|
-
const t14 = t13.join(" ");
|
|
185
|
-
const t15 = previewWindowType === "popup" && `${baseClass}__main--popup-open`;
|
|
186
|
-
let t16;
|
|
187
|
-
if ($[51] !== t15) {
|
|
188
|
-
t16 = [`${baseClass}__main`, t15].filter(Boolean);
|
|
189
|
-
$[51] = t15;
|
|
190
|
-
$[52] = t16;
|
|
191
|
-
} else {
|
|
192
|
-
t16 = $[52];
|
|
193
|
-
}
|
|
194
|
-
t7 = _jsx(OperationProvider, {
|
|
195
|
-
operation,
|
|
196
|
-
children: _jsxs(Form, {
|
|
197
|
-
action,
|
|
198
|
-
className: `${baseClass}__form`,
|
|
199
|
-
disabled: t5,
|
|
200
|
-
initialState,
|
|
201
|
-
isInitializing,
|
|
202
|
-
method: t6,
|
|
203
|
-
onChange: [onChange],
|
|
204
|
-
onSuccess: onSave,
|
|
205
|
-
children: [t8, t9, t10, t11, _jsxs("div", {
|
|
206
|
-
className: t14,
|
|
207
|
-
children: [_jsxs("div", {
|
|
208
|
-
className: t16.join(" "),
|
|
209
|
-
children: [BeforeDocument, _jsx(DocumentFields, {
|
|
210
|
-
AfterFields,
|
|
211
|
-
BeforeFields,
|
|
212
|
-
docPermissions,
|
|
213
|
-
fields,
|
|
214
|
-
forceSidebarWrap: true,
|
|
215
|
-
readOnly: !hasSavePermission,
|
|
216
|
-
schemaPath: collectionSlug || globalSlug
|
|
217
|
-
}), AfterDocument]
|
|
218
|
-
}), _jsx(LivePreview, {
|
|
219
|
-
collectionSlug,
|
|
220
|
-
globalSlug
|
|
221
|
-
})]
|
|
211
|
+
onTakeOver: () => handleTakeOver(id, collectionSlug, globalSlug, user, false, updateDocumentEditor, setCurrentEditor, documentLockStateRef, isLockingEnabled),
|
|
212
|
+
updatedAt: lastUpdateTime,
|
|
213
|
+
user: currentEditor
|
|
214
|
+
}), isLockingEnabled && showTakeOverModal && /*#__PURE__*/_jsx(DocumentTakeOver, {
|
|
215
|
+
handleBackToDashboard: () => handleBackToDashboard({
|
|
216
|
+
adminRoute,
|
|
217
|
+
router
|
|
218
|
+
}),
|
|
219
|
+
isActive: showTakeOverModal,
|
|
220
|
+
onReadOnly: () => {
|
|
221
|
+
setIsReadOnlyForIncomingUser(true);
|
|
222
|
+
setShowTakeOverModal(false);
|
|
223
|
+
}
|
|
224
|
+
}), (collectionConfig && !(collectionConfig.versions?.drafts && collectionConfig.versions?.drafts?.autosave) || globalConfig && !(globalConfig.versions?.drafts && globalConfig.versions?.drafts?.autosave)) && !disableLeaveWithoutSaving && !isReadOnlyForIncomingUser && /*#__PURE__*/_jsx(LeaveWithoutSaving, {}), /*#__PURE__*/_jsx(SetDocumentStepNav, {
|
|
225
|
+
collectionSlug: collectionSlug,
|
|
226
|
+
globalLabel: globalConfig?.label,
|
|
227
|
+
globalSlug: globalSlug,
|
|
228
|
+
id: id,
|
|
229
|
+
pluralLabel: collectionConfig ? collectionConfig?.labels?.plural : undefined,
|
|
230
|
+
useAsTitle: collectionConfig ? collectionConfig?.admin?.useAsTitle : undefined,
|
|
231
|
+
view: t('general:livePreview')
|
|
232
|
+
}), /*#__PURE__*/_jsx(SetDocumentTitle, {
|
|
233
|
+
collectionConfig: collectionConfig,
|
|
234
|
+
config: config,
|
|
235
|
+
fallback: id?.toString() || '',
|
|
236
|
+
globalConfig: globalConfig
|
|
237
|
+
}), /*#__PURE__*/_jsx(DocumentControls, {
|
|
238
|
+
apiURL: apiURL,
|
|
239
|
+
data: initialData,
|
|
240
|
+
disableActions: disableActions,
|
|
241
|
+
hasPublishPermission: hasPublishPermission,
|
|
242
|
+
hasSavePermission: hasSavePermission,
|
|
243
|
+
id: id,
|
|
244
|
+
isEditing: isEditing,
|
|
245
|
+
onTakeOver: () => handleTakeOver(id, collectionSlug, globalSlug, user, true, updateDocumentEditor, setCurrentEditor, documentLockStateRef, isLockingEnabled, setIsReadOnlyForIncomingUser),
|
|
246
|
+
permissions: docPermissions,
|
|
247
|
+
readOnlyForIncomingUser: isReadOnlyForIncomingUser,
|
|
248
|
+
slug: collectionConfig?.slug || globalConfig?.slug,
|
|
249
|
+
user: currentEditor
|
|
250
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
251
|
+
className: [baseClass, previewWindowType === 'popup' && `${baseClass}--detached`].filter(Boolean).join(' '),
|
|
252
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
253
|
+
className: [`${baseClass}__main`, previewWindowType === 'popup' && `${baseClass}__main--popup-open`].filter(Boolean).join(' '),
|
|
254
|
+
children: [BeforeDocument, /*#__PURE__*/_jsx(DocumentFields, {
|
|
255
|
+
AfterFields: AfterFields,
|
|
256
|
+
BeforeFields: BeforeFields,
|
|
257
|
+
docPermissions: docPermissions,
|
|
258
|
+
fields: fields,
|
|
259
|
+
forceSidebarWrap: true,
|
|
260
|
+
readOnly: isReadOnlyForIncomingUser || !hasSavePermission,
|
|
261
|
+
schemaPath: collectionSlug || globalSlug
|
|
262
|
+
}), AfterDocument]
|
|
263
|
+
}), /*#__PURE__*/_jsx(LivePreview, {
|
|
264
|
+
collectionSlug: collectionSlug,
|
|
265
|
+
globalSlug: globalSlug
|
|
222
266
|
})]
|
|
223
|
-
})
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
$[16] = collectionConfig;
|
|
227
|
-
$[17] = globalConfig;
|
|
228
|
-
$[18] = disableLeaveWithoutSaving;
|
|
229
|
-
$[19] = t;
|
|
230
|
-
$[20] = collectionSlug;
|
|
231
|
-
$[21] = globalSlug;
|
|
232
|
-
$[22] = id;
|
|
233
|
-
$[23] = config;
|
|
234
|
-
$[24] = apiURL;
|
|
235
|
-
$[25] = initialData;
|
|
236
|
-
$[26] = disableActions;
|
|
237
|
-
$[27] = hasPublishPermission;
|
|
238
|
-
$[28] = hasSavePermission;
|
|
239
|
-
$[29] = isEditing;
|
|
240
|
-
$[30] = docPermissions;
|
|
241
|
-
$[31] = previewWindowType;
|
|
242
|
-
$[32] = AfterFields;
|
|
243
|
-
$[33] = BeforeFields;
|
|
244
|
-
$[34] = fields;
|
|
245
|
-
$[35] = BeforeDocument;
|
|
246
|
-
$[36] = AfterDocument;
|
|
247
|
-
$[37] = action;
|
|
248
|
-
$[38] = t5;
|
|
249
|
-
$[39] = initialState;
|
|
250
|
-
$[40] = isInitializing;
|
|
251
|
-
$[41] = t6;
|
|
252
|
-
$[42] = onSave;
|
|
253
|
-
$[43] = operation;
|
|
254
|
-
$[44] = t7;
|
|
255
|
-
} else {
|
|
256
|
-
t7 = $[44];
|
|
257
|
-
}
|
|
258
|
-
return t7;
|
|
267
|
+
})]
|
|
268
|
+
})
|
|
269
|
+
});
|
|
259
270
|
};
|
|
260
271
|
export const LivePreviewClient = props => {
|
|
261
272
|
const $ = _c(14);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.js","names":["c","_c","DocumentControls","DocumentFields","Form","OperationProvider","SetViewActions","useAuth","useConfig","useDocumentEvents","useDocumentInfo","useTranslation","getFormState","React","Fragment","useCallback","LeaveWithoutSaving","SetDocumentStepNav","SetDocumentTitle","useLivePreviewContext","LivePreviewProvider","LivePreview","usePopupWindow","baseClass","PreviewView","t0","$","apiRoute","collectionConfig","config","fields","globalConfig","schemaPath","serverURL","id","action","AfterDocument","AfterFields","apiURL","BeforeDocument","BeforeFields","collectionSlug","disableActions","disableLeaveWithoutSaving","docPermissions","getDocPreferences","globalSlug","hasPublishPermission","hasSavePermission","initialData","initialState","isEditing","isInitializing","onSave","onSaveFromProps","operation","t1","admin","t2","user","userSlug","t","previewWindowType","refreshCookieAsync","reportUpdate","t3","json","entitySlug","updatedAt","result","Date","toISOString","t4","t5","formState","prevFormState","docPreferences","state","body","onChange","t6","t7","t8","versions","drafts","autosave","_jsx","t9","globalLabel","label","pluralLabel","labels","plural","undefined","useAsTitle","view","t10","fallback","toString","t11","data","permissions","slug","t12","t13","filter","Boolean","t14","join","t15","t16","children","_jsxs","className","disabled","method","onSuccess","forceSidebarWrap","readOnly","LivePreviewClient","props","breakpoints","url","getEntityConfig","routes","api","eventType","isPopupOpen","openPopupWindow","popupRef","actions","components","views","edit","livePreview","fieldSchema"],"sources":["../../../src/views/LivePreview/index.client.tsx"],"sourcesContent":["'use client'\nimport type { FormProps } from '@payloadcms/ui'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientField,\n ClientGlobalConfig,\n Data,\n LivePreviewConfig,\n} from 'payload'\n\nimport {\n DocumentControls,\n DocumentFields,\n Form,\n OperationProvider,\n SetViewActions,\n useAuth,\n useConfig,\n useDocumentEvents,\n useDocumentInfo,\n useTranslation,\n} from '@payloadcms/ui'\nimport { getFormState } from '@payloadcms/ui/shared'\nimport React, { Fragment, useCallback } from 'react'\n\nimport { LeaveWithoutSaving } from '../../elements/LeaveWithoutSaving/index.js'\nimport { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js'\nimport { SetDocumentTitle } from '../Edit/Default/SetDocumentTitle/index.js'\nimport { useLivePreviewContext } from './Context/context.js'\nimport { LivePreviewProvider } from './Context/index.js'\nimport './index.scss'\nimport { LivePreview } from './Preview/index.js'\nimport { usePopupWindow } from './usePopupWindow.js'\n\nconst baseClass = 'live-preview'\n\ntype Props = {\n readonly apiRoute: string\n readonly collectionConfig?: ClientCollectionConfig\n readonly config: ClientConfig\n readonly fields: ClientField[]\n readonly globalConfig?: ClientGlobalConfig\n readonly schemaPath: string\n readonly serverURL: string\n}\n\nconst PreviewView: React.FC<Props> = ({\n apiRoute,\n collectionConfig,\n config,\n fields,\n globalConfig,\n schemaPath,\n serverURL,\n}) => {\n const {\n id,\n action,\n AfterDocument,\n AfterFields,\n apiURL,\n BeforeDocument,\n BeforeFields,\n collectionSlug,\n disableActions,\n disableLeaveWithoutSaving,\n docPermissions,\n getDocPreferences,\n globalSlug,\n hasPublishPermission,\n hasSavePermission,\n initialData,\n initialState,\n isEditing,\n isInitializing,\n onSave: onSaveFromProps,\n } = useDocumentInfo()\n\n const operation = id ? 'update' : 'create'\n\n const {\n config: {\n admin: { user: userSlug },\n },\n } = useConfig()\n const { t } = useTranslation()\n const { previewWindowType } = useLivePreviewContext()\n const { refreshCookieAsync, user } = useAuth()\n const { reportUpdate } = useDocumentEvents()\n\n const onSave = useCallback(\n (json) => {\n reportUpdate({\n id,\n entitySlug: collectionSlug,\n updatedAt: json?.result?.updatedAt || new Date().toISOString(),\n })\n\n // If we're editing the doc of the logged-in user,\n // Refresh the cookie to get new permissions\n if (user && collectionSlug === userSlug && id === user.id) {\n void refreshCookieAsync()\n }\n\n if (typeof onSaveFromProps === 'function') {\n void onSaveFromProps({\n ...json,\n operation: id ? 'update' : 'create',\n })\n }\n },\n [collectionSlug, id, onSaveFromProps, refreshCookieAsync, reportUpdate, user, userSlug],\n )\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const docPreferences = await getDocPreferences()\n\n const { state } = await getFormState({\n apiRoute,\n body: {\n id,\n docPreferences,\n formState: prevFormState,\n operation,\n schemaPath,\n },\n serverURL,\n })\n\n return state\n },\n [serverURL, apiRoute, id, operation, schemaPath, getDocPreferences],\n )\n\n return (\n <OperationProvider operation={operation}>\n <Form\n action={action}\n className={`${baseClass}__form`}\n disabled={!hasSavePermission}\n initialState={initialState}\n isInitializing={isInitializing}\n method={id ? 'PATCH' : 'POST'}\n onChange={[onChange]}\n onSuccess={onSave}\n >\n {((collectionConfig &&\n !(collectionConfig.versions?.drafts && collectionConfig.versions?.drafts?.autosave)) ||\n (globalConfig &&\n !(globalConfig.versions?.drafts && globalConfig.versions?.drafts?.autosave))) &&\n !disableLeaveWithoutSaving && <LeaveWithoutSaving />}\n <SetDocumentStepNav\n collectionSlug={collectionSlug}\n globalLabel={globalConfig?.label}\n globalSlug={globalSlug}\n id={id}\n pluralLabel={collectionConfig ? collectionConfig?.labels?.plural : undefined}\n useAsTitle={collectionConfig ? collectionConfig?.admin?.useAsTitle : undefined}\n view={t('general:livePreview')}\n />\n <SetDocumentTitle\n collectionConfig={collectionConfig}\n config={config}\n fallback={id?.toString() || ''}\n globalConfig={globalConfig}\n />\n <DocumentControls\n apiURL={apiURL}\n data={initialData}\n disableActions={disableActions}\n hasPublishPermission={hasPublishPermission}\n hasSavePermission={hasSavePermission}\n id={id}\n isEditing={isEditing}\n permissions={docPermissions}\n slug={collectionConfig?.slug || globalConfig?.slug}\n />\n <div\n className={[baseClass, previewWindowType === 'popup' && `${baseClass}--detached`]\n .filter(Boolean)\n .join(' ')}\n >\n <div\n className={[\n `${baseClass}__main`,\n previewWindowType === 'popup' && `${baseClass}__main--popup-open`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {BeforeDocument}\n <DocumentFields\n AfterFields={AfterFields}\n BeforeFields={BeforeFields}\n docPermissions={docPermissions}\n fields={fields}\n forceSidebarWrap\n readOnly={!hasSavePermission}\n schemaPath={collectionSlug || globalSlug}\n />\n {AfterDocument}\n </div>\n <LivePreview collectionSlug={collectionSlug} globalSlug={globalSlug} />\n </div>\n </Form>\n </OperationProvider>\n )\n}\n\nexport const LivePreviewClient: React.FC<{\n readonly breakpoints: LivePreviewConfig['breakpoints']\n readonly initialData: Data\n readonly url: string\n}> = (props) => {\n const { breakpoints, url } = props\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const {\n config,\n config: {\n routes: { api: apiRoute },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const collectionConfig = getEntityConfig({ collectionSlug }) as ClientCollectionConfig\n\n const globalConfig = getEntityConfig({ globalSlug }) as ClientGlobalConfig\n\n const schemaPath = collectionSlug || globalSlug\n\n return (\n <Fragment>\n <SetViewActions\n actions={\n (collectionConfig || globalConfig)?.admin?.components?.views?.edit?.livePreview?.actions\n }\n />\n <LivePreviewProvider\n breakpoints={breakpoints}\n fieldSchema={collectionConfig?.fields || globalConfig?.fields}\n isPopupOpen={isPopupOpen}\n openPopupWindow={openPopupWindow}\n popupRef={popupRef}\n url={url}\n >\n <PreviewView\n apiRoute={apiRoute}\n collectionConfig={collectionConfig}\n config={config}\n fields={(collectionConfig || globalConfig)?.fields}\n globalConfig={globalConfig}\n schemaPath={schemaPath}\n serverURL={serverURL}\n />\n </LivePreviewProvider>\n </Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAWA,SACEC,gBAAgB,EAChBC,cAAc,EACdC,IAAI,EACJC,iBAAiB,EACjBC,cAAc,EACdC,OAAO,EACPC,SAAS,EACTC,iBAAiB,EACjBC,eAAe,EACfC,cAAc,QACT;AACP,SAASC,YAAY,QAAQ;AAC7B,OAAOC,KAAA,IAASC,QAAQ,EAAEC,WAAW,QAAQ;AAE7C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,mBAAmB,QAAQ;AAEpC,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAE/B,MAAMC,SAAA,GAAY;AAYlB,MAAMC,WAAA,GAA+BC,EAAA;EAAA,MAAAC,CAAA,GAAAzB,EAAA;EAAC;IAAA0B,QAAA;IAAAC,gBAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,YAAA;IAAAC,UAAA;IAAAC;EAAA,IAAAR,EAQrC;EACC;IAAAS,EAAA;IAAAC,MAAA;IAAAC,aAAA;IAAAC,WAAA;IAAAC,MAAA;IAAAC,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,mBAAA;QAAAqG,WAAA;QAAAc,WAAA,EAEe3G,gBAAA,EAAAE,MAAA,IAA4BC,YAAA,EAAAD,MAAc;QAAAiG,WAAA;QAAAC,eAAA;QAAAC,QAAA;QAAAP,GAAA;QAAAX,QAAA,EAMvDzB,IAAA,CAAA9D,WAAA;UAAAG,QAAA;UAAAC,gBAAA;UAAAC,MAAA;UAAAC,MAAA,GAIWF,gBAAA,IAAoBG,YAAW,GAAAD,MAAA;UAAAC,YAAA;UAAAC,UAAA;UAAAC;QAAA,C;;;;;;;;;;;;;;;;;;SAlB9CgC,E;CA0BJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.client.js","names":["c","_c","DocumentControls","DocumentFields","Form","OperationProvider","SetViewActions","useAuth","useConfig","useDocumentEvents","useDocumentInfo","useTranslation","getFormState","handleBackToDashboard","handleGoBack","handleTakeOver","useRouter","React","Fragment","useCallback","useEffect","useRef","useState","DocumentLocked","DocumentTakeOver","LeaveWithoutSaving","SetDocumentStepNav","SetDocumentTitle","useLivePreviewContext","LivePreviewProvider","LivePreview","usePopupWindow","baseClass","PreviewView","apiRoute","collectionConfig","config","fields","globalConfig","schemaPath","serverURL","id","action","AfterDocument","AfterFields","apiURL","BeforeDocument","BeforeFields","collectionSlug","currentEditor","disableActions","disableLeaveWithoutSaving","docPermissions","documentIsLocked","getDocPreferences","globalSlug","hasPublishPermission","hasSavePermission","initialData","initialState","isEditing","isInitializing","onSave","onSaveFromProps","setCurrentEditor","setDocumentIsLocked","unlockDocument","updateDocumentEditor","operation","admin","user","userSlug","routes","adminRoute","router","t","previewWindowType","refreshCookieAsync","reportUpdate","docConfig","lockDocumentsProp","lockDocuments","undefined","isLockingEnabled","isReadOnlyForIncomingUser","setIsReadOnlyForIncomingUser","showTakeOverModal","setShowTakeOverModal","documentLockStateRef","hasShownLockedModal","isLocked","lastUpdateTime","setLastUpdateTime","Date","now","json","entitySlug","updatedAt","result","toISOString","onChange","formState","prevFormState","currentTime","timeSinceLastUpdate","updateLastEdited","docPreferences","lockedState","state","body","returnLockStatus","previousOwnerId","current","currentPath","window","location","pathname","documentId","stayWithinDocumentPaths","isStayingWithinDocument","some","path","includes","shouldShowDocumentLockedModal","_jsx","_jsxs","className","disabled","method","onSuccess","isActive","onReadOnly","onTakeOver","versions","drafts","autosave","globalLabel","label","pluralLabel","labels","plural","useAsTitle","view","fallback","toString","data","permissions","readOnlyForIncomingUser","slug","filter","Boolean","join","forceSidebarWrap","readOnly","LivePreviewClient","props","$","breakpoints","url","t0","getEntityConfig","t1","api","t2","eventType","isPopupOpen","openPopupWindow","popupRef","t3","children","actions","components","views","edit","livePreview","fieldSchema"],"sources":["../../../src/views/LivePreview/index.client.tsx"],"sourcesContent":["'use client'\nimport type { FormProps } from '@payloadcms/ui'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientField,\n ClientGlobalConfig,\n ClientUser,\n Data,\n LivePreviewConfig,\n} from 'payload'\n\nimport {\n DocumentControls,\n DocumentFields,\n Form,\n OperationProvider,\n SetViewActions,\n useAuth,\n useConfig,\n useDocumentEvents,\n useDocumentInfo,\n useTranslation,\n} from '@payloadcms/ui'\nimport {\n getFormState,\n handleBackToDashboard,\n handleGoBack,\n handleTakeOver,\n} from '@payloadcms/ui/shared'\nimport { useRouter } from 'next/navigation.js'\nimport React, { Fragment, useCallback, useEffect, useRef, useState } from 'react'\n\nimport { DocumentLocked } from '../../elements/DocumentLocked/index.js'\nimport { DocumentTakeOver } from '../../elements/DocumentTakeOver/index.js'\nimport { LeaveWithoutSaving } from '../../elements/LeaveWithoutSaving/index.js'\nimport { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js'\nimport { SetDocumentTitle } from '../Edit/Default/SetDocumentTitle/index.js'\nimport { useLivePreviewContext } from './Context/context.js'\nimport { LivePreviewProvider } from './Context/index.js'\nimport './index.scss'\nimport { LivePreview } from './Preview/index.js'\nimport { usePopupWindow } from './usePopupWindow.js'\n\nconst baseClass = 'live-preview'\n\ntype Props = {\n readonly apiRoute: string\n readonly collectionConfig?: ClientCollectionConfig\n readonly config: ClientConfig\n readonly fields: ClientField[]\n readonly globalConfig?: ClientGlobalConfig\n readonly schemaPath: string\n readonly serverURL: string\n}\n\nconst PreviewView: React.FC<Props> = ({\n apiRoute,\n collectionConfig,\n config,\n fields,\n globalConfig,\n schemaPath,\n serverURL,\n}) => {\n const {\n id,\n action,\n AfterDocument,\n AfterFields,\n apiURL,\n BeforeDocument,\n BeforeFields,\n collectionSlug,\n currentEditor,\n disableActions,\n disableLeaveWithoutSaving,\n docPermissions,\n documentIsLocked,\n getDocPreferences,\n globalSlug,\n hasPublishPermission,\n hasSavePermission,\n initialData,\n initialState,\n isEditing,\n isInitializing,\n onSave: onSaveFromProps,\n setCurrentEditor,\n setDocumentIsLocked,\n unlockDocument,\n updateDocumentEditor,\n } = useDocumentInfo()\n\n const operation = id ? 'update' : 'create'\n\n const {\n config: {\n admin: { user: userSlug },\n routes: { admin: adminRoute },\n },\n } = useConfig()\n const router = useRouter()\n const { t } = useTranslation()\n const { previewWindowType } = useLivePreviewContext()\n const { refreshCookieAsync, user } = useAuth()\n const { reportUpdate } = useDocumentEvents()\n\n const docConfig = collectionConfig || globalConfig\n\n const lockDocumentsProp = docConfig?.lockDocuments !== undefined ? docConfig?.lockDocuments : true\n\n const isLockingEnabled = lockDocumentsProp !== false\n\n const [isReadOnlyForIncomingUser, setIsReadOnlyForIncomingUser] = useState(false)\n const [showTakeOverModal, setShowTakeOverModal] = useState(false)\n\n const documentLockStateRef = useRef<{\n hasShownLockedModal: boolean\n isLocked: boolean\n user: ClientUser\n } | null>({\n hasShownLockedModal: false,\n isLocked: false,\n user: null,\n })\n\n const [lastUpdateTime, setLastUpdateTime] = useState(Date.now())\n\n const onSave = useCallback(\n (json) => {\n reportUpdate({\n id,\n entitySlug: collectionSlug,\n updatedAt: json?.result?.updatedAt || new Date().toISOString(),\n })\n\n // If we're editing the doc of the logged-in user,\n // Refresh the cookie to get new permissions\n if (user && collectionSlug === userSlug && id === user.id) {\n void refreshCookieAsync()\n }\n\n // Unlock the document after save\n if ((id || globalSlug) && isLockingEnabled) {\n setDocumentIsLocked(false)\n }\n\n if (typeof onSaveFromProps === 'function') {\n void onSaveFromProps({\n ...json,\n operation: id ? 'update' : 'create',\n })\n }\n },\n [\n collectionSlug,\n globalSlug,\n id,\n isLockingEnabled,\n onSaveFromProps,\n refreshCookieAsync,\n reportUpdate,\n setDocumentIsLocked,\n user,\n userSlug,\n ],\n )\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const currentTime = Date.now()\n const timeSinceLastUpdate = currentTime - lastUpdateTime\n\n const updateLastEdited = isLockingEnabled && timeSinceLastUpdate >= 10000 // 10 seconds\n\n if (updateLastEdited) {\n setLastUpdateTime(currentTime)\n }\n\n const docPreferences = await getDocPreferences()\n\n const { lockedState, state } = await getFormState({\n apiRoute,\n body: {\n id,\n collectionSlug,\n docPreferences,\n formState: prevFormState,\n globalSlug,\n operation,\n returnLockStatus: isLockingEnabled ? true : false,\n schemaPath,\n updateLastEdited,\n },\n serverURL,\n })\n\n setDocumentIsLocked(true)\n\n if (isLockingEnabled) {\n const previousOwnerId = documentLockStateRef.current?.user?.id\n\n if (lockedState) {\n if (!documentLockStateRef.current || lockedState.user.id !== previousOwnerId) {\n if (previousOwnerId === user.id && lockedState.user.id !== user.id) {\n setShowTakeOverModal(true)\n documentLockStateRef.current.hasShownLockedModal = true\n }\n\n documentLockStateRef.current = documentLockStateRef.current = {\n hasShownLockedModal: documentLockStateRef.current?.hasShownLockedModal || false,\n isLocked: true,\n user: lockedState.user,\n }\n setCurrentEditor(lockedState.user)\n }\n }\n }\n\n return state\n },\n [\n collectionSlug,\n globalSlug,\n serverURL,\n apiRoute,\n id,\n isLockingEnabled,\n lastUpdateTime,\n operation,\n schemaPath,\n getDocPreferences,\n setCurrentEditor,\n setDocumentIsLocked,\n user,\n ],\n )\n\n // Clean up when the component unmounts or when the document is unlocked\n useEffect(() => {\n return () => {\n if (!isLockingEnabled) {\n return\n }\n\n const currentPath = window.location.pathname\n\n const documentId = id || globalSlug\n\n // Routes where we do NOT want to unlock the document\n const stayWithinDocumentPaths = ['preview', 'api', 'versions']\n\n const isStayingWithinDocument = stayWithinDocumentPaths.some((path) =>\n currentPath.includes(path),\n )\n\n // Unlock the document only if we're actually navigating away from the document\n if (documentId && documentIsLocked && !isStayingWithinDocument) {\n // Check if this user is still the current editor\n if (documentLockStateRef.current?.user?.id === user.id) {\n void unlockDocument(id, collectionSlug ?? globalSlug)\n setDocumentIsLocked(false)\n setCurrentEditor(null)\n }\n }\n\n setShowTakeOverModal(false)\n }\n }, [\n collectionSlug,\n globalSlug,\n id,\n unlockDocument,\n user.id,\n setCurrentEditor,\n isLockingEnabled,\n documentIsLocked,\n setDocumentIsLocked,\n ])\n\n const shouldShowDocumentLockedModal =\n documentIsLocked &&\n currentEditor &&\n currentEditor.id !== user.id &&\n !isReadOnlyForIncomingUser &&\n !showTakeOverModal &&\n // eslint-disable-next-line react-compiler/react-compiler\n !documentLockStateRef.current?.hasShownLockedModal\n\n return (\n <OperationProvider operation={operation}>\n <Form\n action={action}\n className={`${baseClass}__form`}\n disabled={isReadOnlyForIncomingUser || !hasSavePermission}\n initialState={initialState}\n isInitializing={isInitializing}\n method={id ? 'PATCH' : 'POST'}\n onChange={[onChange]}\n onSuccess={onSave}\n >\n {isLockingEnabled && shouldShowDocumentLockedModal && !isReadOnlyForIncomingUser && (\n <DocumentLocked\n handleGoBack={() => handleGoBack({ adminRoute, collectionSlug, router })}\n isActive={shouldShowDocumentLockedModal}\n onReadOnly={() => {\n setIsReadOnlyForIncomingUser(true)\n setShowTakeOverModal(false)\n }}\n onTakeOver={() =>\n handleTakeOver(\n id,\n collectionSlug,\n globalSlug,\n user,\n false,\n updateDocumentEditor,\n setCurrentEditor,\n documentLockStateRef,\n isLockingEnabled,\n )\n }\n updatedAt={lastUpdateTime}\n user={currentEditor}\n />\n )}\n {isLockingEnabled && showTakeOverModal && (\n <DocumentTakeOver\n handleBackToDashboard={() => handleBackToDashboard({ adminRoute, router })}\n isActive={showTakeOverModal}\n onReadOnly={() => {\n setIsReadOnlyForIncomingUser(true)\n setShowTakeOverModal(false)\n }}\n />\n )}\n {((collectionConfig &&\n !(collectionConfig.versions?.drafts && collectionConfig.versions?.drafts?.autosave)) ||\n (globalConfig &&\n !(globalConfig.versions?.drafts && globalConfig.versions?.drafts?.autosave))) &&\n !disableLeaveWithoutSaving &&\n !isReadOnlyForIncomingUser && <LeaveWithoutSaving />}\n <SetDocumentStepNav\n collectionSlug={collectionSlug}\n globalLabel={globalConfig?.label}\n globalSlug={globalSlug}\n id={id}\n pluralLabel={collectionConfig ? collectionConfig?.labels?.plural : undefined}\n useAsTitle={collectionConfig ? collectionConfig?.admin?.useAsTitle : undefined}\n view={t('general:livePreview')}\n />\n <SetDocumentTitle\n collectionConfig={collectionConfig}\n config={config}\n fallback={id?.toString() || ''}\n globalConfig={globalConfig}\n />\n <DocumentControls\n apiURL={apiURL}\n data={initialData}\n disableActions={disableActions}\n hasPublishPermission={hasPublishPermission}\n hasSavePermission={hasSavePermission}\n id={id}\n isEditing={isEditing}\n onTakeOver={() =>\n handleTakeOver(\n id,\n collectionSlug,\n globalSlug,\n user,\n true,\n updateDocumentEditor,\n setCurrentEditor,\n documentLockStateRef,\n isLockingEnabled,\n setIsReadOnlyForIncomingUser,\n )\n }\n permissions={docPermissions}\n readOnlyForIncomingUser={isReadOnlyForIncomingUser}\n slug={collectionConfig?.slug || globalConfig?.slug}\n user={currentEditor}\n />\n <div\n className={[baseClass, previewWindowType === 'popup' && `${baseClass}--detached`]\n .filter(Boolean)\n .join(' ')}\n >\n <div\n className={[\n `${baseClass}__main`,\n previewWindowType === 'popup' && `${baseClass}__main--popup-open`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {BeforeDocument}\n <DocumentFields\n AfterFields={AfterFields}\n BeforeFields={BeforeFields}\n docPermissions={docPermissions}\n fields={fields}\n forceSidebarWrap\n readOnly={isReadOnlyForIncomingUser || !hasSavePermission}\n schemaPath={collectionSlug || globalSlug}\n />\n {AfterDocument}\n </div>\n <LivePreview collectionSlug={collectionSlug} globalSlug={globalSlug} />\n </div>\n </Form>\n </OperationProvider>\n )\n}\n\nexport const LivePreviewClient: React.FC<{\n readonly breakpoints: LivePreviewConfig['breakpoints']\n readonly initialData: Data\n readonly url: string\n}> = (props) => {\n const { breakpoints, url } = props\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const {\n config,\n config: {\n routes: { api: apiRoute },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const collectionConfig = getEntityConfig({ collectionSlug }) as ClientCollectionConfig\n\n const globalConfig = getEntityConfig({ globalSlug }) as ClientGlobalConfig\n\n const schemaPath = collectionSlug || globalSlug\n\n return (\n <Fragment>\n <SetViewActions\n actions={\n (collectionConfig || globalConfig)?.admin?.components?.views?.edit?.livePreview?.actions\n }\n />\n <LivePreviewProvider\n breakpoints={breakpoints}\n fieldSchema={collectionConfig?.fields || globalConfig?.fields}\n isPopupOpen={isPopupOpen}\n openPopupWindow={openPopupWindow}\n popupRef={popupRef}\n url={url}\n >\n <PreviewView\n apiRoute={apiRoute}\n collectionConfig={collectionConfig}\n config={config}\n fields={(collectionConfig || globalConfig)?.fields}\n globalConfig={globalConfig}\n schemaPath={schemaPath}\n serverURL={serverURL}\n />\n </LivePreviewProvider>\n </Fragment>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAYA,SACEC,gBAAgB,EAChBC,cAAc,EACdC,IAAI,EACJC,iBAAiB,EACjBC,cAAc,EACdC,OAAO,EACPC,SAAS,EACTC,iBAAiB,EACjBC,eAAe,EACfC,cAAc,QACT;AACP,SACEC,YAAY,EACZC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,QACT;AACP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A;QAAAC,eAAA;QAAAC,QAAA;QAAAT,GAAA;QAAAW,QAAA,EAMvD7C,IAAA,CAAA3F,WAAA;UAAAC,QAAA;UAAAC,gBAAA;UAAAC,MAAA;UAAAC,MAAA,GAIWF,gBAAA,IAAoBG,YAAW,GAAAD,MAAA;UAAAC,YAAA;UAAAC,UAAA;UAAAC;QAAA,C;;;;;;;;;;;;;;;;;;SAlB9CgI,E;CA0BJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/Restore/index.tsx"],"names":[],"mappings":"AAeA,OAAO,KAA0C,MAAM,OAAO,CAAA;AAG9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,OAAO,cAAc,CAAA;AAKrB,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/Restore/index.tsx"],"names":[],"mappings":"AAeA,OAAO,KAA0C,MAAM,OAAO,CAAA;AAG9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,OAAO,cAAc,CAAA;AAKrB,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAiH5B,CAAA;AAED,eAAe,OAAO,CAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { getTranslation } from '@payloadcms/translations';
|
|
5
|
-
import { Button,
|
|
5
|
+
import { Button, Modal, PopupList, useConfig, useModal, useTranslation } from '@payloadcms/ui';
|
|
6
6
|
import { formatAdminURL, requests } from '@payloadcms/ui/shared';
|
|
7
7
|
import { useRouter } from 'next/navigation.js';
|
|
8
8
|
import React, { Fragment, useCallback, useState } from 'react';
|
|
@@ -77,27 +77,21 @@ const Restore = ({
|
|
|
77
77
|
}
|
|
78
78
|
}, [fetchURL, redirectURL, t, i18n, router]);
|
|
79
79
|
return /*#__PURE__*/_jsxs(Fragment, {
|
|
80
|
-
children: [/*#__PURE__*/
|
|
80
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
81
81
|
className: [baseClass, className].filter(Boolean).join(' '),
|
|
82
|
-
children:
|
|
82
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
83
|
+
buttonStyle: "pill",
|
|
83
84
|
className: [canRestoreAsDraft && `${baseClass}__button`].filter(Boolean).join(' '),
|
|
84
85
|
onClick: () => toggleModal(modalSlug),
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
button: /*#__PURE__*/_jsx(Pill, {
|
|
88
|
-
className: `${baseClass}__chevron`,
|
|
89
|
-
children: /*#__PURE__*/_jsx(ChevronIcon, {})
|
|
90
|
-
}),
|
|
91
|
-
caret: false,
|
|
92
|
-
render: () => /*#__PURE__*/_jsx(PopupList.ButtonGroup, {
|
|
86
|
+
size: "small",
|
|
87
|
+
SubMenuPopupContent: canRestoreAsDraft && /*#__PURE__*/_jsx(PopupList.ButtonGroup, {
|
|
93
88
|
children: /*#__PURE__*/_jsx(PopupList.Button, {
|
|
94
89
|
onClick: () => [setDraft(true), toggleModal(modalSlug)],
|
|
95
90
|
children: t('version:restoreAsDraft')
|
|
96
91
|
})
|
|
97
92
|
}),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
})]
|
|
93
|
+
children: t('version:restoreThisVersion')
|
|
94
|
+
})
|
|
101
95
|
}), /*#__PURE__*/_jsx(Modal, {
|
|
102
96
|
className: `${baseClass}__modal`,
|
|
103
97
|
slug: modalSlug,
|