@payloadcms/ui 3.73.0-canary.4 → 3.73.0-internal.6ea481d
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/QueryPresets/QueryPresetBar/index.d.ts.map +1 -1
- package/dist/elements/QueryPresets/QueryPresetBar/index.js +1 -2
- package/dist/elements/QueryPresets/QueryPresetBar/index.js.map +1 -1
- package/dist/elements/Table/OrderableTable.d.ts.map +1 -1
- package/dist/elements/Table/OrderableTable.js +5 -1
- package/dist/elements/Table/OrderableTable.js.map +1 -1
- package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/index.js +10 -1
- package/dist/elements/WhereBuilder/index.js.map +1 -1
- package/dist/exports/client/index.js +12 -12
- package/dist/exports/client/index.js.map +3 -3
- package/dist/hooks/useEffectEvent.d.ts +14 -1
- package/dist/hooks/useEffectEvent.d.ts.map +1 -1
- package/dist/hooks/useEffectEvent.js +12 -34
- package/dist/hooks/useEffectEvent.js.map +1 -1
- package/dist/providers/ListQuery/index.d.ts.map +1 -1
- package/dist/providers/ListQuery/index.js +28 -26
- package/dist/providers/ListQuery/index.js.map +1 -1
- package/dist/utilities/upsertPreferences.d.ts.map +1 -1
- package/dist/utilities/upsertPreferences.js +2 -1
- package/dist/utilities/upsertPreferences.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
|
|
3
|
+
Polyfill taken and modified from https://github.com/bluesky-social/social-app/blob/ce0bf867ff3b50a495d8db242a7f55371bffeadc/src/lib/hooks/useNonReactiveCallback.ts
|
|
4
|
+
|
|
5
|
+
Copyright 2023–2025 Bluesky PBC
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
12
|
+
*/
|
|
13
|
+
import React from 'react';
|
|
14
|
+
export declare const useEffectEvent: typeof React.useEffectEvent;
|
|
2
15
|
//# sourceMappingURL=useEffectEvent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEffectEvent.d.ts","sourceRoot":"","sources":["../../src/hooks/useEffectEvent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEffectEvent.d.ts","sourceRoot":"","sources":["../../src/hooks/useEffectEvent.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAkD,MAAM,OAAO,CAAA;AAWtE,eAAO,MAAM,cAAc,6BAepB,CAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Polyfill taken and modified from https://github.com/bluesky-social/social-app/blob/ce0bf867ff3b50a495d8db242a7f55371bffeadc/src/lib/hooks/useNonReactiveCallback.ts
|
|
6
6
|
|
|
7
7
|
Copyright 2023–2025 Bluesky PBC
|
|
8
8
|
|
|
@@ -12,8 +12,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|
|
12
12
|
|
|
13
13
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
16
|
-
import { useCallback, useInsertionEffect, useRef } from 'react';
|
|
15
|
+
import React, { useCallback, useInsertionEffect, useRef } from 'react';
|
|
17
16
|
// This should be used sparingly. It erases reactivity, i.e. when the inputs
|
|
18
17
|
// change, the function itself will remain the same. This means that if you
|
|
19
18
|
// use this at a higher level of your tree, and then some state you read in it
|
|
@@ -22,36 +21,15 @@ import { useCallback, useInsertionEffect, useRef } from 'react';
|
|
|
22
21
|
//
|
|
23
22
|
// Also, you should avoid calling the returned function during rendering
|
|
24
23
|
// since the values captured by it are going to lag behind.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const $ = _c(4);
|
|
24
|
+
export const useEffectEvent = 'useEffectEvent' in React && typeof React.useEffectEvent === 'function' ? React.useEffectEvent : fn => {
|
|
25
|
+
// useEffectEvent is not available in older versions of React, so we need to polyfill it
|
|
28
26
|
const ref = useRef(fn);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
$[1] = t0;
|
|
38
|
-
$[2] = t1;
|
|
39
|
-
} else {
|
|
40
|
-
t0 = $[1];
|
|
41
|
-
t1 = $[2];
|
|
42
|
-
}
|
|
43
|
-
useInsertionEffect(t0, t1);
|
|
44
|
-
let t2;
|
|
45
|
-
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
46
|
-
t2 = (...t3) => {
|
|
47
|
-
const args = t3;
|
|
48
|
-
const latestFn = ref.current;
|
|
49
|
-
return latestFn(...args);
|
|
50
|
-
};
|
|
51
|
-
$[3] = t2;
|
|
52
|
-
} else {
|
|
53
|
-
t2 = $[3];
|
|
54
|
-
}
|
|
55
|
-
return t2;
|
|
56
|
-
}
|
|
27
|
+
useInsertionEffect(() => {
|
|
28
|
+
ref.current = fn;
|
|
29
|
+
}, [fn]);
|
|
30
|
+
return useCallback((...args) => {
|
|
31
|
+
const latestFn = ref.current;
|
|
32
|
+
return latestFn(...args);
|
|
33
|
+
}, []);
|
|
34
|
+
};
|
|
57
35
|
//# sourceMappingURL=useEffectEvent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEffectEvent.js","names":["
|
|
1
|
+
{"version":3,"file":"useEffectEvent.js","names":["React","useCallback","useInsertionEffect","useRef","useEffectEvent","fn","ref","current","args","latestFn"],"sources":["../../src/hooks/useEffectEvent.ts"],"sourcesContent":["'use client'\n\n/**\n\nPolyfill taken and modified from https://github.com/bluesky-social/social-app/blob/ce0bf867ff3b50a495d8db242a7f55371bffeadc/src/lib/hooks/useNonReactiveCallback.ts\n\nCopyright 2023–2025 Bluesky PBC\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nimport React, { useCallback, useInsertionEffect, useRef } from 'react'\n\n// This should be used sparingly. It erases reactivity, i.e. when the inputs\n// change, the function itself will remain the same. This means that if you\n// use this at a higher level of your tree, and then some state you read in it\n// changes, there is no mechanism for anything below in the tree to \"react\"\n// to this change (e.g. by knowing to call your function again).\n//\n// Also, you should avoid calling the returned function during rendering\n// since the values captured by it are going to lag behind.\n\nexport const useEffectEvent =\n 'useEffectEvent' in React && typeof React.useEffectEvent === 'function'\n ? // useEffectEvent is available in Next.js 16 / newer versions of React\n React.useEffectEvent\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n <T extends Function>(fn: T): T => {\n // useEffectEvent is not available in older versions of React, so we need to polyfill it\n const ref = useRef(fn)\n useInsertionEffect(() => {\n ref.current = fn\n }, [fn])\n return useCallback((...args: any) => {\n const latestFn = ref.current\n return latestFn(...args)\n }, []) as unknown as T\n }\n"],"mappings":"AAAA;;AAEA;;;;;;;;;;;;AAaA,OAAOA,KAAA,IAASC,WAAW,EAAEC,kBAAkB,EAAEC,MAAM,QAAQ;AAE/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAMC,cAAA,GACX,oBAAoBJ,KAAA,IAAS,OAAOA,KAAA,CAAMI,cAAc,KAAK,aAEzDJ,KAAA,CAAMI,cAAc,GAECC,EAAA;EACnB;EACA,MAAMC,GAAA,GAAMH,MAAA,CAAOE,EAAA;EACnBH,kBAAA,CAAmB;IACjBI,GAAA,CAAIC,OAAO,GAAGF,EAAA;EAChB,GAAG,CAACA,EAAA,CAAG;EACP,OAAOJ,WAAA,CAAY,CAAC,GAAGO,IAAA;IACrB,MAAMC,QAAA,GAAWH,GAAA,CAAIC,OAAO;IAC5B,OAAOE,QAAA,IAAYD,IAAA;EACrB,GAAG,EAAE;AACP","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,YAAY,CAAA;AAWnE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/ListQuery/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,YAAY,CAAA;AAWnE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAuKtD,CAAA"}
|
|
@@ -25,7 +25,6 @@ export const ListQueryProvider = ({
|
|
|
25
25
|
// TODO: Investigate if this is still needed
|
|
26
26
|
'use no memo';
|
|
27
27
|
|
|
28
|
-
// TODO: Investigate if this is still needed
|
|
29
28
|
const router = useRouter();
|
|
30
29
|
const rawSearchParams = useSearchParams();
|
|
31
30
|
const {
|
|
@@ -38,15 +37,16 @@ export const ListQueryProvider = ({
|
|
|
38
37
|
const collectionConfig = getEntityConfig({
|
|
39
38
|
collectionSlug
|
|
40
39
|
});
|
|
41
|
-
const searchParams = useMemo(() => sanitizeQuery(parseSearchParams(rawSearchParams)), [rawSearchParams]);
|
|
42
40
|
const contextRef = useRef({});
|
|
43
41
|
contextRef.current.modified = modified;
|
|
44
42
|
const {
|
|
45
|
-
onQueryChange
|
|
43
|
+
onQueryChange: onQueryChangeFromContext
|
|
46
44
|
} = useListDrawerContext();
|
|
45
|
+
const onQueryChange = onQueryChangeFromContext || onQueryChangeFromProps;
|
|
46
|
+
const queryFromURL = useMemo(() => sanitizeQuery(parseSearchParams(rawSearchParams)), [rawSearchParams]);
|
|
47
47
|
const [query, setQuery] = useState(() => {
|
|
48
48
|
if (modifySearchParams) {
|
|
49
|
-
return
|
|
49
|
+
return queryFromURL;
|
|
50
50
|
} else {
|
|
51
51
|
return {
|
|
52
52
|
limit: queryFromProps.limit,
|
|
@@ -57,11 +57,7 @@ export const ListQueryProvider = ({
|
|
|
57
57
|
const refineListData = useCallback(
|
|
58
58
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
59
59
|
async (incomingQuery, modified_0) => {
|
|
60
|
-
|
|
61
|
-
setModified(modified_0);
|
|
62
|
-
} else {
|
|
63
|
-
setModified(true);
|
|
64
|
-
}
|
|
60
|
+
setModified(modified_0 ?? true);
|
|
65
61
|
const newQuery = mergeQuery(query, incomingQuery, {
|
|
66
62
|
defaults: {
|
|
67
63
|
limit: queryFromProps.limit,
|
|
@@ -69,19 +65,19 @@ export const ListQueryProvider = ({
|
|
|
69
65
|
}
|
|
70
66
|
});
|
|
71
67
|
if (modifySearchParams) {
|
|
72
|
-
|
|
68
|
+
const search = `?${qs.stringify({
|
|
73
69
|
...newQuery,
|
|
74
70
|
columns: JSON.stringify(newQuery.columns),
|
|
75
71
|
queryByGroup: JSON.stringify(newQuery.queryByGroup)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
})}`;
|
|
73
|
+
if (window.location.search !== search) {
|
|
74
|
+
startRouteTransition(() => router.replace(search));
|
|
75
|
+
}
|
|
76
|
+
} else if (typeof onQueryChange === 'function') {
|
|
77
|
+
onQueryChange(newQuery);
|
|
82
78
|
}
|
|
83
79
|
setQuery(newQuery);
|
|
84
|
-
}, [query, queryFromProps.limit, queryFromProps.sort, modifySearchParams, onQueryChange,
|
|
80
|
+
}, [query, queryFromProps.limit, queryFromProps.sort, modifySearchParams, onQueryChange, startRouteTransition, router]);
|
|
85
81
|
const handlePageChange = useCallback(async arg => {
|
|
86
82
|
await refineListData({
|
|
87
83
|
page: arg
|
|
@@ -94,9 +90,9 @@ export const ListQueryProvider = ({
|
|
|
94
90
|
});
|
|
95
91
|
}, [refineListData]);
|
|
96
92
|
const handleSearchChange = useCallback(async arg_1 => {
|
|
97
|
-
const
|
|
93
|
+
const search_0 = arg_1 === '' ? undefined : arg_1;
|
|
98
94
|
await refineListData({
|
|
99
|
-
search
|
|
95
|
+
search: search_0
|
|
100
96
|
});
|
|
101
97
|
}, [refineListData]);
|
|
102
98
|
const handleSortChange = useCallback(async sort => {
|
|
@@ -109,27 +105,33 @@ export const ListQueryProvider = ({
|
|
|
109
105
|
where
|
|
110
106
|
});
|
|
111
107
|
}, [refineListData]);
|
|
112
|
-
|
|
108
|
+
/**
|
|
109
|
+
* The server component may pass props to this client component, e.g. from
|
|
110
|
+
* fetching the query from preferences.
|
|
111
|
+
* This effect is responsible for syncing the props back to the URL, without
|
|
112
|
+
* triggering a re-render.
|
|
113
|
+
*/
|
|
114
|
+
const syncPropsToURL = useEffectEvent(() => {
|
|
113
115
|
const newQuery_0 = sanitizeQuery({
|
|
114
116
|
...(query || {}),
|
|
115
117
|
...(queryFromProps || {})
|
|
116
118
|
});
|
|
117
|
-
const
|
|
119
|
+
const search_1 = `?${qs.stringify({
|
|
118
120
|
...newQuery_0,
|
|
119
121
|
columns: JSON.stringify(newQuery_0.columns),
|
|
120
122
|
queryByGroup: JSON.stringify(newQuery_0.queryByGroup)
|
|
121
123
|
})}`;
|
|
122
|
-
if (window.location.search !==
|
|
124
|
+
if (window.location.search !== search_1) {
|
|
123
125
|
setQuery(newQuery_0);
|
|
124
|
-
// Important: do not use router.replace here to avoid re-rendering
|
|
125
|
-
window.history.replaceState(null, '',
|
|
126
|
+
// Important: do not use router.replace here to avoid re-rendering.
|
|
127
|
+
window.history.replaceState(null, '', search_1);
|
|
126
128
|
}
|
|
127
129
|
});
|
|
128
130
|
// If `query` is updated externally, update the local state
|
|
129
131
|
// E.g. when HMR runs, these properties may be different
|
|
130
132
|
useEffect(() => {
|
|
131
|
-
if (modifySearchParams) {
|
|
132
|
-
|
|
133
|
+
if (modifySearchParams && queryFromProps) {
|
|
134
|
+
syncPropsToURL();
|
|
133
135
|
}
|
|
134
136
|
}, [modifySearchParams, queryFromProps]);
|
|
135
137
|
return /*#__PURE__*/_jsx(ListQueryContext, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useRouter","useSearchParams","qs","React","useCallback","useEffect","useMemo","useRef","useState","useListDrawerContext","useEffectEvent","useRouteTransition","parseSearchParams","useConfig","ListQueryContext","ListQueryModifiedContext","mergeQuery","sanitizeQuery","useListQuery","ListQueryProvider","children","collectionSlug","data","modifySearchParams","onQueryChange","onQueryChangeFromProps","orderableFieldName","query","queryFromProps","router","rawSearchParams","startRouteTransition","modified","setModified","getEntityConfig","collectionConfig","searchParams","contextRef","current","setQuery","limit","sort","refineListData","incomingQuery","undefined","newQuery","defaults","replace","stringify","columns","JSON","queryByGroup","addQueryPrefix","onChangeFn","handlePageChange","arg","page","handlePerPageChange","handleSearchChange","search","handleSortChange","handleWhereChange","where","mergeQueryFromPropsAndSyncToURL","window","location","history","replaceState","_jsx","value","defaultLimit","isGroupingBy","Boolean","admin","groupBy"],"sources":["../../../src/providers/ListQuery/index.tsx"],"sourcesContent":["'use client'\nimport { useRouter, useSearchParams } from 'next/navigation.js'\nimport { type ListQuery, type Where } from 'payload'\nimport * as qs from 'qs-esm'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { IListQueryContext, ListQueryProps } from './types.js'\n\nimport { useListDrawerContext } from '../../elements/ListDrawer/Provider.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useRouteTransition } from '../../providers/RouteTransition/index.js'\nimport { parseSearchParams } from '../../utilities/parseSearchParams.js'\nimport { useConfig } from '../Config/index.js'\nimport { ListQueryContext, ListQueryModifiedContext } from './context.js'\nimport { mergeQuery } from './mergeQuery.js'\nimport { sanitizeQuery } from './sanitizeQuery.js'\n\nexport { useListQuery } from './context.js'\n\nexport const ListQueryProvider: React.FC<ListQueryProps> = ({\n children,\n collectionSlug,\n data,\n modifySearchParams,\n onQueryChange: onQueryChangeFromProps,\n orderableFieldName,\n query: queryFromProps,\n}) => {\n // TODO: Investigate if this is still needed\n 'use no memo'\n // TODO: Investigate if this is still needed\n\n const router = useRouter()\n const rawSearchParams = useSearchParams()\n const { startRouteTransition } = useRouteTransition()\n const [modified, setModified] = useState(false)\n const { getEntityConfig } = useConfig()\n const collectionConfig = getEntityConfig({ collectionSlug })\n\n const searchParams = useMemo<ListQuery>(\n () => sanitizeQuery(parseSearchParams(rawSearchParams)),\n [rawSearchParams],\n )\n\n const contextRef = useRef({} as IListQueryContext)\n\n contextRef.current.modified = modified\n\n const { onQueryChange } = useListDrawerContext()\n\n const [query, setQuery] = useState<ListQuery>(() => {\n if (modifySearchParams) {\n return searchParams\n } else {\n return {\n limit: queryFromProps.limit,\n sort: queryFromProps.sort,\n }\n }\n })\n\n const refineListData = useCallback(\n // eslint-disable-next-line @typescript-eslint/require-await\n async (incomingQuery: ListQuery, modified?: boolean) => {\n if (modified !== undefined) {\n setModified(modified)\n } else {\n setModified(true)\n }\n\n const newQuery = mergeQuery(query, incomingQuery, {\n defaults: {\n limit: queryFromProps.limit,\n sort: queryFromProps.sort,\n },\n })\n\n if (modifySearchParams) {\n startRouteTransition(() =>\n router.replace(\n `${qs.stringify(\n {\n ...newQuery,\n columns: JSON.stringify(newQuery.columns),\n queryByGroup: JSON.stringify(newQuery.queryByGroup),\n },\n { addQueryPrefix: true },\n )}`,\n ),\n )\n } else if (\n typeof onQueryChange === 'function' ||\n typeof onQueryChangeFromProps === 'function'\n ) {\n const onChangeFn = onQueryChange || onQueryChangeFromProps\n onChangeFn(newQuery)\n }\n\n setQuery(newQuery)\n },\n [\n query,\n queryFromProps.limit,\n queryFromProps.sort,\n modifySearchParams,\n onQueryChange,\n onQueryChangeFromProps,\n startRouteTransition,\n router,\n ],\n )\n\n const handlePageChange = useCallback(\n async (arg: number) => {\n await refineListData({ page: arg })\n },\n [refineListData],\n )\n\n const handlePerPageChange = React.useCallback(\n async (arg: number) => {\n await refineListData({ limit: 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 (sort: string) => {\n await refineListData({ sort })\n },\n [refineListData],\n )\n\n const handleWhereChange = useCallback(\n async (where: Where) => {\n await refineListData({ where })\n },\n [refineListData],\n )\n\n const mergeQueryFromPropsAndSyncToURL = useEffectEvent(() => {\n const newQuery = sanitizeQuery({ ...(query || {}), ...(queryFromProps || {}) })\n\n const search = `?${qs.stringify({\n ...newQuery,\n columns: JSON.stringify(newQuery.columns),\n queryByGroup: JSON.stringify(newQuery.queryByGroup),\n })}`\n\n if (window.location.search !== search) {\n setQuery(newQuery)\n\n // Important: do not use router.replace here to avoid re-rendering on initial load\n window.history.replaceState(null, '', search)\n }\n })\n\n // If `query` is updated externally, update the local state\n // E.g. when HMR runs, these properties may be different\n useEffect(() => {\n if (modifySearchParams) {\n mergeQueryFromPropsAndSyncToURL()\n }\n }, [modifySearchParams, queryFromProps])\n\n return (\n <ListQueryContext\n value={{\n collectionSlug,\n data,\n defaultLimit: data?.limit,\n handlePageChange,\n handlePerPageChange,\n handleSearchChange,\n handleSortChange,\n handleWhereChange,\n isGroupingBy: Boolean(collectionConfig?.admin?.groupBy && query?.groupBy),\n orderableFieldName,\n query,\n refineListData,\n setModified,\n ...contextRef.current,\n }}\n >\n <ListQueryModifiedContext value={modified}>{children}</ListQueryModifiedContext>\n </ListQueryContext>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,SAAS,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R,IAAIkB,kBAAA,EAAoB;MACtBwC,+BAAA;IACF;EACF,GAAG,CAACxC,kBAAA,EAAoBK,cAAA,CAAe;EAEvC,oBACEwC,IAAA,CAACtD,gBAAA;IACCuD,KAAA,EAAO;MACLhD,cAAA;MACAC,IAAA;MACAgD,YAAA,EAAchD,IAAA,EAAMkB,KAAA;MACpBc,gBAAA;MACAG,mBAAA;MACAC,kBAAA;MACAE,gBAAA;MACAC,iBAAA;MACAU,YAAA,EAAcC,OAAA,CAAQrC,gBAAA,EAAkBsC,KAAA,EAAOC,OAAA,IAAW/C,KAAA,EAAO+C,OAAA;MACjEhD,kBAAA;MACAC,KAAA;MACAe,cAAA;MACAT,WAAA;MACA,GAAGI,UAAA,CAAWC;IAChB;cAEA,aAAA8B,IAAA,CAACrD,wBAAA;MAAyBsD,KAAA,EAAOrC,QAAA;gBAAWZ;;;AAGlD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useRouter","useSearchParams","qs","React","useCallback","useEffect","useMemo","useRef","useState","useListDrawerContext","useEffectEvent","useRouteTransition","parseSearchParams","useConfig","ListQueryContext","ListQueryModifiedContext","mergeQuery","sanitizeQuery","useListQuery","ListQueryProvider","children","collectionSlug","data","modifySearchParams","onQueryChange","onQueryChangeFromProps","orderableFieldName","query","queryFromProps","router","rawSearchParams","startRouteTransition","modified","setModified","getEntityConfig","collectionConfig","contextRef","current","onQueryChangeFromContext","queryFromURL","setQuery","limit","sort","refineListData","incomingQuery","newQuery","defaults","search","stringify","columns","JSON","queryByGroup","window","location","replace","handlePageChange","arg","page","handlePerPageChange","handleSearchChange","undefined","handleSortChange","handleWhereChange","where","syncPropsToURL","history","replaceState","_jsx","value","defaultLimit","isGroupingBy","Boolean","admin","groupBy"],"sources":["../../../src/providers/ListQuery/index.tsx"],"sourcesContent":["'use client'\nimport { useRouter, useSearchParams } from 'next/navigation.js'\nimport { type ListQuery, type Where } from 'payload'\nimport * as qs from 'qs-esm'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { IListQueryContext, ListQueryProps } from './types.js'\n\nimport { useListDrawerContext } from '../../elements/ListDrawer/Provider.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useRouteTransition } from '../../providers/RouteTransition/index.js'\nimport { parseSearchParams } from '../../utilities/parseSearchParams.js'\nimport { useConfig } from '../Config/index.js'\nimport { ListQueryContext, ListQueryModifiedContext } from './context.js'\nimport { mergeQuery } from './mergeQuery.js'\nimport { sanitizeQuery } from './sanitizeQuery.js'\n\nexport { useListQuery } from './context.js'\n\nexport const ListQueryProvider: React.FC<ListQueryProps> = ({\n children,\n collectionSlug,\n data,\n modifySearchParams,\n onQueryChange: onQueryChangeFromProps,\n orderableFieldName,\n query: queryFromProps,\n}) => {\n // TODO: Investigate if this is still needed\n 'use no memo'\n\n const router = useRouter()\n const rawSearchParams = useSearchParams()\n const { startRouteTransition } = useRouteTransition()\n const [modified, setModified] = useState(false)\n const { getEntityConfig } = useConfig()\n const collectionConfig = getEntityConfig({ collectionSlug })\n\n const contextRef = useRef({} as IListQueryContext)\n contextRef.current.modified = modified\n\n const { onQueryChange: onQueryChangeFromContext } = useListDrawerContext()\n const onQueryChange = onQueryChangeFromContext || onQueryChangeFromProps\n\n const queryFromURL = useMemo<ListQuery>(\n () => sanitizeQuery(parseSearchParams(rawSearchParams)),\n [rawSearchParams],\n )\n\n const [query, setQuery] = useState<ListQuery>(() => {\n if (modifySearchParams) {\n return queryFromURL\n } else {\n return {\n limit: queryFromProps.limit,\n sort: queryFromProps.sort,\n }\n }\n })\n\n const refineListData = useCallback(\n // eslint-disable-next-line @typescript-eslint/require-await\n async (incomingQuery: ListQuery, modified?: boolean) => {\n setModified(modified ?? true)\n\n const newQuery = mergeQuery(query, incomingQuery, {\n defaults: {\n limit: queryFromProps.limit,\n sort: queryFromProps.sort,\n },\n })\n\n if (modifySearchParams) {\n const search = `?${qs.stringify({\n ...newQuery,\n columns: JSON.stringify(newQuery.columns),\n queryByGroup: JSON.stringify(newQuery.queryByGroup),\n })}`\n if (window.location.search !== search) {\n startRouteTransition(() => router.replace(search))\n }\n } else if (typeof onQueryChange === 'function') {\n onQueryChange(newQuery)\n }\n\n setQuery(newQuery)\n },\n [\n query,\n queryFromProps.limit,\n queryFromProps.sort,\n modifySearchParams,\n onQueryChange,\n startRouteTransition,\n router,\n ],\n )\n\n const handlePageChange = useCallback(\n async (arg: number) => {\n await refineListData({ page: arg })\n },\n [refineListData],\n )\n\n const handlePerPageChange = React.useCallback(\n async (arg: number) => {\n await refineListData({ limit: 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 (sort: string) => {\n await refineListData({ sort })\n },\n [refineListData],\n )\n\n const handleWhereChange = useCallback(\n async (where: Where) => {\n await refineListData({ where })\n },\n [refineListData],\n )\n\n /**\n * The server component may pass props to this client component, e.g. from\n * fetching the query from preferences.\n * This effect is responsible for syncing the props back to the URL, without\n * triggering a re-render.\n */\n const syncPropsToURL = useEffectEvent(() => {\n const newQuery = sanitizeQuery({ ...(query || {}), ...(queryFromProps || {}) })\n\n const search = `?${qs.stringify({\n ...newQuery,\n columns: JSON.stringify(newQuery.columns),\n queryByGroup: JSON.stringify(newQuery.queryByGroup),\n })}`\n\n if (window.location.search !== search) {\n setQuery(newQuery)\n // Important: do not use router.replace here to avoid re-rendering.\n window.history.replaceState(null, '', search)\n }\n })\n\n // If `query` is updated externally, update the local state\n // E.g. when HMR runs, these properties may be different\n useEffect(() => {\n if (modifySearchParams && queryFromProps) {\n syncPropsToURL()\n }\n }, [modifySearchParams, queryFromProps])\n\n return (\n <ListQueryContext\n value={{\n collectionSlug,\n data,\n defaultLimit: data?.limit,\n handlePageChange,\n handlePerPageChange,\n handleSearchChange,\n handleSortChange,\n handleWhereChange,\n isGroupingBy: Boolean(collectionConfig?.admin?.groupBy && query?.groupBy),\n orderableFieldName,\n query,\n refineListData,\n setModified,\n ...contextRef.current,\n }}\n >\n <ListQueryModifiedContext value={modified}>{children}</ListQueryModifiedContext>\n </ListQueryContext>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,SAAS,EAAEC,eAAe,QAAQ;AAE3C,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAIzE,SAASC,oBAAoB,QAAQ;AACrC,SAASC,cAAc,QAAQ;AAC/B,SAASC,kBAAkB,QAAQ;AACnC,SAASC,iBAAiB,QAAQ;AAClC,SAASC,SAAS,QAAQ;AAC1B,SAASC,gBAAgB,EAAEC,wBAAwB,QAAQ;AAC3D,SAASC,UAAU,QAAQ;AAC3B,SAASC,aAAa,QAAQ;AAE9B,SAASC,YAAY,QAAQ;AAE7B,OAAO,MAAMC,iBAAA,GAA8CA,CAAC;EAC1DC,QAAQ;EACRC,cAAc;EACdC,IAAI;EACJC,kBAAkB;EAClBC,aAAA,EAAeC,sBAAsB;EACrCC,kBAAkB;EAClBC,KAAA,EAAOC;AAAc,CACtB;EACC;EACA;;EAEA,MAAMC,MAAA,GAAS7B,SAAA;EACf,MAAM8B,eAAA,GAAkB7B,eAAA;EACxB,MAAM;IAAE8B;EAAoB,CAAE,GAAGpB,kBAAA;EACjC,MAAM,CAACqB,QAAA,EAAUC,WAAA,CAAY,GAAGzB,QAAA,CAAS;EACzC,MAAM;IAAE0B;EAAe,CAAE,GAAGrB,SAAA;EAC5B,MAAMsB,gBAAA,GAAmBD,eAAA,CAAgB;IAAEb;EAAe;EAE1D,MAAMe,UAAA,GAAa7B,MAAA,CAAO,CAAC;EAC3B6B,UAAA,CAAWC,OAAO,CAACL,QAAQ,GAAGA,QAAA;EAE9B,MAAM;IAAER,aAAA,EAAec;EAAwB,CAAE,GAAG7B,oBAAA;EACpD,MAAMe,aAAA,GAAgBc,wBA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AM,KAAKA,QAAA,EAAQ;MACrCP,QAAA,CAASK,UAAA;MACT;MACAO,MAAA,CAAOa,OAAO,CAACC,YAAY,CAAC,MAAM,IAAInB,QAAA;IACxC;EACF;EAEA;EACA;EACA1C,SAAA,CAAU;IACR,IAAIkB,kBAAA,IAAsBK,cAAA,EAAgB;MACxCoC,cAAA;IACF;EACF,GAAG,CAACzC,kBAAA,EAAoBK,cAAA,CAAe;EAEvC,oBACEuC,IAAA,CAACrD,gBAAA;IACCsD,KAAA,EAAO;MACL/C,cAAA;MACAC,IAAA;MACA+C,YAAA,EAAc/C,IAAA,EAAMmB,KAAA;MACpBc,gBAAA;MACAG,mBAAA;MACAC,kBAAA;MACAE,gBAAA;MACAC,iBAAA;MACAQ,YAAA,EAAcC,OAAA,CAAQpC,gBAAA,EAAkBqC,KAAA,EAAOC,OAAA,IAAW9C,KAAA,EAAO8C,OAAA;MACjE/C,kBAAA;MACAC,KAAA;MACAgB,cAAA;MACAV,WAAA;MACA,GAAGG,UAAA,CAAWC;IAChB;cAEA,aAAA8B,IAAA,CAACpD,wBAAA;MAAyBqD,KAAA,EAAOpC,QAAA;gBAAWZ;;;AAGlD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertPreferences.d.ts","sourceRoot":"","sources":["../../src/utilities/upsertPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7E,KAAK,aAAa,CAAC,CAAC,IAAI;IACtB,EAAE,EAAE,qBAAqB,GAAG,SAAS,CAAA;IACrC,KAAK,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;CACtB,CAAA;AAED,KAAK,YAAY,GAAG,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,CAAA;AAQ5E,eAAO,MAAM,cAAc,GAClB,CAAC,OACD,MAA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CAAC,CAAA;IACnF,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,CAAC,CAAA;CACT,KAAG,OAAO,CAAC,CAAC,CA0DZ,CAAA"}
|
|
@@ -46,7 +46,7 @@ export const upsertPreferences = async ({
|
|
|
46
46
|
const existingPrefs = req.user ? await getPreferences(key, req.payload, req.user.id, req.user.collection) : {};
|
|
47
47
|
let newPrefs = existingPrefs?.value;
|
|
48
48
|
if (!existingPrefs?.id) {
|
|
49
|
-
await req.payload.create({
|
|
49
|
+
const createdPrefs = await req.payload.create({
|
|
50
50
|
collection: 'payload-preferences',
|
|
51
51
|
data: {
|
|
52
52
|
key,
|
|
@@ -60,6 +60,7 @@ export const upsertPreferences = async ({
|
|
|
60
60
|
disableTransaction: true,
|
|
61
61
|
user: req.user
|
|
62
62
|
});
|
|
63
|
+
return createdPrefs.value;
|
|
63
64
|
} else {
|
|
64
65
|
let mergedPrefs;
|
|
65
66
|
if (typeof customMerge === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertPreferences.js","names":["dequal","cache","removeUndefined","defaultMerge","existingValue","incomingValue","getPreferences","key","payload","userID","userSlug","result","find","collection","depth","limit","pagination","where","and","equals","then","res","docs","upsertPreferences","customMerge","req","value","existingPrefs","user","id","newPrefs","create","data","disableTransaction","mergedPrefs","update"],"sources":["../../src/utilities/upsertPreferences.ts"],"sourcesContent":["import type { DefaultDocumentIDType, Payload, PayloadRequest } from 'payload'\n\nimport { dequal } from 'dequal/lite'\nimport { cache } from 'react'\n\nimport { removeUndefined } from './removeUndefined.js'\n\ntype PreferenceDoc<T> = {\n id: DefaultDocumentIDType | undefined\n value?: T | undefined\n}\n\ntype DefaultMerge = <T>(existingValue: T, incomingValue: T | undefined) => T\n\nconst defaultMerge: DefaultMerge = <T>(existingValue: T, incomingValue: T | undefined) =>\n ({\n ...(typeof existingValue === 'object' ? existingValue : {}), // Shallow merge existing prefs to acquire any missing keys from incoming value\n ...removeUndefined(incomingValue || {}),\n }) as T\n\nexport const getPreferences = cache(\n async <T>(\n key: string,\n payload: Payload,\n userID: DefaultDocumentIDType,\n userSlug: string,\n ): Promise<PreferenceDoc<T>> => {\n const result = (await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: key,\n },\n },\n {\n 'user.relationTo': {\n equals: userSlug,\n },\n },\n {\n 'user.value': {\n equals: userID,\n },\n },\n ],\n },\n })\n .then((res) => res.docs?.[0])) as { id: DefaultDocumentIDType; value: T }\n\n return result\n },\n)\n\n/**\n * Will update the given preferences by key, creating a new record if it doesn't already exist, or merging existing preferences with the new value.\n * This is not possible to do with the existing `db.upsert` operation because it stores on the `value` key and does not perform a deep merge beyond the first level.\n * I.e. if you have a preferences record with a `value` key, `db.upsert` will overwrite the existing value. In the future if this supported we should use that instead.\n * @param req - The PayloadRequest object\n * @param key - The key of the preferences to update\n * @param value - The new value to merge with the existing preferences\n */\nexport const upsertPreferences = async <T extends Record<string, unknown> | string>({\n customMerge,\n key,\n req,\n value: incomingValue,\n}: {\n customMerge?: (existingValue: T, incomingValue: T, defaultMerge: DefaultMerge) => T\n key: string\n req: PayloadRequest\n value: T\n}): Promise<T> => {\n const existingPrefs: PreferenceDoc<T> = req.user\n ? await getPreferences<T>(key, req.payload, req.user.id, req.user.collection)\n : ({} as PreferenceDoc<T>)\n\n let newPrefs = existingPrefs?.value\n\n if (!existingPrefs?.id) {\n await req.payload.create({\n collection: 'payload-preferences',\n data: {\n key,\n user: {\n collection: req.user.collection,\n value: req.user.id,\n },\n value: incomingValue,\n },\n depth: 0,\n disableTransaction: true,\n user: req.user,\n })\n } else {\n let mergedPrefs: T\n\n if (typeof customMerge === 'function') {\n mergedPrefs = customMerge(existingPrefs.value, incomingValue, defaultMerge)\n } else {\n // Strings are valid JSON, i.e. `locale` saved as a string to the locale preferences\n mergedPrefs =\n typeof incomingValue === 'object'\n ? defaultMerge<T>(existingPrefs.value, incomingValue)\n : incomingValue\n }\n\n if (!dequal(mergedPrefs, existingPrefs.value)) {\n newPrefs = await req.payload\n .update({\n id: existingPrefs.id,\n collection: 'payload-preferences',\n data: {\n key,\n user: {\n collection: req.user.collection,\n value: req.user.id,\n },\n value: mergedPrefs,\n },\n depth: 0,\n disableTransaction: true,\n user: req.user,\n })\n ?.then((res) => res.value)\n }\n }\n\n return newPrefs\n}\n"],"mappings":"AAEA,SAASA,MAAM,QAAQ;AACvB,SAASC,KAAK,QAAQ;AAEtB,SAASC,eAAe,QAAQ;AAShC,MAAMC,YAAA,GAA6BA,CAAIC,aAAA,EAAkBC,aAAA,MACtD;EACC,IAAI,OAAOD,aAAA,KAAkB,WAAWA,aAAA,GAAgB,CAAC,CAAC;EAC1D,GAAGF,eAAA,CAAgBG,aAAA,IAAiB,CAAC;AACvC;AAEF,OAAO,MAAMC,cAAA,GAAiBL,KAAA,CAC5B,OACEM,GAAA,EACAC,OAAA,EACAC,MAAA,EACAC,QAAA;EAEA,MAAMC,MAAA,GAAU,MAAMH,OAAA,CACnBI,IAAI,CAAC;IACJC,UAAA,EAAY;IACZC,KAAA,EAAO;IACPC,KAAA,EAAO;IACPC,UAAA,EAAY;IACZC,KAAA,EAAO;MACLC,GAAA,EAAK,CACH;QACEX,GAAA,EAAK;UACHY,MAAA,EAAQZ;QACV;MACF,GACA;QACE,mBAAmB;UACjBY,MAAA,EAAQT;QACV;MACF,GACA;QACE,cAAc;UACZS,MAAA,EAAQV;QACV;MACF;IAEJ;EACF,GACCW,IAAI,CAAEC,GAAA,IAAQA,GAAA,CAAIC,IAAI,GAAG,EAAE;EAE9B,OAAOX,MAAA;AACT;AAGF;;;;;;;;AAQA,OAAO,MAAMY,iBAAA,GAAoB,MAAAA,CAAmD;EAClFC,WAAW;EACXjB,GAAG;EACHkB,GAAG;EACHC,KAAA,EAAOrB;AAAa,CAMrB;EACC,MAAMsB,aAAA,GAAkCF,GAAA,CAAIG,IAAI,GAC5C,MAAMtB,cAAA,CAAkBC,GAAA,EAAKkB,GAAA,CAAIjB,OAAO,EAAEiB,GAAA,CAAIG,IAAI,CAACC,EAAE,EAAEJ,GAAA,CAAIG,IAAI,CAACf,UAAU,IACzE,CAAC;EAEN,IAAIiB,QAAA,GAAWH,aAAA,EAAeD,KAAA;EAE9B,IAAI,CAACC,aAAA,EAAeE,EAAA,EAAI;IACtB,
|
|
1
|
+
{"version":3,"file":"upsertPreferences.js","names":["dequal","cache","removeUndefined","defaultMerge","existingValue","incomingValue","getPreferences","key","payload","userID","userSlug","result","find","collection","depth","limit","pagination","where","and","equals","then","res","docs","upsertPreferences","customMerge","req","value","existingPrefs","user","id","newPrefs","createdPrefs","create","data","disableTransaction","mergedPrefs","update"],"sources":["../../src/utilities/upsertPreferences.ts"],"sourcesContent":["import type { DefaultDocumentIDType, Payload, PayloadRequest } from 'payload'\n\nimport { dequal } from 'dequal/lite'\nimport { cache } from 'react'\n\nimport { removeUndefined } from './removeUndefined.js'\n\ntype PreferenceDoc<T> = {\n id: DefaultDocumentIDType | undefined\n value?: T | undefined\n}\n\ntype DefaultMerge = <T>(existingValue: T, incomingValue: T | undefined) => T\n\nconst defaultMerge: DefaultMerge = <T>(existingValue: T, incomingValue: T | undefined) =>\n ({\n ...(typeof existingValue === 'object' ? existingValue : {}), // Shallow merge existing prefs to acquire any missing keys from incoming value\n ...removeUndefined(incomingValue || {}),\n }) as T\n\nexport const getPreferences = cache(\n async <T>(\n key: string,\n payload: Payload,\n userID: DefaultDocumentIDType,\n userSlug: string,\n ): Promise<PreferenceDoc<T>> => {\n const result = (await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: key,\n },\n },\n {\n 'user.relationTo': {\n equals: userSlug,\n },\n },\n {\n 'user.value': {\n equals: userID,\n },\n },\n ],\n },\n })\n .then((res) => res.docs?.[0])) as { id: DefaultDocumentIDType; value: T }\n\n return result\n },\n)\n\n/**\n * Will update the given preferences by key, creating a new record if it doesn't already exist, or merging existing preferences with the new value.\n * This is not possible to do with the existing `db.upsert` operation because it stores on the `value` key and does not perform a deep merge beyond the first level.\n * I.e. if you have a preferences record with a `value` key, `db.upsert` will overwrite the existing value. In the future if this supported we should use that instead.\n * @param req - The PayloadRequest object\n * @param key - The key of the preferences to update\n * @param value - The new value to merge with the existing preferences\n */\nexport const upsertPreferences = async <T extends Record<string, unknown> | string>({\n customMerge,\n key,\n req,\n value: incomingValue,\n}: {\n customMerge?: (existingValue: T, incomingValue: T, defaultMerge: DefaultMerge) => T\n key: string\n req: PayloadRequest\n value: T\n}): Promise<T> => {\n const existingPrefs: PreferenceDoc<T> = req.user\n ? await getPreferences<T>(key, req.payload, req.user.id, req.user.collection)\n : ({} as PreferenceDoc<T>)\n\n let newPrefs = existingPrefs?.value\n\n if (!existingPrefs?.id) {\n const createdPrefs = await req.payload.create({\n collection: 'payload-preferences',\n data: {\n key,\n user: {\n collection: req.user.collection,\n value: req.user.id,\n },\n value: incomingValue,\n },\n depth: 0,\n disableTransaction: true,\n user: req.user,\n })\n return createdPrefs.value\n } else {\n let mergedPrefs: T\n\n if (typeof customMerge === 'function') {\n mergedPrefs = customMerge(existingPrefs.value, incomingValue, defaultMerge)\n } else {\n // Strings are valid JSON, i.e. `locale` saved as a string to the locale preferences\n mergedPrefs =\n typeof incomingValue === 'object'\n ? defaultMerge<T>(existingPrefs.value, incomingValue)\n : incomingValue\n }\n\n if (!dequal(mergedPrefs, existingPrefs.value)) {\n newPrefs = await req.payload\n .update({\n id: existingPrefs.id,\n collection: 'payload-preferences',\n data: {\n key,\n user: {\n collection: req.user.collection,\n value: req.user.id,\n },\n value: mergedPrefs,\n },\n depth: 0,\n disableTransaction: true,\n user: req.user,\n })\n ?.then((res) => res.value)\n }\n }\n\n return newPrefs\n}\n"],"mappings":"AAEA,SAASA,MAAM,QAAQ;AACvB,SAASC,KAAK,QAAQ;AAEtB,SAASC,eAAe,QAAQ;A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version": "3.73.0-internal.6ea481d",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"ts-essentials": "10.0.3",
|
|
137
137
|
"use-context-selector": "2.0.0",
|
|
138
138
|
"uuid": "10.0.0",
|
|
139
|
-
"@payloadcms/translations": "3.73.0-
|
|
139
|
+
"@payloadcms/translations": "3.73.0-internal.6ea481d"
|
|
140
140
|
},
|
|
141
141
|
"devDependencies": {
|
|
142
142
|
"@babel/cli": "7.27.2",
|
|
@@ -152,13 +152,13 @@
|
|
|
152
152
|
"esbuild": "0.27.1",
|
|
153
153
|
"esbuild-sass-plugin": "3.3.1",
|
|
154
154
|
"@payloadcms/eslint-config": "3.28.0",
|
|
155
|
-
"payload": "3.73.0-
|
|
155
|
+
"payload": "3.73.0-internal.6ea481d"
|
|
156
156
|
},
|
|
157
157
|
"peerDependencies": {
|
|
158
158
|
"next": "^15.2.8 || ^15.3.8 || ^15.4.10 || ^15.5.9 || >=16.1.1-canary.35 <16.2.0 || ^16.2.0",
|
|
159
159
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
160
160
|
"react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
161
|
-
"payload": "3.73.0-
|
|
161
|
+
"payload": "3.73.0-internal.6ea481d"
|
|
162
162
|
},
|
|
163
163
|
"engines": {
|
|
164
164
|
"node": "^18.20.2 || >=20.9.0"
|