@payloadcms/ui 3.2.1 → 3.2.2-canary.317488d
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/elements/Button/types.d.ts +8 -0
- package/dist/elements/Button/types.d.ts.map +1 -1
- package/dist/elements/Button/types.js.map +1 -1
- package/dist/elements/DocumentDrawer/Provider.d.ts +2 -2
- package/dist/elements/DocumentDrawer/Provider.d.ts.map +1 -1
- package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
- package/dist/elements/DocumentFields/index.d.ts.map +1 -1
- package/dist/elements/DocumentFields/index.js +53 -92
- package/dist/elements/DocumentFields/index.js.map +1 -1
- package/dist/exports/client/{CodeEditor-DRTCMRCY.js → CodeEditor-5MCGR4GL.js} +2 -2
- package/dist/exports/client/chunk-4SO5UCQD.js +14 -0
- package/dist/exports/client/chunk-4SO5UCQD.js.map +8 -0
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +3 -3
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +11 -1
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
- package/dist/forms/Form/mergeServerFormState.js.map +1 -1
- package/dist/forms/Form/types.d.ts +1 -1
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/Submit/index.d.ts.map +1 -1
- package/dist/forms/Submit/index.js +6 -4
- package/dist/forms/Submit/index.js.map +1 -1
- package/dist/providers/Config/index.d.ts.map +1 -1
- package/dist/providers/Config/index.js +34 -19
- package/dist/providers/Config/index.js.map +1 -1
- package/dist/providers/ListQuery/index.d.ts.map +1 -1
- package/dist/providers/ListQuery/index.js +5 -6
- package/dist/providers/ListQuery/index.js.map +1 -1
- package/dist/providers/SearchParams/index.d.ts +2 -0
- package/dist/providers/SearchParams/index.d.ts.map +1 -1
- package/dist/providers/SearchParams/index.js +24 -28
- package/dist/providers/SearchParams/index.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts +6 -5
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/views/Edit/index.d.ts +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +76 -51
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/exports/client/chunk-PNHVQDTJ.js +0 -14
- package/dist/exports/client/chunk-PNHVQDTJ.js.map +0 -8
- /package/dist/exports/client/{CodeEditor-DRTCMRCY.js.map → CodeEditor-5MCGR4GL.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useRouter","isNumber","qs","React","createContext","useCallback","useContext","useEffect","useState","useListDrawerContext","usePreferences","useSearchParams","Context","useListQuery","ListQueryProvider","children","collectionSlug","data","defaultLimit","defaultSort","modifySearchParams","onQueryChange","onQueryChangeFromProps","preferenceKey","router","setPreference","searchParams","currentQuery","setCurrentQuery","refineListData","query","pageQuery","page","updatedPreferences","updatePreferences","limit","Number","sort","newQuery","search","where","replace","stringify","addQueryPrefix","onChangeFn","handlePageChange","arg","String","handlePerPageChange","handleSearchChange","undefined","handleSortChange","handleWhereChange","shouldUpdateQueryString","_jsx","Provider","value"],"sources":["../../../src/providers/ListQuery/index.tsx"],"sourcesContent":["'use client'\nimport type { ListQuery, PaginatedDocs, Where } from 'payload'\n\nimport { useRouter } from 'next/navigation.js'\nimport { isNumber } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useState } from 'react'\n\nimport type { Column } from '../../elements/Table/index.js'\n\nimport { useListDrawerContext } from '../../elements/ListDrawer/Provider.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { useSearchParams } from '../SearchParams/index.js'\n\nexport type ColumnPreferences = Pick<Column, 'accessor' | 'active'>[]\n\ntype ContextHandlers = {\n handlePageChange?: (page: number) => Promise<void>\n handlePerPageChange?: (limit: number) => Promise<void>\n handleSearchChange?: (search: string) => Promise<void>\n handleSortChange?: (sort: string) => Promise<void>\n handleWhereChange?: (where: Where) => Promise<void>\n}\n\nexport type ListQueryProps = {\n readonly children: React.ReactNode\n readonly collectionSlug: string\n readonly data: PaginatedDocs\n readonly defaultLimit?: number\n readonly defaultSort?: string\n readonly modifySearchParams?: boolean\n readonly onQueryChange?: (query: ListQuery) => void\n readonly preferenceKey?: string\n}\n\nexport type ListQueryContext = {\n data: PaginatedDocs\n defaultLimit?: number\n defaultSort?: string\n query: ListQuery\n refineListData: (args: ListQuery) => Promise<void>\n} & ContextHandlers\n\nconst Context = createContext({} as ListQueryContext)\n\nexport const useListQuery = (): ListQueryContext => useContext(Context)\n\nexport const ListQueryProvider: React.FC<ListQueryProps> = ({\n children,\n collectionSlug,\n data,\n defaultLimit,\n defaultSort,\n modifySearchParams,\n onQueryChange: onQueryChangeFromProps,\n preferenceKey,\n}) => {\n 'use no memo'\n const router = useRouter()\n const { setPreference } = usePreferences()\n const { searchParams } = useSearchParams()\n\n const { onQueryChange } = useListDrawerContext()\n\n const [currentQuery, setCurrentQuery] = useState(() => {\n if (modifySearchParams) {\n return searchParams\n } else {\n return {}\n }\n })\n\n useEffect(() => {\n if (modifySearchParams) {\n setCurrentQuery(searchParams)\n }\n }, [searchParams, modifySearchParams])\n\n const refineListData = useCallback(\n async (query: ListQuery) => {\n let pageQuery = 'page' in query ? query.page : currentQuery?.page\n\n if ('where' in query || 'search' in query) {\n pageQuery = '1'\n }\n\n const updatedPreferences: Record<string, unknown> = {}\n let updatePreferences = false\n\n if ('limit' in query) {\n updatedPreferences.limit = Number(query.limit)\n updatePreferences = true\n }\n\n if ('sort' in query) {\n updatedPreferences.sort = query.sort\n updatePreferences = true\n }\n\n if (updatePreferences && preferenceKey) {\n await setPreference(preferenceKey, updatedPreferences, true)\n }\n\n const newQuery: ListQuery = {\n limit: 'limit' in query ? query.limit : (currentQuery?.limit as string),\n page: pageQuery as string,\n search: 'search' in query ? query.search : (currentQuery?.search as string),\n sort: 'sort' in query ? query.sort : (currentQuery?.sort as string),\n where: 'where' in query ? query.where : (currentQuery?.where as Where),\n }\n\n if (modifySearchParams) {\n router.replace(`${qs.stringify(newQuery, { addQueryPrefix: true })}`)\n } else if (\n typeof onQueryChange === 'function' ||\n typeof onQueryChangeFromProps === 'function'\n ) {\n const onChangeFn = onQueryChange || onQueryChangeFromProps\n onChangeFn(newQuery)\n }\n },\n [\n modifySearchParams,\n currentQuery?.page,\n currentQuery?.limit,\n currentQuery?.sort,\n currentQuery?.where,\n currentQuery?.search,\n preferenceKey,\n router,\n setPreference,\n onQueryChange,\n onQueryChangeFromProps,\n ],\n )\n\n const handlePageChange = useCallback(\n async (arg: number) => {\n await refineListData({ page: String(arg) })\n },\n [refineListData],\n )\n\n const handlePerPageChange = React.useCallback(\n async (arg: number) => {\n await refineListData({ limit: String(arg), page: '1' })\n },\n [refineListData],\n )\n\n const handleSearchChange = useCallback(\n async (arg: string) => {\n const search = arg === '' ? undefined : arg\n await refineListData({ search })\n },\n [refineListData],\n )\n\n const handleSortChange = useCallback(\n async (arg: string) => {\n await refineListData({ sort: arg })\n },\n [refineListData],\n )\n\n const handleWhereChange = useCallback(\n async (arg: Where) => {\n await refineListData({ where: arg })\n },\n [refineListData],\n )\n\n useEffect(() => {\n if (modifySearchParams) {\n let shouldUpdateQueryString = false\n\n if (isNumber(defaultLimit) && !('limit' in currentQuery)) {\n currentQuery.limit = String(defaultLimit)\n shouldUpdateQueryString = true\n }\n\n if (defaultSort && !('sort' in currentQuery)) {\n currentQuery.sort = defaultSort\n shouldUpdateQueryString = true\n }\n\n setCurrentQuery(currentQuery)\n\n if (shouldUpdateQueryString) {\n router.replace(`?${qs.stringify(currentQuery)}`)\n }\n }\n }, [defaultSort, defaultLimit, router, modifySearchParams, currentQuery])\n\n return (\n <Context.Provider\n value={{\n data,\n handlePageChange,\n handlePerPageChange,\n handleSearchChange,\n handleSortChange,\n handleW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,IAAe,EAAE,UAAUQ,YAAW,GAAI;QAC5CA,YAAA,CAAaU,IAAI,GAAGlB,WAAA;QACpBkC,uBAAA,GAA0B;MAC5B;MAEAzB,eAAA,CAAgBD,YAAA;MAEhB,IAAI0B,uBAAA,EAAyB;QAC3B7B,MAAA,CAAOiB,OAAO,CAAC,IAAIvC,EAAA,CAAGwC,SAAS,CAACf,YAAA,GAAe;MACjD;IACF;EACF,GAAG,CAACR,WAAA,EAAaD,YAAA,EAAcM,MAAA,EAAQJ,kBAAA,EAAoBO,YAAA,CAAa;EAExE,oBACE2B,IAAA,CAAC1C,OAAA,CAAQ2C,QAAQ;IACfC,KAAA,EAAO;MACLvC,IAAA;MACA4B,gBAAA;MACAG,mBAAA;MACAC,kBAAA;MACAE,gBAAA;MACAC,iBAAA;MACAtB,KAAA,EAAOH,YAAA;MACPE;IACF;cAECd;;AAGP","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useRouter","useSearchParams","isNumber","qs","React","createContext","useCallback","useContext","useEffect","useMemo","useState","useListDrawerContext","usePreferences","createParams","Context","useListQuery","ListQueryProvider","children","collectionSlug","data","defaultLimit","defaultSort","modifySearchParams","onQueryChange","onQueryChangeFromProps","preferenceKey","router","setPreference","rawSearchParams","searchParams","currentQuery","setCurrentQuery","refineListData","query","pageQuery","page","updatedPreferences","updatePreferences","limit","Number","sort","newQuery","search","where","replace","stringify","addQueryPrefix","onChangeFn","handlePageChange","arg","String","handlePerPageChange","handleSearchChange","undefined","handleSortChange","handleWhereChange","shouldUpdateQueryString","_jsx","Provider","value"],"sources":["../../../src/providers/ListQuery/index.tsx"],"sourcesContent":["'use client'\nimport type { ListQuery, PaginatedDocs, Where } from 'payload'\n\nimport { useRouter, useSearchParams } from 'next/navigation.js'\nimport { isNumber } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\n\nimport type { Column } from '../../elements/Table/index.js'\n\nimport { useListDrawerContext } from '../../elements/ListDrawer/Provider.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { createParams } from '../SearchParams/index.js'\n\nexport type ColumnPreferences = Pick<Column, 'accessor' | 'active'>[]\n\ntype ContextHandlers = {\n handlePageChange?: (page: number) => Promise<void>\n handlePerPageChange?: (limit: number) => Promise<void>\n handleSearchChange?: (search: string) => Promise<void>\n handleSortChange?: (sort: string) => Promise<void>\n handleWhereChange?: (where: Where) => Promise<void>\n}\n\nexport type ListQueryProps = {\n readonly children: React.ReactNode\n readonly collectionSlug: string\n readonly data: PaginatedDocs\n readonly defaultLimit?: number\n readonly defaultSort?: string\n readonly modifySearchParams?: boolean\n readonly onQueryChange?: (query: ListQuery) => void\n readonly preferenceKey?: string\n}\n\nexport type ListQueryContext = {\n data: PaginatedDocs\n defaultLimit?: number\n defaultSort?: string\n query: ListQuery\n refineListData: (args: ListQuery) => Promise<void>\n} & ContextHandlers\n\nconst Context = createContext({} as ListQueryContext)\n\nexport const useListQuery = (): ListQueryContext => useContext(Context)\n\nexport const ListQueryProvider: React.FC<ListQueryProps> = ({\n children,\n collectionSlug,\n data,\n defaultLimit,\n defaultSort,\n modifySearchParams,\n onQueryChange: onQueryChangeFromProps,\n preferenceKey,\n}) => {\n 'use no memo'\n const router = useRouter()\n const { setPreference } = usePreferences()\n const rawSearchParams = useSearchParams()\n const searchParams = useMemo(() => createParams(rawSearchParams), [rawSearchParams])\n\n const { onQueryChange } = useListDrawerContext()\n\n const [currentQuery, setCurrentQuery] = useState(() => {\n if (modifySearchParams) {\n return searchParams\n } else {\n return {}\n }\n })\n\n useEffect(() => {\n if (modifySearchParams) {\n setCurrentQuery(searchParams)\n }\n }, [searchParams, modifySearchParams])\n\n const refineListData = useCallback(\n async (query: ListQuery) => {\n let pageQuery = 'page' in query ? query.page : currentQuery?.page\n\n if ('where' in query || 'search' in query) {\n pageQuery = '1'\n }\n\n const updatedPreferences: Record<string, unknown> = {}\n let updatePreferences = false\n\n if ('limit' in query) {\n updatedPreferences.limit = Number(query.limit)\n updatePreferences = true\n }\n\n if ('sort' in query) {\n updatedPreferences.sort = query.sort\n updatePreferences = true\n }\n\n if (updatePreferences && preferenceKey) {\n await setPreference(preferenceKey, updatedPreferences, true)\n }\n\n const newQuery: ListQuery = {\n limit: 'limit' in query ? query.limit : (currentQuery?.limit as string),\n page: pageQuery as string,\n search: 'search' in query ? query.search : (currentQuery?.search as string),\n sort: 'sort' in query ? query.sort : (currentQuery?.sort as string),\n where: 'where' in query ? query.where : (currentQuery?.where as Where),\n }\n\n if (modifySearchParams) {\n router.replace(`${qs.stringify(newQuery, { addQueryPrefix: true })}`)\n } else if (\n typeof onQueryChange === 'function' ||\n typeof onQueryChangeFromProps === 'function'\n ) {\n const onChangeFn = onQueryChange || onQueryChangeFromProps\n onChangeFn(newQuery)\n }\n },\n [\n modifySearchParams,\n currentQuery?.page,\n currentQuery?.limit,\n currentQuery?.sort,\n currentQuery?.where,\n currentQuery?.search,\n preferenceKey,\n router,\n setPreference,\n onQueryChange,\n onQueryChangeFromProps,\n ],\n )\n\n const handlePageChange = useCallback(\n async (arg: number) => {\n await refineListData({ page: String(arg) })\n },\n [refineListData],\n )\n\n const handlePerPageChange = React.useCallback(\n async (arg: number) => {\n await refineListData({ limit: String(arg), page: '1' })\n },\n [refineListData],\n )\n\n const handleSearchChange = useCallback(\n async (arg: string) => {\n const search = arg === '' ? undefined : arg\n await refineListData({ search })\n },\n [refineListData],\n )\n\n const handleSortChange = useCallback(\n async (arg: string) => {\n await refineListData({ sort: arg })\n },\n [refineListData],\n )\n\n const handleWhereChange = useCallback(\n async (arg: Where) => {\n await refineListData({ where: arg })\n },\n [refineListData],\n )\n\n useEffect(() => {\n if (modifySearchParams) {\n let shouldUpdateQueryString = false\n\n if (isNumber(defaultLimit) && !('limit' in currentQuery)) {\n currentQuery.limit = String(defaultLimit)\n shouldUpdateQueryString = true\n }\n\n if (defaultSort && !('sort' in currentQuery)) {\n currentQuery.sort = defaultSort\n shouldUpdateQueryString = true\n }\n\n setCurrentQuery(currentQuery)\n\n if (shouldUpdateQueryString) {\n router.replace(`?${qs.stringify(currentQuery)}`)\n }\n }\n }, [defaultSort, defaultLimit, router, modifySearchParams, currentQuery])\n\n return (\n <Context.Provider\n value={{\n data,\n handlePageChange,\n handlePerPageChange,\n handleSearchChange,\n handleSortChange,\n handleWhereChange,\n query: currentQuery,\n refineListData,\n }}\n >\n {children}\n </Context.Provider>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,SAAS,EAAEC,eAAe,QAAQ;AAC3C,SAASC,QAAQ,QAAQ;AACzB,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAI5F,SAASC,oBAAoB,QAAQ;AACrC,SAASC,cAAc,QAAQ;AAC/B,SAASC,YAAY,QAAQ;AA+B7B,MAAMC,OAAA,gBAAUT,aAAA,CAAc,CAAC;AAE/B,OAAO,MAAMU,YAAA,GAAeA,CAAA;EAAA,OAAwBR,UAAA,CAAAO,OAAW;AAAA;AAE/D,OAAO,MAAME,iBAAA,GAA8CA,CAAC;EAC1DC,QAAQ;EACRC,cAAc;EACdC,IAAI;EACJC,YAAY;EACZC,WAAW;EACXC,kBAAkB;EAClBC,aAAA,EAAeC,sBAAsB;EACrCC;AAAa,CACd;EACC;;EACA,MAAMC,MAAA,GAAS1B,SAAA;EACf,MAAM;IAAE2B;EAAa,CAAE,GAAGf,cAAA;EAC1B,MAAMgB,eAAA,GAAkB3B,eAAA;EACxB,MAAM4B,YAAA,GAAepB,OAAA,CAAQ,MAAMI,YAAA,CAAae,eAAA,GAAkB,CAACA,eAAA,CAAgB;EAEnF,MAAM;IAAEL;EAAa,CAAE,GAAGZ,oBAAA;EAE1B,MAAM,CAACmB,YAAA,EAAcC,eAAA,CAAgB,GAAGrB,QAAA,CAAS;IAC/C,IAAIY,kBAAA,EAAoB;MACtB,O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,MAAMjB,cAAA,CAAe;MAAEW,KAAA,EAAOM;IAAI;EACpC,GACA,CAACjB,cAAA,CAAe;EAGlBxB,SAAA,CAAU;IACR,IAAIc,kBAAA,EAAoB;MACtB,IAAIkC,uBAAA,GAA0B;MAE9B,IAAItD,QAAA,CAASkB,YAAA,KAAiB,EAAE,WAAWU,YAAW,GAAI;QACxDA,YAAA,CAAaQ,KAAK,GAAGY,MAAA,CAAO9B,YAAA;QAC5BoC,uBAAA,GAA0B;MAC5B;MAEA,IAAInC,WAAA,IAAe,EAAE,UAAUS,YAAW,GAAI;QAC5CA,YAAA,CAAaU,IAAI,GAAGnB,WAAA;QACpBmC,uBAAA,GAA0B;MAC5B;MAEAzB,eAAA,CAAgBD,YAAA;MAEhB,IAAI0B,uBAAA,EAAyB;QAC3B9B,MAAA,CAAOkB,OAAO,CAAC,IAAIzC,EAAA,CAAG0C,SAAS,CAACf,YAAA,GAAe;MACjD;IACF;EACF,GAAG,CAACT,WAAA,EAAaD,YAAA,EAAcM,MAAA,EAAQJ,kBAAA,EAAoBQ,YAAA,CAAa;EAExE,oBACE2B,IAAA,CAAC3C,OAAA,CAAQ4C,QAAQ;IACfC,KAAA,EAAO;MACLxC,IAAA;MACA6B,gBAAA;MACAG,mBAAA;MACAC,kBAAA;MACAE,gBAAA;MACAC,iBAAA;MACAtB,KAAA,EAAOH,YAAA;MACPE;IACF;cAECf;;AAGP","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReadonlyURLSearchParams } from 'next/navigation.js';
|
|
1
2
|
import * as qs from 'qs-esm';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
export type SearchParamsContext = {
|
|
@@ -8,6 +9,7 @@ export type SearchParamsContext = {
|
|
|
8
9
|
}) => string;
|
|
9
10
|
};
|
|
10
11
|
export type State = qs.ParsedQs;
|
|
12
|
+
export declare function createParams(params: ReadonlyURLSearchParams): State;
|
|
11
13
|
export declare const SearchParamsProvider: React.FC<{
|
|
12
14
|
children?: React.ReactNode;
|
|
13
15
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/SearchParams/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/SearchParams/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAGjE,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,KAAoC,MAAM,OAAO,CAAA;AAExD,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,EAAE,CAAC,QAAQ,CAAA;IACzB,eAAe,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,MAAM,CAAA;CACvF,CAAA;AAED,MAAM,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAA;AAS/B,wBAAgB,YAAY,CAAC,MAAM,EAAE,uBAAuB,GAAG,KAAK,CAOnE;AAGD,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAuBzE,CAAA;AAED,eAAO,MAAM,eAAe,QAAO,mBAA0C,CAAA"}
|
|
@@ -10,35 +10,31 @@ const initialContext = {
|
|
|
10
10
|
stringifyParams: () => ''
|
|
11
11
|
};
|
|
12
12
|
const Context = /*#__PURE__*/createContext(initialContext);
|
|
13
|
-
function createParams(
|
|
13
|
+
export function createParams(params) {
|
|
14
|
+
const search = params.toString();
|
|
14
15
|
return qs.parse(search, {
|
|
15
16
|
depth: 10,
|
|
16
17
|
ignoreQueryPrefix: true
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
|
-
// TODO:
|
|
20
|
+
// TODO: this provider should likely be marked as deprecated and then removed in the next major release
|
|
20
21
|
export const SearchParamsProvider = t0 => {
|
|
21
|
-
const $ = _c(
|
|
22
|
+
const $ = _c(11);
|
|
22
23
|
const {
|
|
23
24
|
children
|
|
24
25
|
} = t0;
|
|
25
26
|
const nextSearchParams = useNextSearchParams();
|
|
26
27
|
let t1;
|
|
27
|
-
let searchString;
|
|
28
28
|
if ($[0] !== nextSearchParams) {
|
|
29
|
-
|
|
30
|
-
t1 = createParams(searchString);
|
|
29
|
+
t1 = () => createParams(nextSearchParams);
|
|
31
30
|
$[0] = nextSearchParams;
|
|
32
31
|
$[1] = t1;
|
|
33
|
-
$[2] = searchString;
|
|
34
32
|
} else {
|
|
35
33
|
t1 = $[1];
|
|
36
|
-
searchString = $[2];
|
|
37
34
|
}
|
|
38
|
-
const
|
|
39
|
-
const [searchParams, setSearchParams] = React.useState(initialParams);
|
|
35
|
+
const [searchParams, setSearchParams] = React.useState(t1);
|
|
40
36
|
let t2;
|
|
41
|
-
if ($[
|
|
37
|
+
if ($[2] !== searchParams) {
|
|
42
38
|
t2 = t3 => {
|
|
43
39
|
const {
|
|
44
40
|
params,
|
|
@@ -52,29 +48,29 @@ export const SearchParamsProvider = t0 => {
|
|
|
52
48
|
addQueryPrefix: true
|
|
53
49
|
});
|
|
54
50
|
};
|
|
55
|
-
$[
|
|
56
|
-
$[
|
|
51
|
+
$[2] = searchParams;
|
|
52
|
+
$[3] = t2;
|
|
57
53
|
} else {
|
|
58
|
-
t2 = $[
|
|
54
|
+
t2 = $[3];
|
|
59
55
|
}
|
|
60
56
|
const stringifyParams = t2;
|
|
61
57
|
let t3;
|
|
62
58
|
let t4;
|
|
63
|
-
if ($[
|
|
59
|
+
if ($[4] !== nextSearchParams) {
|
|
64
60
|
t3 = () => {
|
|
65
|
-
setSearchParams(createParams(
|
|
61
|
+
setSearchParams(createParams(nextSearchParams));
|
|
66
62
|
};
|
|
67
|
-
t4 = [
|
|
68
|
-
$[
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
63
|
+
t4 = [nextSearchParams];
|
|
64
|
+
$[4] = nextSearchParams;
|
|
65
|
+
$[5] = t3;
|
|
66
|
+
$[6] = t4;
|
|
71
67
|
} else {
|
|
72
|
-
t3 = $[
|
|
73
|
-
t4 = $[
|
|
68
|
+
t3 = $[5];
|
|
69
|
+
t4 = $[6];
|
|
74
70
|
}
|
|
75
71
|
React.useEffect(t3, t4);
|
|
76
72
|
let t5;
|
|
77
|
-
if ($[
|
|
73
|
+
if ($[7] !== searchParams || $[8] !== stringifyParams || $[9] !== children) {
|
|
78
74
|
t5 = _jsx(Context.Provider, {
|
|
79
75
|
value: {
|
|
80
76
|
searchParams,
|
|
@@ -82,12 +78,12 @@ export const SearchParamsProvider = t0 => {
|
|
|
82
78
|
},
|
|
83
79
|
children
|
|
84
80
|
});
|
|
85
|
-
$[
|
|
86
|
-
$[
|
|
87
|
-
$[
|
|
88
|
-
$[
|
|
81
|
+
$[7] = searchParams;
|
|
82
|
+
$[8] = stringifyParams;
|
|
83
|
+
$[9] = children;
|
|
84
|
+
$[10] = t5;
|
|
89
85
|
} else {
|
|
90
|
-
t5 = $[
|
|
86
|
+
t5 = $[10];
|
|
91
87
|
}
|
|
92
88
|
return t5;
|
|
93
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useSearchParams","useNextSearchParams","qs","React","createContext","useContext","initialContext","searchParams","stringifyParams","Context","createParams","search","parse","depth","ignoreQueryPrefix","SearchParamsProvider","t0","$","children","nextSearchParams","t1","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useSearchParams","useNextSearchParams","qs","React","createContext","useContext","initialContext","searchParams","stringifyParams","Context","createParams","params","search","toString","parse","depth","ignoreQueryPrefix","SearchParamsProvider","t0","$","children","nextSearchParams","t1","setSearchParams","useState","t2","t3","replace","t4","undefined","stringify","addQueryPrefix","useEffect","t5","_jsx","Provider","value"],"sources":["../../../src/providers/SearchParams/index.tsx"],"sourcesContent":["'use client'\nimport type { ReadonlyURLSearchParams } from 'next/navigation.js'\n\nimport { useSearchParams as useNextSearchParams } from 'next/navigation.js'\nimport * as qs from 'qs-esm'\nimport React, { createContext, useContext } from 'react'\n\nexport type SearchParamsContext = {\n searchParams: qs.ParsedQs\n stringifyParams: ({ params, replace }: { params: State; replace?: boolean }) => string\n}\n\nexport type State = qs.ParsedQs\n\nconst initialContext: SearchParamsContext = {\n searchParams: {},\n stringifyParams: () => '',\n}\n\nconst Context = createContext(initialContext)\n\nexport function createParams(params: ReadonlyURLSearchParams): State {\n const search = params.toString()\n\n return qs.parse(search, {\n depth: 10,\n ignoreQueryPrefix: true,\n })\n}\n\n// TODO: this provider should likely be marked as deprecated and then removed in the next major release\nexport const SearchParamsProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const nextSearchParams = useNextSearchParams()\n\n const [searchParams, setSearchParams] = React.useState(() => createParams(nextSearchParams))\n\n const stringifyParams = React.useCallback(\n ({ params, replace = false }: { params: State; replace?: boolean }) => {\n return qs.stringify(\n {\n ...(replace ? {} : searchParams),\n ...params,\n },\n { addQueryPrefix: true },\n )\n },\n [searchParams],\n )\n\n React.useEffect(() => {\n setSearchParams(createParams(nextSearchParams))\n }, [nextSearchParams])\n\n return <Context.Provider value={{ searchParams, stringifyParams }}>{children}</Context.Provider>\n}\n\nexport const useSearchParams = (): SearchParamsContext => useContext(Context)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,eAAA,IAAmBC,mBAAmB,QAAQ;AACvD,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,UAAU,QAAQ;AASjD,MAAMC,cAAA,GAAsC;EAC1CC,YAAA,EAAc,CAAC;EACfC,eAAA,EAAiBA,CAAA,KAAM;AACzB;AAEA,MAAMC,OAAA,gBAAUL,aAAA,CAAcE,cAAA;AAE9B,OAAO,SAASI,aAAaC,MAA+B;EAC1D,MAAMC,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AA,MAAAO,EAAA;IAAAP,CAAA,MAAAS,EAAA;EAAA;IAAAF,EAAA,GAAAP,CAAA;IAAAS,EAAA,GAAAT,CAAA;EAAA;EAFrBhB,KAAA,CAAA6B,SAAA,CAAgBN,EAEhB,EAAGE,EAAkB;EAAA,IAAAK,EAAA;EAAA,IAAAd,CAAA,QAAAZ,YAAA,IAAAY,CAAA,QAAAX,eAAA,IAAAW,CAAA,QAAAC,QAAA;IAEda,EAAA,GAAAC,IAAA,CAAAzB,OAAA,CAAA0B,QAAA;MAAAC,KAAA;QAAA7B,YAAA;QAAAC;MAAA;MAAAY;IAAA,C;;;;;;;;SAAAa,E;CACT;AAEA,OAAO,MAAMjC,eAAA,GAAkBA,CAAA;EAAA,OAA2BK,UAAA,CAAAI,OAAW;AAAA","ignoreList":[]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FormState } from 'payload';
|
|
2
|
+
export type LockedState = {
|
|
3
|
+
isLocked: boolean;
|
|
4
|
+
lastEditedAt: string;
|
|
5
|
+
user: ClientUser | number | string;
|
|
6
|
+
};
|
|
2
7
|
type BuildFormStateSuccessResult = {
|
|
3
8
|
clientConfig?: ClientConfig;
|
|
4
9
|
errors?: never;
|
|
5
10
|
indexPath?: string;
|
|
6
|
-
lockedState?:
|
|
7
|
-
isLocked: boolean;
|
|
8
|
-
lastEditedAt: string;
|
|
9
|
-
user: ClientUser | number | string;
|
|
10
|
-
};
|
|
11
|
+
lockedState?: LockedState;
|
|
11
12
|
state: FormState;
|
|
12
13
|
};
|
|
13
14
|
type BuildFormStateErrorResult = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAYnG,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAYnG,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;CACnC,CAAA;AAED,KAAK,2BAA2B,GAAG;IACjC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,2BAA2B,CAAA;AAE1F,eAAO,MAAM,qBAAqB,SAC1B,kBAAkB,KACvB,OAAO,CAAC,oBAAoB,CAqD9B,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,kBAAkB,KACvB,OAAO,CAAC,2BAA2B,CA4HrC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.js","names":["formatErrors","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","buildFormStateHandler","args","req","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","docs","length","res","buildFormState","err","logger","error","msg","message","id","idFromArgs","collectionSlug","data","incomingData","docPermissions","docPreferences","formState","globalSlug","operation","renderAllFields","i18n","returnLockStatus","schemaPath","updateLastEdited","schemaMap","clientSchemaMap","importMap","undefined","fieldOrEntityConfig","get","fields","type","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","upload","file","lockedStateResult","lockedState","state"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FormState } from 'payload'\n\nimport { formatErrors } from 'payload'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n lockedState?: { isLocked: boolean; lastEditedAt: string; user: ClientUser | number | string }\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n lockedState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateResult> => {\n const { req } = args\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n try {\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n throw new Error('Unauthorized')\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n throw new Error('Unauthorized')\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n throw new Error('Unauthorized')\n }\n }\n\n const res = await buildFormState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n formState,\n globalSlug,\n operation,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLockStatus,\n schemaPath = collectionSlug || globalSlug,\n updateLastEdited,\n } = args\n\n let data = incomingData\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({ config, i18n, importMap: req.payload.importMap }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) {\n data = reduceFieldsToValues(formState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n fields,\n fieldSchemaMap: schemaMap,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n return {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\n}\n"],"mappings":"AAEA,SAASA,YAAY,QAAQ;AAC7B,SAASC,oBAAoB,QAAQ;AAErC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AAsBvC,OAAO,MAAMC,qBAAA,GAAwB,MACnCC,IAAA;EAEA,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,MAAME,gBAAA,GAAmBD,GAAA,CAAIE,IAAI,EAAEC,UAAA;EACnC,MAAMC,aAAA,GAAgBJ,GAAA,CAAIK,OAAO,CAACC,MAAM,CAACC,KAAK,CAACL,IAAI;EAEnD,IAAI;IACF;IACA,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;;;;EASA,MAAMc,MAAA,GAASE,KAAA,CAAMC,OAAO,CAACL,mBAAA,IACzBA,mBAAA,GACA,YAAYA,mBAAA,GACVA,mBAAA,CAAoBE,MAAM,GAC1B,CAACF,mBAAA,CAAoB;EAE3B,MAAMM,eAAA,GAAkB,MAAM5D,uBAAA,CAAwB;IACpDmC,EAAA;IACA0B,oBAAA,EAAsBV,eAAA;IACtBd,cAAA;IACAC,IAAA;IACAkB,MAAA;IACAM,cAAA,EAAgBZ,SAAA;IAChBN,SAAA;IACAmB,WAAA,EAAavB,cAAA,EAAgBgB,MAAA,IAAU,CAAC;IACxCQ,WAAA,EAAavB,cAAA,IAAkB;MAAEe,MAAA,EAAQ,CAAC;IAAE;IAC5CS,iBAAA,EAAmBvB,SAAA;IACnBG,eAAA;IACAqB,aAAA,EAAejE,WAAA;IACfO,GAAA;IACAwC;EACF;EAEA;EACA,IAAIX,cAAA,IAAkBK,SAAA,EAAW;IAC/B,IAAI7B,OAAA,CAAQI,WAAW,CAACoB,cAAA,CAAe,EAAEvB,MAAA,EAAQqD,MAAA,IAAUzB,SAAA,CAAU0B,IAAI,EAAE;MACzER,eAAA,CAAgBQ,IAAI,GAAG1B,SAAA,CAAU0B,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAItB,gBAAA,EAAkB;IACpBsB,iBAAA,GAAoB,MAAMhE,sBAAA,CAAuB;MAC/C8B,EAAA;MACAE,cAAA;MACAM,UAAA;MACAnC,GAAA;MACAyC;IACF;EACF;EAEA,OAAO;IACLqB,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOX;EACT;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"buildFormState.js","names":["formatErrors","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","buildFormStateHandler","args","req","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","docs","length","res","buildFormState","err","logger","error","msg","message","id","idFromArgs","collectionSlug","data","incomingData","docPermissions","docPreferences","formState","globalSlug","operation","renderAllFields","i18n","returnLockStatus","schemaPath","updateLastEdited","schemaMap","clientSchemaMap","importMap","undefined","fieldOrEntityConfig","get","fields","type","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","upload","file","lockedStateResult","lockedState","state"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FormState } from 'payload'\n\nimport { formatErrors } from 'payload'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\n\nexport type LockedState = {\n isLocked: boolean\n lastEditedAt: string\n user: ClientUser | number | string\n}\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n lockedState?: LockedState\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n lockedState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateResult> => {\n const { req } = args\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n try {\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n throw new Error('Unauthorized')\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n throw new Error('Unauthorized')\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n throw new Error('Unauthorized')\n }\n }\n\n const res = await buildFormState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n formState,\n globalSlug,\n operation,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLockStatus,\n schemaPath = collectionSlug || globalSlug,\n updateLastEdited,\n } = args\n\n let data = incomingData\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({ config, i18n, importMap: req.payload.importMap }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) {\n data = reduceFieldsToValues(formState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n fields,\n fieldSchemaMap: schemaMap,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n return {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\n}\n"],"mappings":"AAEA,SAASA,YAAY,QAAQ;AAC7B,SAASC,oBAAoB,QAAQ;AAErC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AA4BvC,OAAO,MAAMC,qBAAA,GAAwB,MACnCC,IAAA;EAEA,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,MAAME,gBAAA,GAAmBD,GAAA,CAAIE,IAAI,EAAEC,UAAA;EACnC,MAAMC,aAAA,GAAgBJ,GAAA,CAAIK,OAAO,CAACC,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AAOvC,oBAAA,CAAqB2C,SAAA,EAAW;EACzC;EAEA;;;;;;;;;EASA,MAAMc,MAAA,GAASE,KAAA,CAAMC,OAAO,CAACL,mBAAA,IACzBA,mBAAA,GACA,YAAYA,mBAAA,GACVA,mBAAA,CAAoBE,MAAM,GAC1B,CAACF,mBAAA,CAAoB;EAE3B,MAAMM,eAAA,GAAkB,MAAM5D,uBAAA,CAAwB;IACpDmC,EAAA;IACA0B,oBAAA,EAAsBV,eAAA;IACtBd,cAAA;IACAC,IAAA;IACAkB,MAAA;IACAM,cAAA,EAAgBZ,SAAA;IAChBN,SAAA;IACAmB,WAAA,EAAavB,cAAA,EAAgBgB,MAAA,IAAU,CAAC;IACxCQ,WAAA,EAAavB,cAAA,IAAkB;MAAEe,MAAA,EAAQ,CAAC;IAAE;IAC5CS,iBAAA,EAAmBvB,SAAA;IACnBG,eAAA;IACAqB,aAAA,EAAejE,WAAA;IACfO,GAAA;IACAwC;EACF;EAEA;EACA,IAAIX,cAAA,IAAkBK,SAAA,EAAW;IAC/B,IAAI7B,OAAA,CAAQI,WAAW,CAACoB,cAAA,CAAe,EAAEvB,MAAA,EAAQqD,MAAA,IAAUzB,SAAA,CAAU0B,IAAI,EAAE;MACzER,eAAA,CAAgBQ,IAAI,GAAG1B,SAAA,CAAU0B,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAItB,gBAAA,EAAkB;IACpBsB,iBAAA,GAAoB,MAAMhE,sBAAA,CAAuB;MAC/C8B,EAAA;MACAE,cAAA;MACAM,UAAA;MACAnC,GAAA;MACAyC;IACF;EACF;EAEA,OAAO;IACLqB,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOX;EACT;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/Edit/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/Edit/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,uBAAuB,EAGxB,MAAM,SAAS,CAAA;AAGhB,OAAO,KAA6D,MAAM,OAAO,CAAA;AA8BjF,OAAO,cAAc,CAAA;AAOrB,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAsiB7D,CAAA"}
|
package/dist/views/Edit/index.js
CHANGED
|
@@ -26,9 +26,9 @@ import { handleBackToDashboard } from '../../utilities/handleBackToDashboard.js'
|
|
|
26
26
|
import { handleGoBack } from '../../utilities/handleGoBack.js';
|
|
27
27
|
import { handleTakeOver } from '../../utilities/handleTakeOver.js';
|
|
28
28
|
import { Auth } from './Auth/index.js';
|
|
29
|
-
import './index.scss';
|
|
30
29
|
import { SetDocumentStepNav } from './SetDocumentStepNav/index.js';
|
|
31
30
|
import { SetDocumentTitle } from './SetDocumentTitle/index.js';
|
|
31
|
+
import './index.scss';
|
|
32
32
|
const baseClass = 'collection-edit';
|
|
33
33
|
// This component receives props only on _pages_
|
|
34
34
|
// When rendered within a drawer, props are empty
|
|
@@ -117,6 +117,7 @@ export const DefaultEditView = ({
|
|
|
117
117
|
getFormState
|
|
118
118
|
} = useServerFunctions();
|
|
119
119
|
const onChangeAbortControllerRef = useRef(null);
|
|
120
|
+
const onSaveAbortControllerRef = useRef(null);
|
|
120
121
|
const locale = params.get('locale');
|
|
121
122
|
const entitySlug = collectionConfig?.slug || globalConfig?.slug;
|
|
122
123
|
const operation = collectionSlug && !id ? 'create' : 'update';
|
|
@@ -130,10 +131,13 @@ export const DefaultEditView = ({
|
|
|
130
131
|
const lockDuration = typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault;
|
|
131
132
|
const lockDurationInMilliseconds = lockDuration * 1000;
|
|
132
133
|
let preventLeaveWithoutSaving = true;
|
|
134
|
+
let autosaveEnabled = false;
|
|
133
135
|
if (collectionConfig) {
|
|
134
|
-
|
|
136
|
+
autosaveEnabled = Boolean(collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.autosave);
|
|
137
|
+
preventLeaveWithoutSaving = !autosaveEnabled;
|
|
135
138
|
} else if (globalConfig) {
|
|
136
|
-
|
|
139
|
+
autosaveEnabled = Boolean(globalConfig?.versions?.drafts && globalConfig?.versions?.drafts?.autosave);
|
|
140
|
+
preventLeaveWithoutSaving = !autosaveEnabled;
|
|
137
141
|
} else if (typeof disableLeaveWithoutSaving !== 'undefined') {
|
|
138
142
|
preventLeaveWithoutSaving = !disableLeaveWithoutSaving;
|
|
139
143
|
}
|
|
@@ -166,6 +170,25 @@ export const DefaultEditView = ({
|
|
|
166
170
|
}
|
|
167
171
|
return false;
|
|
168
172
|
});
|
|
173
|
+
const handleDocumentLocking = useCallback(lockedState => {
|
|
174
|
+
setDocumentIsLocked(true);
|
|
175
|
+
const previousOwnerId = typeof documentLockStateRef.current?.user === 'object' ? documentLockStateRef.current?.user?.id : documentLockStateRef.current?.user;
|
|
176
|
+
if (lockedState) {
|
|
177
|
+
const lockedUserID = typeof lockedState.user === 'string' || typeof lockedState.user === 'number' ? lockedState.user : lockedState.user.id;
|
|
178
|
+
if (!documentLockStateRef.current || lockedUserID !== previousOwnerId) {
|
|
179
|
+
if (previousOwnerId === user.id && lockedUserID !== user.id) {
|
|
180
|
+
setShowTakeOverModal(true);
|
|
181
|
+
documentLockStateRef.current.hasShownLockedModal = true;
|
|
182
|
+
}
|
|
183
|
+
documentLockStateRef.current = {
|
|
184
|
+
hasShownLockedModal: documentLockStateRef.current?.hasShownLockedModal || false,
|
|
185
|
+
isLocked: true,
|
|
186
|
+
user: lockedState.user
|
|
187
|
+
};
|
|
188
|
+
setCurrentEditor(lockedState.user);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}, [setCurrentEditor, setDocumentIsLocked, user.id]);
|
|
169
192
|
const onSave = useCallback(async json => {
|
|
170
193
|
reportUpdate({
|
|
171
194
|
id,
|
|
@@ -187,10 +210,6 @@ export const DefaultEditView = ({
|
|
|
187
210
|
operation: id ? 'update' : 'create'
|
|
188
211
|
});
|
|
189
212
|
}
|
|
190
|
-
// Unlock the document after save
|
|
191
|
-
if ((id || globalSlug) && isLockingEnabled) {
|
|
192
|
-
setDocumentIsLocked(false);
|
|
193
|
-
}
|
|
194
213
|
if (!isEditing && depth < 2) {
|
|
195
214
|
// Redirect to the same locale if it's been set
|
|
196
215
|
const redirectRoute = formatAdminURL({
|
|
@@ -202,13 +221,39 @@ export const DefaultEditView = ({
|
|
|
202
221
|
resetUploadEdits();
|
|
203
222
|
}
|
|
204
223
|
await getDocPermissions(json);
|
|
205
|
-
|
|
224
|
+
if ((id || globalSlug) && !autosaveEnabled) {
|
|
225
|
+
abortAndIgnore(onSaveAbortControllerRef.current);
|
|
226
|
+
const controller = new AbortController();
|
|
227
|
+
onSaveAbortControllerRef.current = controller;
|
|
228
|
+
const docPreferences = await getDocPreferences();
|
|
229
|
+
const {
|
|
230
|
+
state
|
|
231
|
+
} = await getFormState({
|
|
232
|
+
id,
|
|
233
|
+
collectionSlug,
|
|
234
|
+
data: json?.doc,
|
|
235
|
+
docPermissions,
|
|
236
|
+
docPreferences,
|
|
237
|
+
globalSlug,
|
|
238
|
+
operation,
|
|
239
|
+
renderAllFields: true,
|
|
240
|
+
returnLockStatus: false,
|
|
241
|
+
schemaPath: schemaPathSegments.join('.'),
|
|
242
|
+
signal: controller.signal
|
|
243
|
+
});
|
|
244
|
+
// Unlock the document after save
|
|
245
|
+
if (isLockingEnabled) {
|
|
246
|
+
setDocumentIsLocked(false);
|
|
247
|
+
}
|
|
248
|
+
return state;
|
|
249
|
+
}
|
|
250
|
+
}, [adminRoute, collectionSlug, depth, docPermissions, entitySlug, getDocPermissions, getDocPreferences, getFormState, globalSlug, id, incrementVersionCount, isEditing, isLockingEnabled, locale, onSaveFromContext, operation, refreshCookieAsync, reportUpdate, resetUploadEdits, router, schemaPathSegments, setDocumentIsLocked, updateSavedDocumentData, user, userSlug, autosaveEnabled]);
|
|
206
251
|
const onChange = useCallback(async ({
|
|
207
252
|
formState: prevFormState
|
|
208
253
|
}) => {
|
|
209
254
|
abortAndIgnore(onChangeAbortControllerRef.current);
|
|
210
|
-
const
|
|
211
|
-
onChangeAbortControllerRef.current =
|
|
255
|
+
const controller_0 = new AbortController();
|
|
256
|
+
onChangeAbortControllerRef.current = controller_0;
|
|
212
257
|
const currentTime = Date.now();
|
|
213
258
|
const timeSinceLastUpdate = currentTime - editSessionStartTime;
|
|
214
259
|
const updateLastEdited = isLockingEnabled && timeSinceLastUpdate >= 10000 // 10 seconds
|
|
@@ -216,65 +261,44 @@ export const DefaultEditView = ({
|
|
|
216
261
|
if (updateLastEdited) {
|
|
217
262
|
setEditSessionStartTime(currentTime);
|
|
218
263
|
}
|
|
219
|
-
const
|
|
264
|
+
const docPreferences_0 = await getDocPreferences();
|
|
220
265
|
const {
|
|
221
|
-
lockedState,
|
|
222
|
-
state
|
|
266
|
+
lockedState: lockedState_0,
|
|
267
|
+
state: state_0
|
|
223
268
|
} = await getFormState({
|
|
224
269
|
id,
|
|
225
270
|
collectionSlug,
|
|
226
271
|
docPermissions,
|
|
227
|
-
docPreferences,
|
|
272
|
+
docPreferences: docPreferences_0,
|
|
228
273
|
formState: prevFormState,
|
|
229
274
|
globalSlug,
|
|
230
275
|
operation,
|
|
231
276
|
// Performance optimization: Setting it to false ensure that only fields that have explicit requireRender set in the form state will be rendered (e.g. new array rows).
|
|
232
|
-
// We only
|
|
277
|
+
// We only want to render ALL fields on initial render, not in onChange.
|
|
233
278
|
renderAllFields: false,
|
|
234
|
-
returnLockStatus: isLockingEnabled
|
|
279
|
+
returnLockStatus: isLockingEnabled,
|
|
235
280
|
schemaPath: schemaPathSegments.join('.'),
|
|
236
|
-
signal:
|
|
281
|
+
signal: controller_0.signal,
|
|
237
282
|
updateLastEdited
|
|
238
283
|
});
|
|
239
|
-
setDocumentIsLocked(true);
|
|
240
284
|
if (isLockingEnabled) {
|
|
241
|
-
|
|
242
|
-
if (lockedState) {
|
|
243
|
-
const lockedUserID = typeof lockedState.user === 'string' || typeof lockedState.user === 'number' ? lockedState.user : lockedState.user.id;
|
|
244
|
-
if (!documentLockStateRef.current || lockedUserID !== previousOwnerId) {
|
|
245
|
-
if (previousOwnerId === user.id && lockedUserID !== user.id) {
|
|
246
|
-
setShowTakeOverModal(true);
|
|
247
|
-
documentLockStateRef.current.hasShownLockedModal = true;
|
|
248
|
-
}
|
|
249
|
-
documentLockStateRef.current = documentLockStateRef.current = {
|
|
250
|
-
hasShownLockedModal: documentLockStateRef.current?.hasShownLockedModal || false,
|
|
251
|
-
isLocked: true,
|
|
252
|
-
user: lockedState.user
|
|
253
|
-
};
|
|
254
|
-
setCurrentEditor(lockedState.user);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
285
|
+
handleDocumentLocking(lockedState_0);
|
|
257
286
|
}
|
|
258
|
-
return
|
|
259
|
-
}, [
|
|
287
|
+
return state_0;
|
|
288
|
+
}, [id, collectionSlug, getDocPreferences, getFormState, globalSlug, handleDocumentLocking, isLockingEnabled, operation, schemaPathSegments, docPermissions, editSessionStartTime]);
|
|
260
289
|
// Clean up when the component unmounts or when the document is unlocked
|
|
261
290
|
useEffect(() => {
|
|
262
291
|
return () => {
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
// Check if this user is still the current editor
|
|
274
|
-
if (typeof documentLockStateRef.current?.user === 'object' ? documentLockStateRef.current?.user?.id === user?.id : documentLockStateRef.current?.user === user?.id) {
|
|
275
|
-
void unlockDocument(id, collectionSlug ?? globalSlug);
|
|
276
|
-
setDocumentIsLocked(false);
|
|
277
|
-
setCurrentEditor(null);
|
|
292
|
+
if (isLockingEnabled && documentIsLocked && (id || globalSlug)) {
|
|
293
|
+
// Only retain the lock if the user is still viewing the document
|
|
294
|
+
const shouldUnlockDocument = !['preview', 'api', 'versions'].some(path => window.location.pathname.includes(path));
|
|
295
|
+
if (shouldUnlockDocument) {
|
|
296
|
+
// Check if this user is still the current editor
|
|
297
|
+
if (typeof documentLockStateRef.current?.user === 'object' ? documentLockStateRef.current?.user?.id === user?.id : documentLockStateRef.current?.user === user?.id) {
|
|
298
|
+
void unlockDocument(id, collectionSlug ?? globalSlug);
|
|
299
|
+
setDocumentIsLocked(false);
|
|
300
|
+
setCurrentEditor(null);
|
|
301
|
+
}
|
|
278
302
|
}
|
|
279
303
|
}
|
|
280
304
|
setShowTakeOverModal(false);
|
|
@@ -283,6 +307,7 @@ export const DefaultEditView = ({
|
|
|
283
307
|
useEffect(() => {
|
|
284
308
|
return () => {
|
|
285
309
|
abortAndIgnore(onChangeAbortControllerRef.current);
|
|
310
|
+
abortAndIgnore(onSaveAbortControllerRef.current);
|
|
286
311
|
};
|
|
287
312
|
}, []);
|
|
288
313
|
const shouldShowDocumentLockedModal = documentIsLocked && currentEditor && (typeof currentEditor === 'object' ? currentEditor.id !== user?.id : currentEditor !== user?.id) && !isReadOnlyForIncomingUser && !showTakeOverModal && !documentLockStateRef.current?.hasShownLockedModal && !isLockExpired;
|