@payloadcms/ui 3.0.0-canary.23fcb9e → 3.0.0-canary.294ea5c

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.
Files changed (140) hide show
  1. package/dist/elements/AddNewRelation/index.d.ts.map +1 -0
  2. package/dist/{fields/Relationship/AddNew → elements/AddNewRelation}/index.js +98 -82
  3. package/dist/elements/AddNewRelation/index.js.map +1 -0
  4. package/dist/elements/AddNewRelation/index.scss +42 -0
  5. package/dist/elements/AddNewRelation/types.d.ts +11 -0
  6. package/dist/elements/AddNewRelation/types.d.ts.map +1 -0
  7. package/dist/elements/AddNewRelation/types.js.map +1 -0
  8. package/dist/elements/AddNewRelation/useRelatedCollections.d.ts.map +1 -0
  9. package/dist/{fields/Relationship/AddNew → elements/AddNewRelation}/useRelatedCollections.js +1 -1
  10. package/dist/elements/AddNewRelation/useRelatedCollections.js.map +1 -0
  11. package/dist/elements/AppHeader/index.js +41 -80
  12. package/dist/elements/AppHeader/index.js.map +1 -1
  13. package/dist/elements/Autosave/index.js +148 -231
  14. package/dist/elements/Autosave/index.js.map +1 -1
  15. package/dist/elements/Button/index.js +86 -218
  16. package/dist/elements/Button/index.js.map +1 -1
  17. package/dist/elements/Collapsible/index.js +44 -62
  18. package/dist/elements/Collapsible/index.js.map +1 -1
  19. package/dist/elements/Collapsible/index.scss +15 -28
  20. package/dist/elements/CopyToClipboard/index.js +20 -54
  21. package/dist/elements/CopyToClipboard/index.js.map +1 -1
  22. package/dist/elements/DocumentDrawer/DrawerContent.js +1 -1
  23. package/dist/elements/DocumentDrawer/DrawerContent.js.map +1 -1
  24. package/dist/elements/DocumentDrawer/index.js +1 -1
  25. package/dist/elements/DocumentDrawer/index.js.map +1 -1
  26. package/dist/elements/Dropzone/index.js +59 -119
  27. package/dist/elements/Dropzone/index.js.map +1 -1
  28. package/dist/elements/EditMany/index.js +124 -230
  29. package/dist/elements/EditMany/index.js.map +1 -1
  30. package/dist/elements/EditUpload/index.js +133 -206
  31. package/dist/elements/EditUpload/index.js.map +1 -1
  32. package/dist/elements/FileDetails/DraggableFileDetails/index.d.ts +20 -0
  33. package/dist/elements/FileDetails/DraggableFileDetails/index.d.ts.map +1 -0
  34. package/dist/elements/FileDetails/DraggableFileDetails/index.js +116 -0
  35. package/dist/elements/FileDetails/DraggableFileDetails/index.js.map +1 -0
  36. package/dist/elements/FileDetails/DraggableFileDetails/index.scss +33 -0
  37. package/dist/elements/FileDetails/StaticFileDetails/index.d.ts +17 -0
  38. package/dist/elements/FileDetails/StaticFileDetails/index.d.ts.map +1 -0
  39. package/dist/elements/FileDetails/StaticFileDetails/index.js +71 -0
  40. package/dist/elements/FileDetails/StaticFileDetails/index.js.map +1 -0
  41. package/dist/elements/FileDetails/{index.scss → StaticFileDetails/index.scss} +1 -1
  42. package/dist/elements/FileDetails/index.d.ts +19 -4
  43. package/dist/elements/FileDetails/index.d.ts.map +1 -1
  44. package/dist/elements/FileDetails/index.js +11 -62
  45. package/dist/elements/FileDetails/index.js.map +1 -1
  46. package/dist/elements/ListControls/index.d.ts.map +1 -1
  47. package/dist/elements/ListControls/index.js +91 -192
  48. package/dist/elements/ListControls/index.js.map +1 -1
  49. package/dist/elements/ListDrawer/DrawerContent.d.ts.map +1 -1
  50. package/dist/elements/ListDrawer/DrawerContent.js +42 -31
  51. package/dist/elements/ListDrawer/DrawerContent.js.map +1 -1
  52. package/dist/elements/ListDrawer/index.d.ts.map +1 -1
  53. package/dist/elements/ListDrawer/index.js.map +1 -1
  54. package/dist/elements/ListDrawer/types.d.ts +4 -1
  55. package/dist/elements/ListDrawer/types.d.ts.map +1 -1
  56. package/dist/elements/ListDrawer/types.js.map +1 -1
  57. package/dist/elements/Nav/context.js +47 -83
  58. package/dist/elements/Nav/context.js.map +1 -1
  59. package/dist/elements/SaveButton/index.js +30 -81
  60. package/dist/elements/SaveButton/index.js.map +1 -1
  61. package/dist/elements/SaveDraftButton/index.js +54 -116
  62. package/dist/elements/SaveDraftButton/index.js.map +1 -1
  63. package/dist/elements/SearchFilter/index.js +21 -77
  64. package/dist/elements/SearchFilter/index.js.map +1 -1
  65. package/dist/elements/SelectMany/index.d.ts +6 -0
  66. package/dist/elements/SelectMany/index.d.ts.map +1 -0
  67. package/dist/elements/SelectMany/index.js +29 -0
  68. package/dist/elements/SelectMany/index.js.map +1 -0
  69. package/dist/elements/Upload/index.js +130 -280
  70. package/dist/elements/Upload/index.js.map +1 -1
  71. package/dist/exports/client/{CodeEditor-C4FLUUO7.js → CodeEditor-MTP455NO.js} +2 -2
  72. package/dist/exports/client/chunk-NJHSEGFB.js +14 -0
  73. package/dist/exports/client/{chunk-UGBVRIVY.js.map → chunk-NJHSEGFB.js.map} +2 -2
  74. package/dist/exports/client/index.d.ts +1 -1
  75. package/dist/exports/client/index.d.ts.map +1 -1
  76. package/dist/exports/client/index.js +13 -13
  77. package/dist/exports/client/index.js.map +4 -4
  78. package/dist/fields/Relationship/index.d.ts.map +1 -1
  79. package/dist/fields/Relationship/index.js +319 -507
  80. package/dist/fields/Relationship/index.js.map +1 -1
  81. package/dist/fields/Upload/HasMany/index.d.ts +4 -0
  82. package/dist/fields/Upload/HasMany/index.d.ts.map +1 -0
  83. package/dist/fields/Upload/HasMany/index.js +238 -0
  84. package/dist/fields/Upload/HasMany/index.js.map +1 -0
  85. package/dist/fields/Upload/HasMany/index.scss +71 -0
  86. package/dist/fields/Upload/{Input.d.ts → HasOne/Input.d.ts} +1 -1
  87. package/dist/fields/Upload/HasOne/Input.d.ts.map +1 -0
  88. package/dist/fields/Upload/{Input.js → HasOne/Input.js} +12 -12
  89. package/dist/fields/Upload/HasOne/Input.js.map +1 -0
  90. package/dist/fields/Upload/HasOne/index.d.ts +12 -0
  91. package/dist/fields/Upload/HasOne/index.d.ts.map +1 -0
  92. package/dist/fields/Upload/HasOne/index.js +131 -0
  93. package/dist/fields/Upload/HasOne/index.js.map +1 -0
  94. package/dist/fields/Upload/{index.scss → HasOne/index.scss} +1 -1
  95. package/dist/fields/Upload/index.d.ts +4 -4
  96. package/dist/fields/Upload/index.d.ts.map +1 -1
  97. package/dist/fields/Upload/index.js +84 -98
  98. package/dist/fields/Upload/index.js.map +1 -1
  99. package/dist/forms/Submit/index.js +12 -28
  100. package/dist/forms/Submit/index.js.map +1 -1
  101. package/dist/forms/buildStateFromSchema/addFieldStatePromise.d.ts.map +1 -1
  102. package/dist/forms/buildStateFromSchema/addFieldStatePromise.js +1 -27
  103. package/dist/forms/buildStateFromSchema/addFieldStatePromise.js.map +1 -1
  104. package/dist/hooks/useDelay.js +15 -48
  105. package/dist/hooks/useDelay.js.map +1 -1
  106. package/dist/hooks/useDelayedRender.js +32 -71
  107. package/dist/hooks/useDelayedRender.js.map +1 -1
  108. package/dist/hooks/useIntersect.js +14 -20
  109. package/dist/hooks/useIntersect.js.map +1 -1
  110. package/dist/providers/Config/createClientConfig/collections.d.ts.map +1 -1
  111. package/dist/providers/Config/createClientConfig/collections.js +8 -6
  112. package/dist/providers/Config/createClientConfig/collections.js.map +1 -1
  113. package/dist/providers/ListInfo/index.d.ts +6 -0
  114. package/dist/providers/ListInfo/index.d.ts.map +1 -1
  115. package/dist/providers/ListInfo/index.js.map +1 -1
  116. package/dist/providers/Preferences/index.js +1 -3
  117. package/dist/providers/Preferences/index.js.map +1 -1
  118. package/dist/providers/Selection/index.d.ts +5 -3
  119. package/dist/providers/Selection/index.d.ts.map +1 -1
  120. package/dist/providers/Selection/index.js +102 -190
  121. package/dist/providers/Selection/index.js.map +1 -1
  122. package/dist/scss/app.scss +6 -6
  123. package/dist/scss/type.scss +4 -4
  124. package/dist/styles.css +1 -1
  125. package/package.json +8 -8
  126. package/dist/exports/client/chunk-UGBVRIVY.js +0 -14
  127. package/dist/fields/Relationship/AddNew/index.d.ts.map +0 -1
  128. package/dist/fields/Relationship/AddNew/index.js.map +0 -1
  129. package/dist/fields/Relationship/AddNew/index.scss +0 -28
  130. package/dist/fields/Relationship/AddNew/types.d.ts +0 -12
  131. package/dist/fields/Relationship/AddNew/types.d.ts.map +0 -1
  132. package/dist/fields/Relationship/AddNew/types.js.map +0 -1
  133. package/dist/fields/Relationship/AddNew/useRelatedCollections.d.ts.map +0 -1
  134. package/dist/fields/Relationship/AddNew/useRelatedCollections.js.map +0 -1
  135. package/dist/fields/Upload/Input.d.ts.map +0 -1
  136. package/dist/fields/Upload/Input.js.map +0 -1
  137. /package/dist/{fields/Relationship/AddNew → elements/AddNewRelation}/index.d.ts +0 -0
  138. /package/dist/{fields/Relationship/AddNew → elements/AddNewRelation}/types.js +0 -0
  139. /package/dist/{fields/Relationship/AddNew → elements/AddNewRelation}/useRelatedCollections.d.ts +0 -0
  140. /package/dist/exports/client/{CodeEditor-C4FLUUO7.js.map → CodeEditor-MTP455NO.js.map} +0 -0
@@ -1,6 +1,5 @@
1
1
  'use client';
2
2
 
3
- import { c as _c } from "react/compiler-runtime";
4
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
4
  import { versionDefaults } from 'payload/shared';
6
5
  import React, { useEffect, useRef, useState } from 'react';
@@ -18,24 +17,20 @@ import './index.scss';
18
17
  const baseClass = 'autosave';
19
18
  // The minimum time the saving state should be shown
20
19
  const minimumAnimationTime = 1000;
21
- export const Autosave = t0 => {
22
- const $ = _c(45);
20
+ export const Autosave = ({
21
+ id,
22
+ collection,
23
+ global: globalDoc,
24
+ publishedDocUpdatedAt
25
+ }) => {
23
26
  const {
24
- id,
25
- collection,
26
- global: globalDoc,
27
- publishedDocUpdatedAt
28
- } = t0;
29
- const {
30
- config: t1
27
+ config: {
28
+ routes: {
29
+ api
30
+ },
31
+ serverURL
32
+ }
31
33
  } = useConfig();
32
- const {
33
- routes: t2,
34
- serverURL
35
- } = t1;
36
- const {
37
- api
38
- } = t2;
39
34
  const {
40
35
  docConfig,
41
36
  getVersions,
@@ -61,9 +56,7 @@ export const Autosave = t0 => {
61
56
  t
62
57
  } = useTranslation();
63
58
  let interval = versionDefaults.autosaveInterval;
64
- if (versionsConfig.drafts && versionsConfig.drafts.autosave) {
65
- interval = versionsConfig.drafts.autosave.interval;
66
- }
59
+ if (versionsConfig.drafts && versionsConfig.drafts.autosave) interval = versionsConfig.drafts.autosave.interval;
67
60
  const [saving, setSaving] = useState(false);
68
61
  const [lastSaved, setLastSaved] = useState();
69
62
  const debouncedFields = useDebounce(fields, interval);
@@ -73,230 +66,154 @@ export const Autosave = t0 => {
73
66
  const localeRef = useRef(locale);
74
67
  const debouncedRef = useRef(debouncedFields);
75
68
  debouncedRef.current = debouncedFields;
69
+ // Store fields in ref so the autosave func
70
+ // can always retrieve the most to date copies
71
+ // after the timeout has executed
76
72
  fieldRef.current = fields;
73
+ // Store modified in ref so the autosave func
74
+ // can bail out if modified becomes false while
75
+ // timing out during autosave
77
76
  modifiedRef.current = modified;
77
+ // Store locale in ref so the autosave func
78
+ // can always retrieve the most to date locale
78
79
  localeRef.current = locale;
79
- let t3;
80
- if ($[0] !== modified || $[1] !== collection || $[2] !== id || $[3] !== serverURL || $[4] !== api || $[5] !== globalDoc || $[6] !== submitted || $[7] !== versionsConfig || $[8] !== i18n || $[9] !== reportUpdate || $[10] !== setModified || $[11] !== getVersions || $[12] !== dispatchFields || $[13] !== setSubmitted) {
81
- t3 = () => {
82
- const abortController = new AbortController();
83
- let autosaveTimeout;
84
- autosaveTimeout = undefined;
85
- let startTimestamp;
86
- startTimestamp = undefined;
87
- let endTimestamp;
88
- endTimestamp = undefined;
89
- const autosave = () => {
90
- if (modified) {
91
- startTimestamp = new Date().getTime();
92
- setSaving(true);
93
- let url;
94
- let method;
95
- let entitySlug;
96
- if (collection && id) {
97
- entitySlug = collection.slug;
98
- url = `${serverURL}${api}/${entitySlug}/${id}?draft=true&autosave=true&locale=${localeRef.current}`;
99
- method = "PATCH";
100
- }
101
- if (globalDoc) {
102
- entitySlug = globalDoc.slug;
103
- url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`;
104
- method = "POST";
105
- }
106
- if (url) {
107
- if (modifiedRef.current) {
108
- const {
109
- data,
110
- valid
111
- } = {
112
- ...reduceFieldsToValuesWithValidation(fieldRef.current, true)
113
- };
114
- data._status = "draft";
115
- const skipSubmission = submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate;
116
- if (!skipSubmission) {
117
- fetch(url, {
118
- body: JSON.stringify(data),
119
- credentials: "include",
120
- headers: {
121
- "Accept-Language": i18n.language,
122
- "Content-Type": "application/json"
123
- },
124
- method,
125
- signal: abortController.signal
126
- }).then(res => {
127
- const newDate = new Date();
128
- endTimestamp = newDate.getTime();
129
- if (res.status === 200) {
130
- setLastSaved(newDate.getTime());
131
- reportUpdate({
132
- id,
133
- entitySlug,
134
- updatedAt: newDate.toISOString()
80
+ // When debounced fields change, autosave
81
+ useEffect(() => {
82
+ const abortController = new AbortController();
83
+ let autosaveTimeout = undefined;
84
+ // We need to log the time in order to figure out if we need to trigger the state off later
85
+ let startTimestamp = undefined;
86
+ let endTimestamp = undefined;
87
+ const autosave = () => {
88
+ if (modified) {
89
+ startTimestamp = new Date().getTime();
90
+ setSaving(true);
91
+ let url;
92
+ let method;
93
+ let entitySlug;
94
+ if (collection && id) {
95
+ entitySlug = collection.slug;
96
+ url = `${serverURL}${api}/${entitySlug}/${id}?draft=true&autosave=true&locale=${localeRef.current}`;
97
+ method = 'PATCH';
98
+ }
99
+ if (globalDoc) {
100
+ entitySlug = globalDoc.slug;
101
+ url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`;
102
+ method = 'POST';
103
+ }
104
+ if (url) {
105
+ if (modifiedRef.current) {
106
+ const {
107
+ data,
108
+ valid
109
+ } = {
110
+ ...reduceFieldsToValuesWithValidation(fieldRef.current, true)
111
+ };
112
+ data._status = 'draft';
113
+ const skipSubmission = submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate;
114
+ if (!skipSubmission) {
115
+ void fetch(url, {
116
+ body: JSON.stringify(data),
117
+ credentials: 'include',
118
+ headers: {
119
+ 'Accept-Language': i18n.language,
120
+ 'Content-Type': 'application/json'
121
+ },
122
+ method,
123
+ signal: abortController.signal
124
+ }).then(res => {
125
+ const newDate = new Date();
126
+ // We need to log the time in order to figure out if we need to trigger the state off later
127
+ endTimestamp = newDate.getTime();
128
+ if (res.status === 200) {
129
+ setLastSaved(newDate.getTime());
130
+ reportUpdate({
131
+ id,
132
+ entitySlug,
133
+ updatedAt: newDate.toISOString()
134
+ });
135
+ setModified(false);
136
+ void getVersions();
137
+ } else {
138
+ return res.json();
139
+ }
140
+ }).then(json => {
141
+ if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {
142
+ if (Array.isArray(json.errors)) {
143
+ const [fieldErrors, nonFieldErrors] = json.errors.reduce(([fieldErrs, nonFieldErrs], err) => {
144
+ const newFieldErrs = [];
145
+ const newNonFieldErrs = [];
146
+ if (err?.message) {
147
+ newNonFieldErrs.push(err);
148
+ }
149
+ if (Array.isArray(err?.data)) {
150
+ err.data.forEach(dataError => {
151
+ if (dataError?.field) {
152
+ newFieldErrs.push(dataError);
153
+ } else {
154
+ newNonFieldErrs.push(dataError);
155
+ }
156
+ });
157
+ }
158
+ return [[...fieldErrs, ...newFieldErrs], [...nonFieldErrs, ...newNonFieldErrs]];
159
+ }, [[], []]);
160
+ dispatchFields({
161
+ type: 'ADD_SERVER_ERRORS',
162
+ errors: fieldErrors
135
163
  });
136
- setModified(false);
137
- getVersions();
138
- } else {
139
- return res.json();
140
- }
141
- }).then(json => {
142
- if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {
143
- if (Array.isArray(json.errors)) {
144
- const [fieldErrors, nonFieldErrors] = json.errors.reduce((t4, err) => {
145
- const [fieldErrs, nonFieldErrs] = t4;
146
- const newFieldErrs = [];
147
- const newNonFieldErrs = [];
148
- if (err?.message) {
149
- newNonFieldErrs.push(err);
150
- }
151
- if (Array.isArray(err?.data)) {
152
- err.data.forEach(dataError => {
153
- if (dataError?.field) {
154
- newFieldErrs.push(dataError);
155
- } else {
156
- newNonFieldErrs.push(dataError);
157
- }
158
- });
159
- }
160
- return [[...fieldErrs, ...newFieldErrs], [...nonFieldErrs, ...newNonFieldErrs]];
161
- }, [[], []]);
162
- dispatchFields({
163
- type: "ADD_SERVER_ERRORS",
164
- errors: fieldErrors
165
- });
166
- nonFieldErrors.forEach(err_0 => {
167
- toast.error(err_0.message || i18n.t("error:unknown"));
168
- });
169
- setSubmitted(true);
170
- setSaving(false);
171
- return;
172
- }
173
- }
174
- }).then(() => {
175
- if (endTimestamp - startTimestamp < minimumAnimationTime) {
176
- autosaveTimeout = setTimeout(() => {
177
- setSaving(false);
178
- }, minimumAnimationTime - (endTimestamp - startTimestamp));
179
- } else {
164
+ nonFieldErrors.forEach(err_0 => {
165
+ toast.error(err_0.message || i18n.t('error:unknown'));
166
+ });
167
+ setSubmitted(true);
180
168
  setSaving(false);
169
+ return;
181
170
  }
182
- });
183
- }
171
+ }
172
+ }).then(() => {
173
+ // If request was faster than minimum animation time, animate the difference
174
+ if (endTimestamp - startTimestamp < minimumAnimationTime) {
175
+ autosaveTimeout = setTimeout(() => {
176
+ setSaving(false);
177
+ }, minimumAnimationTime - (endTimestamp - startTimestamp));
178
+ } else {
179
+ setSaving(false);
180
+ }
181
+ });
184
182
  }
185
183
  }
186
184
  }
187
- };
188
- autosave();
189
- return () => {
190
- if (autosaveTimeout) {
191
- clearTimeout(autosaveTimeout);
192
- }
193
- if (abortController.signal) {
194
- ;
195
- try {
196
- abortController.abort("Autosave closed early.");
197
- } catch (t5) {
198
- const error = t5;
199
- }
200
- }
201
- setSaving(false);
202
- };
185
+ }
203
186
  };
204
- $[0] = modified;
205
- $[1] = collection;
206
- $[2] = id;
207
- $[3] = serverURL;
208
- $[4] = api;
209
- $[5] = globalDoc;
210
- $[6] = submitted;
211
- $[7] = versionsConfig;
212
- $[8] = i18n;
213
- $[9] = reportUpdate;
214
- $[10] = setModified;
215
- $[11] = getVersions;
216
- $[12] = dispatchFields;
217
- $[13] = setSubmitted;
218
- $[14] = t3;
219
- } else {
220
- t3 = $[14];
221
- }
222
- const t4 = versionsConfig?.drafts;
223
- let t5;
224
- if ($[15] !== api || $[16] !== collection || $[17] !== dispatchFields || $[18] !== getVersions || $[19] !== globalDoc || $[20] !== i18n || $[21] !== id || $[22] !== interval || $[23] !== modified || $[24] !== reportUpdate || $[25] !== serverURL || $[26] !== setSubmitted || $[27] !== setModified || $[28] !== t4 || $[29] !== debouncedFields || $[30] !== submitted) {
225
- t5 = [api, collection, dispatchFields, getVersions, globalDoc, i18n, id, interval, modified, reportUpdate, serverURL, setSubmitted, setModified, t4, debouncedFields, submitted];
226
- $[15] = api;
227
- $[16] = collection;
228
- $[17] = dispatchFields;
229
- $[18] = getVersions;
230
- $[19] = globalDoc;
231
- $[20] = i18n;
232
- $[21] = id;
233
- $[22] = interval;
234
- $[23] = modified;
235
- $[24] = reportUpdate;
236
- $[25] = serverURL;
237
- $[26] = setSubmitted;
238
- $[27] = setModified;
239
- $[28] = t4;
240
- $[29] = debouncedFields;
241
- $[30] = submitted;
242
- $[31] = t5;
243
- } else {
244
- t5 = $[31];
245
- }
246
- useEffect(t3, t5);
247
- let t6;
248
- let t7;
249
- if ($[32] !== versions || $[33] !== publishedDocUpdatedAt) {
250
- t6 = () => {
251
- if (versions?.docs?.[0]) {
252
- setLastSaved(new Date(versions.docs[0].updatedAt).getTime());
253
- } else {
254
- if (publishedDocUpdatedAt) {
255
- setLastSaved(new Date(publishedDocUpdatedAt).getTime());
187
+ void autosave();
188
+ return () => {
189
+ if (autosaveTimeout) clearTimeout(autosaveTimeout);
190
+ if (abortController.signal) {
191
+ try {
192
+ abortController.abort('Autosave closed early.');
193
+ } catch (error) {
194
+ // swallow error
256
195
  }
257
196
  }
197
+ setSaving(false);
258
198
  };
259
- t7 = [publishedDocUpdatedAt, versions];
260
- $[32] = versions;
261
- $[33] = publishedDocUpdatedAt;
262
- $[34] = t6;
263
- $[35] = t7;
264
- } else {
265
- t6 = $[34];
266
- t7 = $[35];
267
- }
268
- useEffect(t6, t7);
269
- let t8;
270
- if ($[36] !== saving || $[37] !== t) {
271
- t8 = saving && t("general:saving");
272
- $[36] = saving;
273
- $[37] = t;
274
- $[38] = t8;
275
- } else {
276
- t8 = $[38];
277
- }
278
- let t9;
279
- if ($[39] !== saving || $[40] !== lastSaved || $[41] !== i18n || $[42] !== t || $[43] !== t8) {
280
- t9 = _jsxs("div", {
281
- className: baseClass,
282
- children: [t8, !saving && Boolean(lastSaved) && _jsx(React.Fragment, {
283
- children: t("version:lastSavedAgo", {
284
- distance: formatTimeToNow({
285
- date: lastSaved,
286
- i18n
287
- })
199
+ }, [api, collection, dispatchFields, getVersions, globalDoc, i18n, id, interval, modified, reportUpdate, serverURL, setSubmitted, setModified, versionsConfig?.drafts, debouncedFields, submitted]);
200
+ useEffect(() => {
201
+ if (versions?.docs?.[0]) {
202
+ setLastSaved(new Date(versions.docs[0].updatedAt).getTime());
203
+ } else if (publishedDocUpdatedAt) {
204
+ setLastSaved(new Date(publishedDocUpdatedAt).getTime());
205
+ }
206
+ }, [publishedDocUpdatedAt, versions]);
207
+ return /*#__PURE__*/_jsxs("div", {
208
+ className: baseClass,
209
+ children: [saving && t('general:saving'), !saving && Boolean(lastSaved) && /*#__PURE__*/_jsx(React.Fragment, {
210
+ children: t('version:lastSavedAgo', {
211
+ distance: formatTimeToNow({
212
+ date: lastSaved,
213
+ i18n
288
214
  })
289
- })]
290
- });
291
- $[39] = saving;
292
- $[40] = lastSaved;
293
- $[41] = i18n;
294
- $[42] = t;
295
- $[43] = t8;
296
- $[44] = t9;
297
- } else {
298
- t9 = $[44];
299
- }
300
- return t9;
215
+ })
216
+ })]
217
+ });
301
218
  };
302
219
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","versionDefaults","React","useEffect","useRef","useState","toast","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useConfig","useDocumentEvents","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","baseClass","minimumAnimationTime","Autosave","t0","$","id","collection","global","globalDoc","publishedDocUpdatedAt","config","t1","routes","t2","serverURL","api","docConfig","getVersions","versions","reportUpdate","dispatchFields","setModified","setSubmitted","submitted","versionsConfig","fields","formModified","code","locale","i18n","t","interval","autosaveInterval","drafts","autosave","saving","setSaving","lastSaved","setLastSaved","debouncedFields","modified","fieldRef","modifiedRef","localeRef","debouncedRef","current","t3","abortController","AbortController","autosaveTimeout","undefined","startTimestamp","endTimestamp","url","method","entitySlug","slug","data","valid","_status","skipSubmission","validate","fetch","body","JSON","stringify","credentials","headers","language","signal","then","res","newDate","Date","getTime","status","updatedAt","toISOString","json","errors","Array","isArray","fieldErrors","nonFieldErrors","reduce","t4","err","fieldErrs","nonFieldErrs","newFieldErrs","newNonFieldErrs","message","push","forEach","dataError","field","type","err_0","error","clearTimeout","abort","t5","t6","t7","docs","t8","t9","_jsxs","className","children","Boolean","_jsx","Fragment","distance","date"],"sources":["../../../src/elements/Autosave/index.tsx"],"sourcesContent":["'use client'\n// TODO: abstract the `next/navigation` dependency out from this component\nimport type { ClientCollectionConfig, ClientGlobalConfig } from 'payload'\n\nimport { versionDefaults } from 'payload/shared'\nimport React, { useEffect, useRef, useState } from 'react'\nimport { toast } from 'sonner'\n\nimport {\n useAllFormFields,\n useForm,\n useFormModified,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentEvents } from '../../providers/DocumentEvents/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatTimeToNow } from '../../utilities/formatDate.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport './index.scss'\n\nconst baseClass = 'autosave'\n// The minimum time the saving state should be shown\nconst minimumAnimationTime = 1000\n\nexport type Props = {\n collection?: ClientCollectionConfig\n global?: ClientGlobalConfig\n id?: number | string\n publishedDocUpdatedAt: string\n}\n\nexport const Autosave: React.FC<Props> = ({\n id,\n collection,\n global: globalDoc,\n publishedDocUpdatedAt,\n}) => {\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n const { docConfig, getVersions, versions } = useDocumentInfo()\n const { reportUpdate } = useDocumentEvents()\n const { dispatchFields, setModified, setSubmitted } = useForm()\n const submitted = useFormSubmitted()\n const versionsConfig = docConfig?.versions\n\n const [fields] = useAllFormFields()\n const formModified = useFormModified()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n let interval = versionDefaults.autosaveInterval\n if (versionsConfig.drafts && versionsConfig.drafts.autosave)\n interval = versionsConfig.drafts.autosave.interval\n\n const [saving, setSaving] = useState(false)\n const [lastSaved, setLastSaved] = useState<number>()\n const debouncedFields = useDebounce(fields, interval)\n const modified = useDebounce(formModified, interval)\n const fieldRef = useRef(fields)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\n const debouncedRef = useRef(debouncedFields)\n\n debouncedRef.current = debouncedFields\n\n // Store fields in ref so the autosave func\n // can always retrieve the most to date copies\n // after the timeout has executed\n fieldRef.current = fields\n\n // Store modified in ref so the autosave func\n // can bail out if modified becomes false while\n // timing out during autosave\n modifiedRef.current = modified\n\n // Store locale in ref so the autosave func\n // can always retrieve the most to date locale\n localeRef.current = locale\n\n // When debounced fields change, autosave\n useEffect(() => {\n const abortController = new AbortController()\n let autosaveTimeout = undefined\n // We need to log the time in order to figure out if we need to trigger the state off later\n let startTimestamp = undefined\n let endTimestamp = undefined\n\n const autosave = () => {\n if (modified) {\n startTimestamp = new Date().getTime()\n\n setSaving(true)\n\n let url: string\n let method: string\n let entitySlug: string\n\n if (collection && id) {\n entitySlug = collection.slug\n url = `${serverURL}${api}/${entitySlug}/${id}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'PATCH'\n }\n\n if (globalDoc) {\n entitySlug = globalDoc.slug\n url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'POST'\n }\n\n if (url) {\n if (modifiedRef.current) {\n const { data, valid } = {\n ...reduceFieldsToValuesWithValidation(fieldRef.current, true),\n }\n data._status = 'draft'\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission) {\n void fetch(url, {\n body: JSON.stringify(data),\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n 'Content-Type': 'application/json',\n },\n method,\n signal: abortController.signal,\n })\n .then((res) => {\n const newDate = new Date()\n // We need to log the time in order to figure out if we need to trigger the state off later\n endTimestamp = newDate.getTime()\n\n if (res.status === 200) {\n setLastSaved(newDate.getTime())\n\n reportUpdate({\n id,\n entitySlug,\n updatedAt: newDate.toISOString(),\n })\n setModified(false)\n void getVersions()\n } else {\n return res.json()\n }\n })\n .then((json) => {\n if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {\n if (Array.isArray(json.errors)) {\n const [fieldErrors, nonFieldErrors] = json.errors.reduce(\n ([fieldErrs, nonFieldErrs], err) => {\n const newFieldErrs = []\n const newNonFieldErrs = []\n\n if (err?.message) {\n newNonFieldErrs.push(err)\n }\n\n if (Array.isArray(err?.data)) {\n err.data.forEach((dataError) => {\n if (dataError?.field) {\n newFieldErrs.push(dataError)\n } else {\n newNonFieldErrs.push(dataError)\n }\n })\n }\n\n return [\n [...fieldErrs, ...newFieldErrs],\n [...nonFieldErrs, ...newNonFieldErrs],\n ]\n },\n [[], []],\n )\n\n dispatchFields({\n type: 'ADD_SERVER_ERRORS',\n errors: fieldErrors,\n })\n\n nonFieldErrors.forEach((err) => {\n toast.error(err.message || i18n.t('error:unknown'))\n })\n\n setSubmitted(true)\n setSaving(false)\n return\n }\n }\n })\n .then(() => {\n // If request was faster than minimum animation time, animate the difference\n if (endTimestamp - startTimestamp < minimumAnimationTime) {\n autosaveTimeout = setTimeout(\n () => {\n setSaving(false)\n },\n minimumAnimationTime - (endTimestamp - startTimestamp),\n )\n } else {\n setSaving(false)\n }\n })\n }\n }\n }\n }\n }\n\n void autosave()\n\n return () => {\n if (autosaveTimeout) clearTimeout(autosaveTimeout)\n if (abortController.signal) {\n try {\n abortController.abort('Autosave closed early.')\n } catch (error) {\n // swallow error\n }\n }\n setSaving(false)\n }\n }, [\n api,\n collection,\n dispatchFields,\n getVersions,\n globalDoc,\n i18n,\n id,\n interval,\n modified,\n reportUpdate,\n serverURL,\n setSubmitted,\n setModified,\n versionsConfig?.drafts,\n debouncedFields,\n submitted,\n ])\n\n useEffect(() => {\n if (versions?.docs?.[0]) {\n setLastSaved(new Date(versions.docs[0].updatedAt).getTime())\n } else if (publishedDocUpdatedAt) {\n setLastSaved(new Date(publishedDocUpdatedAt).getTime())\n }\n }, [publishedDocUpdatedAt, versions])\n\n return (\n <div className={baseClass}>\n {saving && t('general:saving')}\n {!saving && Boolean(lastSaved) && (\n <React.Fragment>\n {t('version:lastSavedAgo', {\n distance: formatTimeToNow({ date: lastSaved, i18n }),\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,eAAe,QAAQ;AAChC,OAAOC,KAAA,IAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AACnD,SAASC,KAAK,QAAQ;AAEtB,SACEC,gBAAgB,EAChBC,OAAO,EACPC,eAAe,EACfC,gBAAgB,QACX;AACP,SAASC,WAAW,QAAQ;AAC5B,SAASC,SAAS,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,eAAe,QAAQ;AAChC,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,kCAAkC,QAAQ;AACnD,OAAO;AAEP,MAAMC,SAAA,GAAY;AACl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,CACpD;MAAA,C;;;;;;;;;;;SANN6E,E;CAWJ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["versionDefaults","React","useEffect","useRef","useState","toast","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useConfig","useDocumentEvents","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","publishedDocUpdatedAt","config","routes","api","serverURL","docConfig","getVersions","versions","reportUpdate","dispatchFields","setModified","setSubmitted","submitted","versionsConfig","fields","formModified","code","locale","i18n","t","interval","autosaveInterval","drafts","autosave","saving","setSaving","lastSaved","setLastSaved","debouncedFields","modified","fieldRef","modifiedRef","localeRef","debouncedRef","current","abortController","AbortController","autosaveTimeout","undefined","startTimestamp","endTimestamp","Date","getTime","url","method","entitySlug","slug","data","valid","_status","skipSubmission","validate","fetch","body","JSON","stringify","credentials","headers","language","signal","then","res","newDate","status","updatedAt","toISOString","json","errors","Array","isArray","fieldErrors","nonFieldErrors","reduce","fieldErrs","nonFieldErrs","err","newFieldErrs","newNonFieldErrs","message","push","forEach","dataError","field","type","error","setTimeout","clearTimeout","abort","docs","_jsxs","className","Boolean","_jsx","Fragment","distance","date"],"sources":["../../../src/elements/Autosave/index.tsx"],"sourcesContent":["'use client'\n// TODO: abstract the `next/navigation` dependency out from this component\nimport type { ClientCollectionConfig, ClientGlobalConfig } from 'payload'\n\nimport { versionDefaults } from 'payload/shared'\nimport React, { useEffect, useRef, useState } from 'react'\nimport { toast } from 'sonner'\n\nimport {\n useAllFormFields,\n useForm,\n useFormModified,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentEvents } from '../../providers/DocumentEvents/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatTimeToNow } from '../../utilities/formatDate.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport './index.scss'\n\nconst baseClass = 'autosave'\n// The minimum time the saving state should be shown\nconst minimumAnimationTime = 1000\n\nexport type Props = {\n collection?: ClientCollectionConfig\n global?: ClientGlobalConfig\n id?: number | string\n publishedDocUpdatedAt: string\n}\n\nexport const Autosave: React.FC<Props> = ({\n id,\n collection,\n global: globalDoc,\n publishedDocUpdatedAt,\n}) => {\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n const { docConfig, getVersions, versions } = useDocumentInfo()\n const { reportUpdate } = useDocumentEvents()\n const { dispatchFields, setModified, setSubmitted } = useForm()\n const submitted = useFormSubmitted()\n const versionsConfig = docConfig?.versions\n\n const [fields] = useAllFormFields()\n const formModified = useFormModified()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n let interval = versionDefaults.autosaveInterval\n if (versionsConfig.drafts && versionsConfig.drafts.autosave)\n interval = versionsConfig.drafts.autosave.interval\n\n const [saving, setSaving] = useState(false)\n const [lastSaved, setLastSaved] = useState<number>()\n const debouncedFields = useDebounce(fields, interval)\n const modified = useDebounce(formModified, interval)\n const fieldRef = useRef(fields)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\n const debouncedRef = useRef(debouncedFields)\n\n debouncedRef.current = debouncedFields\n\n // Store fields in ref so the autosave func\n // can always retrieve the most to date copies\n // after the timeout has executed\n fieldRef.current = fields\n\n // Store modified in ref so the autosave func\n // can bail out if modified becomes false while\n // timing out during autosave\n modifiedRef.current = modified\n\n // Store locale in ref so the autosave func\n // can always retrieve the most to date locale\n localeRef.current = locale\n\n // When debounced fields change, autosave\n useEffect(() => {\n const abortController = new AbortController()\n let autosaveTimeout = undefined\n // We need to log the time in order to figure out if we need to trigger the state off later\n let startTimestamp = undefined\n let endTimestamp = undefined\n\n const autosave = () => {\n if (modified) {\n startTimestamp = new Date().getTime()\n\n setSaving(true)\n\n let url: string\n let method: string\n let entitySlug: string\n\n if (collection && id) {\n entitySlug = collection.slug\n url = `${serverURL}${api}/${entitySlug}/${id}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'PATCH'\n }\n\n if (globalDoc) {\n entitySlug = globalDoc.slug\n url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'POST'\n }\n\n if (url) {\n if (modifiedRef.current) {\n const { data, valid } = {\n ...reduceFieldsToValuesWithValidation(fieldRef.current, true),\n }\n data._status = 'draft'\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission) {\n void fetch(url, {\n body: JSON.stringify(data),\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n 'Content-Type': 'application/json',\n },\n method,\n signal: abortController.signal,\n })\n .then((res) => {\n const newDate = new Date()\n // We need to log the time in order to figure out if we need to trigger the state off later\n endTimestamp = newDate.getTime()\n\n if (res.status === 200) {\n setLastSaved(newDate.getTime())\n\n reportUpdate({\n id,\n entitySlug,\n updatedAt: newDate.toISOString(),\n })\n setModified(false)\n void getVersions()\n } else {\n return res.json()\n }\n })\n .then((json) => {\n if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {\n if (Array.isArray(json.errors)) {\n const [fieldErrors, nonFieldErrors] = json.errors.reduce(\n ([fieldErrs, nonFieldErrs], err) => {\n const newFieldErrs = []\n const newNonFieldErrs = []\n\n if (err?.message) {\n newNonFieldErrs.push(err)\n }\n\n if (Array.isArray(err?.data)) {\n err.data.forEach((dataError) => {\n if (dataError?.field) {\n newFieldErrs.push(dataError)\n } else {\n newNonFieldErrs.push(dataError)\n }\n })\n }\n\n return [\n [...fieldErrs, ...newFieldErrs],\n [...nonFieldErrs, ...newNonFieldErrs],\n ]\n },\n [[], []],\n )\n\n dispatchFields({\n type: 'ADD_SERVER_ERRORS',\n errors: fieldErrors,\n })\n\n nonFieldErrors.forEach((err) => {\n toast.error(err.message || i18n.t('error:unknown'))\n })\n\n setSubmitted(true)\n setSaving(false)\n return\n }\n }\n })\n .then(() => {\n // If request was faster than minimum animation time, animate the difference\n if (endTimestamp - startTimestamp < minimumAnimationTime) {\n autosaveTimeout = setTimeout(\n () => {\n setSaving(false)\n },\n minimumAnimationTime - (endTimestamp - startTimestamp),\n )\n } else {\n setSaving(false)\n }\n })\n }\n }\n }\n }\n }\n\n void autosave()\n\n return () => {\n if (autosaveTimeout) clearTimeout(autosaveTimeout)\n if (abortController.signal) {\n try {\n abortController.abort('Autosave closed early.')\n } catch (error) {\n // swallow error\n }\n }\n setSaving(false)\n }\n }, [\n api,\n collection,\n dispatchFields,\n getVersions,\n globalDoc,\n i18n,\n id,\n interval,\n modified,\n reportUpdate,\n serverURL,\n setSubmitted,\n setModified,\n versionsConfig?.drafts,\n debouncedFields,\n submitted,\n ])\n\n useEffect(() => {\n if (versions?.docs?.[0]) {\n setLastSaved(new Date(versions.docs[0].updatedAt).getTime())\n } else if (publishedDocUpdatedAt) {\n setLastSaved(new Date(publishedDocUpdatedAt).getTime())\n }\n }, [publishedDocUpdatedAt, versions])\n\n return (\n <div className={baseClass}>\n {saving && t('general:saving')}\n {!saving && Boolean(lastSaved) && (\n <React.Fragment>\n {t('version:lastSavedAgo', {\n distance: formatTimeToNow({ date: lastSaved, i18n }),\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,eAAe,QAAQ;AAChC,OAAOC,KAAA,IAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AACnD,SAASC,KAAK,QAAQ;AAEtB,SACEC,gBAAgB,EAChBC,OAAO,EACPC,eAAe,EACfC,gBAAgB,QACX;AACP,SAASC,WAAW,QAAQ;AAC5B,SAASC,SAAS,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,eAAe,QAAQ;AAChC,SAASC,SAAS,QAAQ;AAC1B,SAASC,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