@payloadcms/ui 3.51.0 → 3.52.0-canary.1

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 (30) hide show
  1. package/dist/elements/Autosave/index.d.ts.map +1 -1
  2. package/dist/elements/Autosave/index.js.map +1 -1
  3. package/dist/elements/DocumentDrawer/Provider.d.ts +1 -1
  4. package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
  5. package/dist/exports/client/index.js +24 -24
  6. package/dist/exports/client/index.js.map +3 -3
  7. package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
  8. package/dist/forms/Form/fieldReducer.js +12 -3
  9. package/dist/forms/Form/fieldReducer.js.map +1 -1
  10. package/dist/forms/Form/index.d.ts.map +1 -1
  11. package/dist/forms/Form/index.js +6 -10
  12. package/dist/forms/Form/index.js.map +1 -1
  13. package/dist/forms/Form/mergeServerFormState.d.ts +1 -2
  14. package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
  15. package/dist/forms/Form/mergeServerFormState.js +4 -4
  16. package/dist/forms/Form/mergeServerFormState.js.map +1 -1
  17. package/dist/forms/Form/types.d.ts +12 -8
  18. package/dist/forms/Form/types.d.ts.map +1 -1
  19. package/dist/forms/Form/types.js.map +1 -1
  20. package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
  21. package/dist/forms/fieldSchemasToFormState/index.js +1 -0
  22. package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
  23. package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
  24. package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
  25. package/dist/utilities/buildFormState.d.ts.map +1 -1
  26. package/dist/utilities/buildFormState.js.map +1 -1
  27. package/dist/views/Edit/index.d.ts.map +1 -1
  28. package/dist/views/Edit/index.js +7 -4
  29. package/dist/views/Edit/index.js.map +1 -1
  30. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Autosave/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAwD,MAAM,OAAO,CAAA;AAkB5E,OAAO,cAAc,CAAA;AAMrB,MAAM,MAAM,KAAK,GAAG;IAClB,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,qBAAqB,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAwNpC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Autosave/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAwD,MAAM,OAAO,CAAA;AAkB5E,OAAO,cAAc,CAAA;AAMrB,MAAM,MAAM,KAAK,GAAG;IAClB,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,qBAAqB,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA0NpC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["dequal","reduceFieldsToValues","versionDefaults","React","useDeferredValue","useEffect","useRef","useState","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useEffectEvent","useQueues","useConfig","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","LeaveWithoutSaving","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","config","routes","api","serverURL","docConfig","incrementVersionCount","lastUpdateTime","mostRecentVersionIsAutosaved","setMostRecentVersionIsAutosaved","setUnpublishedVersionCount","isValid","setBackgroundProcessing","submit","formState","modified","submitted","code","locale","i18n","t","versionsConfig","versions","interval","autosaveInterval","drafts","autosave","validateOnDraft","Boolean","validate","_saving","setSaving","saving","debouncedFormState","formStateRef","modifiedRef","localeRef","current","queueTask","autosaveTimeoutRef","handleAutosave","undefined","startTimestamp","endTimestamp","hideIndicator","setTimeout","stopAutoSaveIndicator","Date","getTime","url","method","entitySlug","slug","valid","skipSubmission","result","acceptValues","overrideLocalChanges","action","context","disableFormWhileProcessing","disableSuccessStatus","overrides","_status","skipValidation","res","ok","prev","newDate","afterProcess","beforeProcess","didMount","previousDebouncedData","updatedAt","_","formData","__","prevFormData","clearTimeout","_jsxs","className","_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 { dequal } from 'dequal/lite'\nimport { reduceFieldsToValues, versionDefaults } from 'payload/shared'\nimport React, { useDeferredValue, useEffect, useRef, useState } from 'react'\n\nimport {\n useAllFormFields,\n useForm,\n useFormModified,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useQueues } from '../../hooks/useQueues.js'\nimport { useConfig } from '../../providers/Config/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/formatDocTitle/formatDateTitle.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.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> = ({ id, collection, global: globalDoc }) => {\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n\n const {\n docConfig,\n incrementVersionCount,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n } = useDocumentInfo()\n\n const { isValid, setBackgroundProcessing, submit } = useForm()\n\n const [formState] = useAllFormFields()\n const modified = useFormModified()\n const submitted = useFormSubmitted()\n\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n const versionsConfig = docConfig?.versions\n let interval = versionDefaults.autosaveInterval\n\n if (versionsConfig.drafts && versionsConfig.drafts.autosave) {\n interval = versionsConfig.drafts.autosave.interval\n }\n\n const validateOnDraft = Boolean(\n docConfig?.versions?.drafts && docConfig?.versions?.drafts.validate,\n )\n\n const [_saving, setSaving] = useState(false)\n\n const saving = useDeferredValue(_saving)\n\n const debouncedFormState = useDebounce(formState, interval)\n\n const formStateRef = useRef(formState)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\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 formStateRef.current = formState\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 const { queueTask } = useQueues()\n\n const autosaveTimeoutRef = useRef<NodeJS.Timeout | null>(null)\n\n const handleAutosave = useEffectEvent(() => {\n autosaveTimeoutRef.current = 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 hideIndicator = () => {\n // If request was faster than minimum animation time, animate the difference\n if (endTimestamp - startTimestamp < minimumAnimationTime) {\n autosaveTimeoutRef.current = setTimeout(\n () => {\n setSaving(false)\n },\n minimumAnimationTime - (endTimestamp - startTimestamp),\n )\n } else {\n stopAutoSaveIndicator()\n }\n }\n\n queueTask(\n async () => {\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 const { valid } = reduceFieldsToValuesWithValidation(formStateRef.current, true)\n\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission && modifiedRef.current && url) {\n const result = await submit({\n acceptValues: {\n overrideLocalChanges: false,\n },\n action: url,\n context: {\n incrementVersionCount: false,\n },\n disableFormWhileProcessing: false,\n disableSuccessStatus: true,\n method,\n overrides: {\n _status: 'draft',\n },\n skipValidation: versionsConfig?.drafts && !versionsConfig?.drafts?.validate,\n })\n\n if (result && result?.res?.ok && !mostRecentVersionIsAutosaved) {\n incrementVersionCount()\n setMostRecentVersionIsAutosaved(true)\n setUnpublishedVersionCount((prev) => prev + 1)\n }\n\n const newDate = new Date()\n\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 hideIndicator()\n }\n }\n },\n {\n afterProcess: () => {\n setBackgroundProcessing(false)\n },\n beforeProcess: () => {\n setBackgroundProcessing(true)\n },\n },\n )\n })\n\n const didMount = useRef(false)\n const previousDebouncedData = useRef(reduceFieldsToValues(debouncedFormState))\n\n // When debounced fields change, autosave\n useEffect(() => {\n /**\n * Ensure autosave doesn't run on mount\n */\n if (!didMount.current) {\n didMount.current = true\n return\n }\n\n /**\n * Ensure autosave only runs if the form data changes, not every time the entire form state changes\n * Remove `updatedAt` from comparison as it changes on every autosave interval.\n */\n const { updatedAt: _, ...formData } = reduceFieldsToValues(debouncedFormState)\n const { updatedAt: __, ...prevFormData } = previousDebouncedData.current\n\n if (dequal(formData, prevFormData)) {\n return\n }\n\n previousDebouncedData.current = formData\n\n handleAutosave()\n }, [debouncedFormState])\n\n /**\n * If component unmounts, clear the autosave timeout\n */\n useEffect(() => {\n return () => {\n stopAutoSaveIndicator()\n }\n }, [])\n\n const stopAutoSaveIndicator = useEffectEvent(() => {\n if (autosaveTimeoutRef.current) {\n clearTimeout(autosaveTimeoutRef.current)\n }\n\n setSaving(false)\n })\n\n return (\n <div className={baseClass}>\n {validateOnDraft && !isValid && <LeaveWithoutSaving />}\n {saving && t('general:saving')}\n {!saving && Boolean(lastUpdateTime) && (\n <React.Fragment>\n {t('version:lastSavedAgo', {\n distance: formatTimeToNow({ date: lastUpdateTime, i18n }),\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,MAAM,QAAQ;AACvB,SAASC,oBAAoB,EAAEC,eAAe,QAAQ;AACtD,OAAOC,KAAA,IAASC,gBAAgB,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAErE,SACEC,gBAAgB,EAChBC,OAAO,EACPC,eAAe,EACfC,gBAAgB,QACX;AACP,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,kCAAkC,QAAQ;AACnD,SAASC,kBAAkB,QAAQ;AACnC,OAAO;AAEP,MAAMC,SAAA,GAAY;AAClB;AACA,MAAMC,oBAAA,GAAuB;AAS7B,OAAO,MAAMC,QAAA,GAA4BA,CAAC;EAAEC,EAAE;EAAEC,UAAU;EAAEC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,kBAAA;EAE1D;EACAxD,SAAA,CAAU;IACR;;;IAGA,IAAI,CAAC8F,QAAA,CAASlC,OAAO,EAAE;MACrBkC,QAAA,CAASlC,OAAO,GAAG;MACnB;IACF;IAEA;;;;IAIA,MAAM;MAAEoC,SAAA,EAAWC,CAAC;MAAE,GAAGC;IAAA,CAAU,GAAGtG,oBAAA,CAAqB4D,kBAAA;IAC3D,MAAM;MAAEwC,SAAA,EAAWG,EAAE;MAAE,GAAGC;IAAA,CAAc,GAAGL,qBAAA,CAAsBnC,OAAO;IAExE,IAAIjE,MAAA,CAAOuG,QAAA,EAAUE,YAAA,GAAe;MAClC;IACF;IAEAL,qBAAA,CAAsBnC,OAAO,GAAGsC,QAAA;IAEhCnC,cAAA;EACF,GAAG,CAACP,kBAAA,CAAmB;EAEvB;;;EAGAxD,SAAA,CAAU;IACR,OAAO;MACLqE,qBAAA;IACF;EACF,GAAG,EAAE;EAEL,MAAMA,qBAAA,GAAwB7D,cAAA,CAAe;IAC3C,IAAIsD,kBAAA,CAAmBF,OAAO,EAAE;MAC9ByC,YAAA,CAAavC,kBAAA,CAAmBF,OAAO;IACzC;IAEAN,SAAA,CAAU;EACZ;EAEA,oBACEgD,KAAA,CAAC;IAAIC,SAAA,EAAWtF,SAAA;eACbiC,eAAA,IAAmB,CAAChB,OAAA,iBAAWsE,IAAA,CAACxF,kBAAA,OAChCuC,MAAA,IAAUZ,CAAA,CAAE,mBACZ,CAACY,MAAA,IAAUJ,OAAA,CAAQrB,cAAA,kBAClB0E,IAAA,CAAC1G,KAAA,CAAM2G,QAAQ;gBACZ9D,CAAA,CAAE,wBAAwB;QACzB+D,QAAA,EAAU5F,eAAA,CAAgB;UAAE6F,IAAA,EAAM7E,cAAA;UAAgBY;QAAK;MACzD;;;AAKV","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["dequal","reduceFieldsToValues","versionDefaults","React","useDeferredValue","useEffect","useRef","useState","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useEffectEvent","useQueues","useConfig","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","LeaveWithoutSaving","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","config","routes","api","serverURL","docConfig","incrementVersionCount","lastUpdateTime","mostRecentVersionIsAutosaved","setMostRecentVersionIsAutosaved","setUnpublishedVersionCount","isValid","setBackgroundProcessing","submit","formState","modified","submitted","code","locale","i18n","t","versionsConfig","versions","interval","autosaveInterval","drafts","autosave","validateOnDraft","Boolean","validate","_saving","setSaving","saving","debouncedFormState","formStateRef","modifiedRef","localeRef","current","queueTask","autosaveTimeoutRef","handleAutosave","undefined","startTimestamp","endTimestamp","hideIndicator","setTimeout","stopAutoSaveIndicator","Date","getTime","url","method","entitySlug","slug","valid","skipSubmission","result","acceptValues","overrideLocalChanges","action","context","disableFormWhileProcessing","disableSuccessStatus","overrides","_status","skipValidation","res","ok","prev","newDate","afterProcess","beforeProcess","didMount","previousDebouncedData","updatedAt","_","formData","__","prevFormData","clearTimeout","_jsxs","className","_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 { dequal } from 'dequal/lite'\nimport { reduceFieldsToValues, versionDefaults } from 'payload/shared'\nimport React, { useDeferredValue, useEffect, useRef, useState } from 'react'\n\nimport {\n useAllFormFields,\n useForm,\n useFormModified,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useQueues } from '../../hooks/useQueues.js'\nimport { useConfig } from '../../providers/Config/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/formatDocTitle/formatDateTitle.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.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> = ({ id, collection, global: globalDoc }) => {\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n\n const {\n docConfig,\n incrementVersionCount,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n } = useDocumentInfo()\n\n const { isValid, setBackgroundProcessing, submit } = useForm()\n\n const [formState] = useAllFormFields()\n const modified = useFormModified()\n const submitted = useFormSubmitted()\n\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n const versionsConfig = docConfig?.versions\n let interval = versionDefaults.autosaveInterval\n\n if (versionsConfig.drafts && versionsConfig.drafts.autosave) {\n interval = versionsConfig.drafts.autosave.interval\n }\n\n const validateOnDraft = Boolean(\n docConfig?.versions?.drafts && docConfig?.versions?.drafts.validate,\n )\n\n const [_saving, setSaving] = useState(false)\n\n const saving = useDeferredValue(_saving)\n\n const debouncedFormState = useDebounce(formState, interval)\n\n const formStateRef = useRef(formState)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\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 formStateRef.current = formState\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 const { queueTask } = useQueues()\n\n const autosaveTimeoutRef = useRef<NodeJS.Timeout | null>(null)\n\n const handleAutosave = useEffectEvent(() => {\n autosaveTimeoutRef.current = 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 hideIndicator = () => {\n // If request was faster than minimum animation time, animate the difference\n if (endTimestamp - startTimestamp < minimumAnimationTime) {\n autosaveTimeoutRef.current = setTimeout(\n () => {\n setSaving(false)\n },\n minimumAnimationTime - (endTimestamp - startTimestamp),\n )\n } else {\n stopAutoSaveIndicator()\n }\n }\n\n queueTask(\n async () => {\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 const { valid } = reduceFieldsToValuesWithValidation(formStateRef.current, true)\n\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission && modifiedRef.current && url) {\n const result = await submit<{\n incrementVersionCount: boolean\n }>({\n acceptValues: {\n overrideLocalChanges: false,\n },\n action: url,\n context: {\n incrementVersionCount: false,\n },\n disableFormWhileProcessing: false,\n disableSuccessStatus: true,\n method,\n overrides: {\n _status: 'draft',\n },\n skipValidation: versionsConfig?.drafts && !versionsConfig?.drafts?.validate,\n })\n\n if (result && result?.res?.ok && !mostRecentVersionIsAutosaved) {\n incrementVersionCount()\n setMostRecentVersionIsAutosaved(true)\n setUnpublishedVersionCount((prev) => prev + 1)\n }\n\n const newDate = new Date()\n\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 hideIndicator()\n }\n }\n },\n {\n afterProcess: () => {\n setBackgroundProcessing(false)\n },\n beforeProcess: () => {\n setBackgroundProcessing(true)\n },\n },\n )\n })\n\n const didMount = useRef(false)\n const previousDebouncedData = useRef(reduceFieldsToValues(debouncedFormState))\n\n // When debounced fields change, autosave\n useEffect(() => {\n /**\n * Ensure autosave doesn't run on mount\n */\n if (!didMount.current) {\n didMount.current = true\n return\n }\n\n /**\n * Ensure autosave only runs if the form data changes, not every time the entire form state changes\n * Remove `updatedAt` from comparison as it changes on every autosave interval.\n */\n const { updatedAt: _, ...formData } = reduceFieldsToValues(debouncedFormState)\n const { updatedAt: __, ...prevFormData } = previousDebouncedData.current\n\n if (dequal(formData, prevFormData)) {\n return\n }\n\n previousDebouncedData.current = formData\n\n handleAutosave()\n }, [debouncedFormState])\n\n /**\n * If component unmounts, clear the autosave timeout\n */\n useEffect(() => {\n return () => {\n stopAutoSaveIndicator()\n }\n }, [])\n\n const stopAutoSaveIndicator = useEffectEvent(() => {\n if (autosaveTimeoutRef.current) {\n clearTimeout(autosaveTimeoutRef.current)\n }\n\n setSaving(false)\n })\n\n return (\n <div className={baseClass}>\n {validateOnDraft && !isValid && <LeaveWithoutSaving />}\n {saving && t('general:saving')}\n {!saving && Boolean(lastUpdateTime) && (\n <React.Fragment>\n {t('version:lastSavedAgo', {\n distance: formatTimeToNow({ date: lastUpdateTime, i18n }),\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,MAAM,QAAQ;AACvB,SAASC,oBAAoB,EAAEC,eAAe,QAAQ;AACtD,OAAOC,KAAA,IAASC,gBAAgB,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAErE,SACEC,gBAAgB,EAChBC,OAAO,EACPC,eAAe,EACfC,gBAAgB,QACX;AACP,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,kCAAkC,QAAQ;A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,cAAA;UAAgBY;QAAK;MACzD;;;AAKV","ignoreList":[]}
@@ -17,7 +17,7 @@ export type DocumentDrawerContextProps = {
17
17
  readonly onSave?: (args: {
18
18
  collectionConfig?: ClientCollectionConfig;
19
19
  /**
20
- * @experimental - Note: this property is experimental and may change in the future. Use as your own discretion.
20
+ * @experimental - Note: this property is experimental and may change in the future. Use at your own discretion.
21
21
  * If you want to pass additional data to the onSuccess callback, you can use this context object.
22
22
  */
23
23
  context?: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","names":["createContext","use","DocumentDrawerCallbacksContext","DocumentDrawerContextProvider","children","rest","_jsx","value","useDocumentDrawerContext","context","Error"],"sources":["../../../src/elements/DocumentDrawer/Provider.tsx"],"sourcesContent":["import type { ClientCollectionConfig, Data, FormState, TypeWithID } from 'payload'\n\nimport { createContext, use } from 'react'\n\nexport type DocumentDrawerContextProps = {\n readonly clearDoc?: () => void\n readonly drawerSlug: string\n readonly onDelete?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n /* only available if `redirectAfterDuplicate` is `false` */\n readonly onDuplicate?: (args: {\n collectionConfig?: ClientCollectionConfig\n doc: TypeWithID\n }) => Promise<void> | void\n readonly onRestore?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n readonly onSave?: (args: {\n collectionConfig?: ClientCollectionConfig\n /**\n * @experimental - Note: this property is experimental and may change in the future. Use as your own discretion.\n * If you want to pass additional data to the onSuccess callback, you can use this context object.\n */\n context?: Record<string, unknown>\n doc: TypeWithID\n operation: 'create' | 'update'\n result: Data\n }) => Promise<FormState | void> | void\n}\n\nexport type DocumentDrawerContextType = {} & DocumentDrawerContextProps\n\nexport const DocumentDrawerCallbacksContext = createContext({} as DocumentDrawerContextType)\n\nexport const DocumentDrawerContextProvider: React.FC<\n {\n children: React.ReactNode\n } & DocumentDrawerContextProps\n> = ({ children, ...rest }) => {\n return <DocumentDrawerCallbacksContext value={rest}>{children}</DocumentDrawerCallbacksContext>\n}\n\nexport const useDocumentDrawerContext = (): DocumentDrawerContextType => {\n const context = use(DocumentDrawerCallbacksContext)\n\n if (!context) {\n throw new Error('useDocumentDrawerContext must be used within a DocumentDrawerProvider')\n }\n\n return context\n}\n"],"mappings":";AAEA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AAiCnC,OAAO,MAAMC,8BAAA,gBAAiCF,aAAA,CAAc,CAAC;AAE7D,OAAO,MAAMG,6BAAA,GAITA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAA,CAAM;EACxB,oBAAOC,IAAA,CAACJ,8BAAA;IAA+BK,KAAA,EAAOF,IAAA;cAAOD;;AACvD;AAEA,OAAO,MAAMI,wBAAA,GAA2BA,CAAA;EACtC,MAAMC,OAAA,GAAUR,GAAA,CAAIC,8BAAA;EAEpB,IAAI,CAACO,OAAA,EAAS;IACZ,MAAM,IAAIC,KAAA,CAAM;EAClB;EAEA,OAAOD,OAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"Provider.js","names":["createContext","use","DocumentDrawerCallbacksContext","DocumentDrawerContextProvider","children","rest","_jsx","value","useDocumentDrawerContext","context","Error"],"sources":["../../../src/elements/DocumentDrawer/Provider.tsx"],"sourcesContent":["import type { ClientCollectionConfig, Data, FormState, TypeWithID } from 'payload'\n\nimport { createContext, use } from 'react'\n\nexport type DocumentDrawerContextProps = {\n readonly clearDoc?: () => void\n readonly drawerSlug: string\n readonly onDelete?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n /* only available if `redirectAfterDuplicate` is `false` */\n readonly onDuplicate?: (args: {\n collectionConfig?: ClientCollectionConfig\n doc: TypeWithID\n }) => Promise<void> | void\n readonly onRestore?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n readonly onSave?: (args: {\n collectionConfig?: ClientCollectionConfig\n /**\n * @experimental - Note: this property is experimental and may change in the future. Use at your own discretion.\n * If you want to pass additional data to the onSuccess callback, you can use this context object.\n */\n context?: Record<string, unknown>\n doc: TypeWithID\n operation: 'create' | 'update'\n result: Data\n }) => Promise<FormState | void> | void\n}\n\nexport type DocumentDrawerContextType = {} & DocumentDrawerContextProps\n\nexport const DocumentDrawerCallbacksContext = createContext({} as DocumentDrawerContextType)\n\nexport const DocumentDrawerContextProvider: React.FC<\n {\n children: React.ReactNode\n } & DocumentDrawerContextProps\n> = ({ children, ...rest }) => {\n return <DocumentDrawerCallbacksContext value={rest}>{children}</DocumentDrawerCallbacksContext>\n}\n\nexport const useDocumentDrawerContext = (): DocumentDrawerContextType => {\n const context = use(DocumentDrawerCallbacksContext)\n\n if (!context) {\n throw new Error('useDocumentDrawerContext must be used within a DocumentDrawerProvider')\n }\n\n return context\n}\n"],"mappings":";AAEA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AAiCnC,OAAO,MAAMC,8BAAA,gBAAiCF,aAAA,CAAc,CAAC;AAE7D,OAAO,MAAMG,6BAAA,GAITA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAA,CAAM;EACxB,oBAAOC,IAAA,CAACJ,8BAAA;IAA+BK,KAAA,EAAOF,IAAA;cAAOD;;AACvD;AAEA,OAAO,MAAMI,wBAAA,GAA2BA,CAAA;EACtC,MAAMC,OAAA,GAAUR,GAAA,CAAIC,8BAAA;EAEpB,IAAI,CAACO,OAAA,EAAS;IACZ,MAAM,IAAIC,KAAA,CAAM;EAClB;EAEA,OAAOD,OAAA;AACT","ignoreList":[]}