@payloadcms/ui 3.28.0 → 3.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/BulkUpload/FormsManager/index.js +2 -2
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/BulkUpload/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/index.js +2 -4
- package/dist/elements/BulkUpload/index.js.map +1 -1
- package/dist/elements/Collapsible/provider.d.ts.map +1 -1
- package/dist/elements/Collapsible/provider.js +3 -5
- package/dist/elements/Collapsible/provider.js.map +1 -1
- package/dist/elements/DocumentDrawer/Provider.d.ts.map +1 -1
- package/dist/elements/DocumentDrawer/Provider.js +3 -3
- package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
- package/dist/elements/Drawer/index.d.ts.map +1 -1
- package/dist/elements/Drawer/index.js +3 -5
- package/dist/elements/Drawer/index.js.map +1 -1
- package/dist/elements/EditMany/DrawerContent.js +1 -1
- package/dist/elements/EditMany/DrawerContent.js.map +1 -1
- package/dist/elements/ListDrawer/Provider.js +3 -3
- package/dist/elements/ListDrawer/Provider.js.map +1 -1
- package/dist/elements/LoadingOverlay/index.js +3 -3
- package/dist/elements/LoadingOverlay/index.js.map +1 -1
- package/dist/elements/Nav/context.d.ts.map +1 -1
- package/dist/elements/Nav/context.js +2 -4
- package/dist/elements/Nav/context.js.map +1 -1
- package/dist/elements/StepNav/context.d.ts.map +1 -1
- package/dist/elements/StepNav/context.js +3 -5
- package/dist/elements/StepNav/context.js.map +1 -1
- package/dist/elements/Table/RelationshipProvider/index.d.ts.map +1 -1
- package/dist/elements/Table/RelationshipProvider/index.js +3 -5
- package/dist/elements/Table/RelationshipProvider/index.js.map +1 -1
- package/dist/elements/TableColumns/RenderDefaultCell/index.d.ts.map +1 -1
- package/dist/elements/TableColumns/RenderDefaultCell/index.js +2 -4
- package/dist/elements/TableColumns/RenderDefaultCell/index.js.map +1 -1
- package/dist/elements/TableColumns/context.d.ts.map +1 -1
- package/dist/elements/TableColumns/context.js +2 -2
- package/dist/elements/TableColumns/context.js.map +1 -1
- package/dist/elements/TableColumns/index.js +1 -1
- package/dist/elements/TableColumns/index.js.map +1 -1
- package/dist/elements/Toasts/fieldErrors.d.ts.map +1 -1
- package/dist/elements/Toasts/fieldErrors.js +2 -2
- package/dist/elements/Toasts/fieldErrors.js.map +1 -1
- package/dist/exports/client/{CodeEditor-TQ5ADFPC.js → CodeEditor-J4IKAVAK.js} +2 -2
- package/dist/exports/client/{DatePicker-HHQ6TPOW.js → DatePicker-DMHV2M2L.js} +2 -2
- package/dist/exports/client/{chunk-IMEQ6NKQ.js → chunk-3AA2TJQ5.js} +2 -2
- package/dist/exports/client/{chunk-IMEQ6NKQ.js.map → chunk-3AA2TJQ5.js.map} +3 -3
- package/dist/exports/client/{chunk-LMYT7O7U.js → chunk-PKQOCWZD.js} +2 -2
- package/dist/exports/client/{chunk-LMYT7O7U.js.map → chunk-PKQOCWZD.js.map} +3 -3
- package/dist/exports/client/index.js +23 -23
- package/dist/exports/client/index.js.map +3 -3
- package/dist/fields/Blocks/BlockRow.d.ts.map +1 -1
- package/dist/fields/Blocks/BlockRow.js +26 -20
- package/dist/fields/Blocks/BlockRow.js.map +1 -1
- package/dist/fields/Group/provider.d.ts.map +1 -1
- package/dist/fields/Group/provider.js +3 -5
- package/dist/fields/Group/provider.js.map +1 -1
- package/dist/fields/Row/provider.d.ts.map +1 -1
- package/dist/fields/Row/provider.js +3 -5
- package/dist/fields/Row/provider.js.map +1 -1
- package/dist/fields/Tabs/provider.d.ts.map +1 -1
- package/dist/fields/Tabs/provider.js +3 -5
- package/dist/fields/Tabs/provider.js.map +1 -1
- package/dist/forms/Form/context.d.ts.map +1 -1
- package/dist/forms/Form/context.js +9 -25
- package/dist/forms/Form/context.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +8 -8
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/RowLabel/Context/index.d.ts.map +1 -1
- package/dist/forms/RowLabel/Context/index.js +2 -2
- package/dist/forms/RowLabel/Context/index.js.map +1 -1
- package/dist/forms/RowLabel/index.d.ts.map +1 -1
- package/dist/forms/RowLabel/index.js +2 -2
- package/dist/forms/RowLabel/index.js.map +1 -1
- package/dist/forms/RowLabel/types.d.ts +1 -1
- package/dist/forms/RowLabel/types.d.ts.map +1 -1
- package/dist/forms/RowLabel/types.js.map +1 -1
- package/dist/hooks/useQueues.js +3 -3
- package/dist/hooks/useQueues.js.map +1 -1
- package/dist/providers/Actions/index.d.ts.map +1 -1
- package/dist/providers/Actions/index.js +3 -5
- package/dist/providers/Actions/index.js.map +1 -1
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js +3 -5
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/ClientFunction/index.d.ts.map +1 -1
- package/dist/providers/ClientFunction/index.js +4 -4
- package/dist/providers/ClientFunction/index.js.map +1 -1
- package/dist/providers/Config/index.d.ts.map +1 -1
- package/dist/providers/Config/index.js +3 -5
- package/dist/providers/Config/index.js.map +1 -1
- package/dist/providers/DocumentEvents/index.d.ts.map +1 -1
- package/dist/providers/DocumentEvents/index.js +3 -5
- package/dist/providers/DocumentEvents/index.js.map +1 -1
- package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
- package/dist/providers/DocumentInfo/index.js +3 -5
- package/dist/providers/DocumentInfo/index.js.map +1 -1
- package/dist/providers/EditDepth/index.d.ts.map +1 -1
- package/dist/providers/EditDepth/index.js +3 -5
- package/dist/providers/EditDepth/index.js.map +1 -1
- package/dist/providers/EntityVisibility/index.d.ts.map +1 -1
- package/dist/providers/EntityVisibility/index.js +3 -5
- package/dist/providers/EntityVisibility/index.js.map +1 -1
- package/dist/providers/ListQuery/context.d.ts.map +1 -1
- package/dist/providers/ListQuery/context.js +2 -2
- package/dist/providers/ListQuery/context.js.map +1 -1
- package/dist/providers/ListQuery/index.js +1 -1
- package/dist/providers/ListQuery/index.js.map +1 -1
- package/dist/providers/Locale/index.d.ts.map +1 -1
- package/dist/providers/Locale/index.js +5 -9
- package/dist/providers/Locale/index.js.map +1 -1
- package/dist/providers/Operation/index.d.ts.map +1 -1
- package/dist/providers/Operation/index.js +3 -5
- package/dist/providers/Operation/index.js.map +1 -1
- package/dist/providers/Params/index.d.ts.map +1 -1
- package/dist/providers/Params/index.js +3 -5
- package/dist/providers/Params/index.js.map +1 -1
- package/dist/providers/Preferences/index.d.ts.map +1 -1
- package/dist/providers/Preferences/index.js +3 -5
- package/dist/providers/Preferences/index.js.map +1 -1
- package/dist/providers/RouteCache/index.d.ts.map +1 -1
- package/dist/providers/RouteCache/index.js +3 -5
- package/dist/providers/RouteCache/index.js.map +1 -1
- package/dist/providers/RouteTransition/index.d.ts.map +1 -1
- package/dist/providers/RouteTransition/index.js +2 -4
- package/dist/providers/RouteTransition/index.js.map +1 -1
- package/dist/providers/SearchParams/index.d.ts.map +1 -1
- package/dist/providers/SearchParams/index.js +3 -5
- package/dist/providers/SearchParams/index.js.map +1 -1
- package/dist/providers/Selection/index.d.ts.map +1 -1
- package/dist/providers/Selection/index.js +3 -5
- package/dist/providers/Selection/index.js.map +1 -1
- package/dist/providers/ServerFunctions/index.js +2 -2
- package/dist/providers/ServerFunctions/index.js.map +1 -1
- package/dist/providers/Theme/index.d.ts.map +1 -1
- package/dist/providers/Theme/index.js +3 -5
- package/dist/providers/Theme/index.js.map +1 -1
- package/dist/providers/Translation/index.d.ts.map +1 -1
- package/dist/providers/Translation/index.js +3 -5
- package/dist/providers/Translation/index.js.map +1 -1
- package/dist/providers/UploadEdits/index.d.ts.map +1 -1
- package/dist/providers/UploadEdits/index.js +2 -4
- package/dist/providers/UploadEdits/index.js.map +1 -1
- package/dist/providers/UploadHandlers/index.d.ts.map +1 -1
- package/dist/providers/UploadHandlers/index.js +3 -3
- package/dist/providers/UploadHandlers/index.js.map +1 -1
- package/package.json +5 -5
- /package/dist/exports/client/{CodeEditor-TQ5ADFPC.js.map → CodeEditor-J4IKAVAK.js.map} +0 -0
- /package/dist/exports/client/{DatePicker-HHQ6TPOW.js.map → DatePicker-DMHV2M2L.js.map} +0 -0
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
-
import React, { createContext,
|
|
4
|
+
import React, { createContext, use } from 'react';
|
|
5
5
|
export const OperationContext = /*#__PURE__*/createContext('');
|
|
6
6
|
export const OperationProvider = ({
|
|
7
7
|
children,
|
|
8
8
|
operation
|
|
9
|
-
}) => /*#__PURE__*/_jsx(OperationContext
|
|
9
|
+
}) => /*#__PURE__*/_jsx(OperationContext, {
|
|
10
10
|
value: operation,
|
|
11
11
|
children: children
|
|
12
12
|
});
|
|
13
|
-
export const useOperation = () =>
|
|
14
|
-
return useContext(OperationContext);
|
|
15
|
-
};
|
|
13
|
+
export const useOperation = () => use(OperationContext);
|
|
16
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","createContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","createContext","use","OperationContext","OperationProvider","children","operation","_jsx","value","useOperation"],"sources":["../../../src/providers/Operation/index.tsx"],"sourcesContent":["'use client'\nimport React, { createContext, use } from 'react'\n\nexport const OperationContext = createContext('' as Operation)\n\nexport const OperationProvider: React.FC<{ children: React.ReactNode; operation: Operation }> = ({\n children,\n operation,\n}) => <OperationContext value={operation}>{children}</OperationContext>\n\nexport type Operation = 'create' | 'update'\n\nexport const useOperation = (): Operation | undefined => use(OperationContext)\n"],"mappings":"AAAA;;;AACA,OAAOA,KAAA,IAASC,aAAa,EAAEC,GAAG,QAAQ;AAE1C,OAAO,MAAMC,gBAAA,gBAAmBF,aAAA,CAAc;AAE9C,OAAO,MAAMG,iBAAA,GAAmFA,CAAC;EAC/FC,QAAQ;EACRC;AAAS,CACV,kBAAKC,IAAA,CAACJ,gBAAA;EAAiBK,KAAA,EAAOF,SAAA;YAAYD;;AAI3C,OAAO,MAAMI,YAAA,GAAeA,CAAA,KAA6BP,GAAA,CAAIC,gBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Params/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Params/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAA6B,MAAM,OAAO,CAAA;AAEjD,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA;AACrD,UAAU,cAAe,SAAQ,MAAM;CAAG;AAI1C;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAGnE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,QAAO,cAA8B,CAAA"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useParams as useNextParams } from 'next/navigation.js';
|
|
6
|
-
import React, { createContext,
|
|
6
|
+
import React, { createContext, use } from 'react';
|
|
7
7
|
const Context = /*#__PURE__*/createContext({});
|
|
8
8
|
/**
|
|
9
9
|
* @deprecated
|
|
@@ -21,7 +21,7 @@ export const ParamsProvider = t0 => {
|
|
|
21
21
|
const params = useNextParams();
|
|
22
22
|
let t1;
|
|
23
23
|
if ($[0] !== children || $[1] !== params) {
|
|
24
|
-
t1 = _jsx(Context
|
|
24
|
+
t1 = _jsx(Context, {
|
|
25
25
|
value: params,
|
|
26
26
|
children
|
|
27
27
|
});
|
|
@@ -41,7 +41,5 @@ export const ParamsProvider = t0 => {
|
|
|
41
41
|
* import { useParams } from 'next/navigation'
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
export const useParams = () =>
|
|
45
|
-
return useContext(Context);
|
|
46
|
-
};
|
|
44
|
+
export const useParams = () => use(Context);
|
|
47
45
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useParams","useNextParams","React","createContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useParams","useNextParams","React","createContext","use","Context","ParamsProvider","t0","$","children","params","t1","_jsx","value"],"sources":["../../../src/providers/Params/index.tsx"],"sourcesContent":["'use client'\n\nimport { useParams as useNextParams } from 'next/navigation.js'\nimport React, { createContext, use } from 'react'\n\nexport type Params = ReturnType<typeof useNextParams>\ninterface IParamsContext extends Params {}\n\nconst Context = createContext<IParamsContext>({} as IParamsContext)\n\n/**\n * @deprecated\n * The ParamsProvider is deprecated and will be removed in the next major release. Instead, use the `useParams` hook from `next/navigation` directly. See https://github.com/payloadcms/payload/pull/9581.\n * @example\n * ```tsx\n * import { useParams } from 'next/navigation'\n * ```\n */\nexport const ParamsProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const params = useNextParams()\n return <Context value={params}>{children}</Context>\n}\n\n/**\n * @deprecated\n * The `useParams` hook is deprecated and will be removed in the next major release. Instead, use the `useParams` hook from `next/navigation` directly. See https://github.com/payloadcms/payload/pull/9581.\n * @example\n * ```tsx\n * import { useParams } from 'next/navigation'\n * ```\n */\nexport const useParams = (): IParamsContext => use(Context)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,SAAA,IAAaC,aAAa,QAAQ;AAC3C,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,QAAQ;AAK1C,MAAMC,OAAA,gBAAUF,aAAA,CAA8B,CAAC;AAE/C;;;;;;;;AAQA,OAAO,MAAMG,cAAA,GAA2DC,EAAA;EAAA,MAAAC,CAAA,GAAAT,EAAA;EAAC;IAAAU;EAAA,IAAAF,EAAY;EACnF,MAAAG,MAAA,GAAeT,aAAA;EAAA,IAAAU,EAAA;EAAA,IAAAH,CAAA,QAAAC,QAAA,IAAAD,CAAA,QAAAE,MAAA;IACRC,EAAA,GAAAC,IAAA,CAAAP,OAAA;MAAAQ,KAAA,EAAgBH,MAAA;MAAAD;IAAA,C;;;;;;;SAAhBE,E;CACT;AAEA;;;;;;;;AAQA,OAAO,MAAMX,SAAA,GAAYA,CAAA,KAAsBI,GAAA,CAAIC,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Preferences/index.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Preferences/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA6D,MAAM,OAAO,CAAA;AAQjF,KAAK,kBAAkB,GAAG;IACxB,aAAa,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;IACnD;;;;OAIG;IACH,aAAa,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAClF,CAAA;AAYD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CA0HxE,CAAA;AAED,eAAO,MAAM,cAAc,QAAO,kBAAkC,CAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { dequal } from 'dequal/lite'; // lite: no need for Map and Set support
|
|
5
|
-
import React, { createContext,
|
|
5
|
+
import React, { createContext, use, useCallback, useEffect, useRef } from 'react';
|
|
6
6
|
import { useTranslation } from '../../providers/Translation/index.js';
|
|
7
7
|
import { requests } from '../../utilities/api.js';
|
|
8
8
|
import { deepMergeSimple } from '../../utilities/deepMerge.js';
|
|
@@ -115,12 +115,10 @@ export const PreferencesProvider = ({
|
|
|
115
115
|
}, [api, getPreference, i18n.language, pendingUpdate, serverURL]);
|
|
116
116
|
contextRef.current.getPreference = getPreference;
|
|
117
117
|
contextRef.current.setPreference = setPreference;
|
|
118
|
-
return /*#__PURE__*/_jsx(Context
|
|
118
|
+
return /*#__PURE__*/_jsx(Context, {
|
|
119
119
|
value: contextRef.current,
|
|
120
120
|
children: children
|
|
121
121
|
});
|
|
122
122
|
};
|
|
123
|
-
export const usePreferences = () =>
|
|
124
|
-
return useContext(Context);
|
|
125
|
-
};
|
|
123
|
+
export const usePreferences = () => use(Context);
|
|
126
124
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["dequal","React","createContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["dequal","React","createContext","use","useCallback","useEffect","useRef","useTranslation","requests","deepMergeSimple","useAuth","useConfig","Context","requestOptions","value","language","body","JSON","stringify","headers","PreferencesProvider","children","contextRef","preferencesRef","pendingUpdate","config","user","i18n","routes","api","serverURL","current","getPreference","key","prefs","promise","Promise","resolve","request","get","status","preference","json","setPreference","merge","post","newValue","currentPreference","updatePreference","setTimeout","_jsx","usePreferences"],"sources":["../../../src/providers/Preferences/index.tsx"],"sourcesContent":["'use client'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport React, { createContext, use, useCallback, useEffect, useRef } from 'react'\n\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { deepMergeSimple } from '../../utilities/deepMerge.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\n\ntype PreferencesContext = {\n getPreference: <T = any>(key: string) => Promise<T>\n /**\n * @param key - a string identifier for the property being set\n * @param value - preference data to store\n * @param merge - when true will combine the existing preference object batch the change into one request for objects, default = false\n */\n setPreference: <T = any>(key: string, value: T, merge?: boolean) => Promise<void>\n}\n\nconst Context = createContext({} as PreferencesContext)\n\nconst requestOptions = (value, language) => ({\n body: JSON.stringify({ value }),\n headers: {\n 'Accept-Language': language,\n 'Content-Type': 'application/json',\n },\n})\n\nexport const PreferencesProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const contextRef = useRef({} as PreferencesContext)\n const preferencesRef = useRef({})\n const pendingUpdate = useRef({})\n const { config } = useConfig()\n const { user } = useAuth()\n const { i18n } = useTranslation()\n\n const {\n routes: { api },\n serverURL,\n } = config\n\n useEffect(() => {\n if (!user) {\n // clear preferences between users\n preferencesRef.current = {}\n }\n }, [user])\n\n const getPreference = useCallback(\n async <T = any,>(key: string): Promise<T> => {\n const prefs = preferencesRef.current\n if (typeof prefs[key] !== 'undefined') {\n return prefs[key]\n }\n const promise = new Promise((resolve: (value: T) => void) => {\n void (async () => {\n const request = await requests.get(`${serverURL}${api}/payload-preferences/${key}`, {\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n let value = null\n if (request.status === 200) {\n const preference = await request.json()\n value = preference.value\n }\n preferencesRef.current[key] = value\n resolve(value)\n })()\n })\n prefs[key] = promise\n return promise\n },\n [i18n.language, api, preferencesRef, serverURL],\n )\n\n const setPreference = useCallback(\n async (key: string, value: unknown, merge = false): Promise<void> => {\n if (merge === false) {\n preferencesRef.current[key] = value\n\n await requests.post(\n `${serverURL}${api}/payload-preferences/${key}`,\n requestOptions(value, i18n.language),\n )\n\n return\n }\n\n let newValue = value\n const currentPreference = await getPreference(key)\n\n // handle value objects where multiple values can be set under one key\n if (\n typeof value === 'object' &&\n typeof currentPreference === 'object' &&\n typeof newValue === 'object'\n ) {\n // merge the value with any existing preference for the key\n if (currentPreference) {\n newValue = deepMergeSimple(currentPreference, newValue)\n }\n\n if (dequal(newValue, currentPreference)) {\n return\n }\n\n // add the requested changes to a pendingUpdate batch for the key\n pendingUpdate.current[key] = {\n ...pendingUpdate.current[key],\n ...(newValue as Record<string, unknown>),\n }\n } else {\n if (newValue === currentPreference) {\n return\n }\n\n pendingUpdate.current[key] = newValue\n }\n\n const updatePreference = async () => {\n // compare the value stored in context before sending to eliminate duplicate requests\n if (dequal(pendingUpdate.current[key], preferencesRef.current[key])) {\n return\n }\n\n // preference set in context here to prevent other updatePreference at the same time\n preferencesRef.current[key] = pendingUpdate.current[key]\n\n await requests.post(\n `${serverURL}${api}/payload-preferences/${key}`,\n requestOptions(preferencesRef.current[key], i18n.language),\n )\n\n // reset any changes for this key after sending the request\n delete pendingUpdate.current[key]\n }\n\n // use timeout to allow multiple changes of different values using the same key in one request\n setTimeout(() => {\n void updatePreference()\n })\n },\n [api, getPreference, i18n.language, pendingUpdate, serverURL],\n )\n\n contextRef.current.getPreference = getPreference\n contextRef.current.setPreference = setPreference\n\n return <Context value={contextRef.current}>{children}</Context>\n}\n\nexport const usePreferences = (): PreferencesContext => use(Context)\n"],"mappings":"AAAA;;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AACrC,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAE1E,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,eAAe,QAAQ;AAChC,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAY1B,MAAMC,OAAA,gBAAUV,aAAA,CAAc,CAAC;AAE/B,MAAMW,cAAA,GAAiBA,CAACC,KAAA,EAAOC,QAAA,MAAc;EAC3CC,IAAA,EAAMC,IAAA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,QAAA;IAC/B;IAEA,MAAME,gBAAA,GAAmB,MAAAA,CAAA;MACvB;MACA,IAAIhD,MAAA,CAAOwB,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI,EAAEV,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAG;QACnE;MACF;MAEA;MACAV,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAGT,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI;MAExD,MAAMzB,QAAA,CAASqC,IAAI,CACjB,GAAGf,SAAA,GAAYD,GAAA,wBAA2BI,KAAA,EAAK,EAC/CpB,cAAA,CAAeU,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,EAAEN,IAAA,CAAKZ,QAAQ;MAG3D;MACA,OAAOS,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI;IACnC;IAEA;IACAgB,UAAA,CAAW;MACT,KAAKD,gBAAA;IACP;EACF,GACA,CAACnB,GAAA,EAAKG,aAAA,EAAeL,IAAA,CAAKZ,QAAQ,EAAES,aAAA,EAAeM,SAAA,CAAU;EAG/DR,UAAA,CAAWS,OAAO,CAACC,aAAa,GAAGA,aAAA;EACnCV,UAAA,CAAWS,OAAO,CAACY,aAAa,GAAGA,aAAA;EAEnC,oBAAOO,IAAA,CAACtC,OAAA;IAAQE,KAAA,EAAOQ,UAAA,CAAWS,OAAO;cAAGV;;AAC9C;AAEA,OAAO,MAAM8B,cAAA,GAAiBA,CAAA,KAA0BhD,GAAA,CAAIS,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/RouteCache/index.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/RouteCache/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAqD,MAAM,OAAO,CAAA;AAEzE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,IAAI,CAAA;CAC5B,CAAA;AAMD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAa9D,CAAA;AAED,eAAO,MAAM,aAAa,yBAAqB,CAAA"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { usePathname, useRouter } from 'next/navigation.js';
|
|
6
|
-
import React, { createContext,
|
|
6
|
+
import React, { createContext, use, useCallback, useEffect } from 'react';
|
|
7
7
|
const Context = /*#__PURE__*/createContext({
|
|
8
8
|
clearRouteCache: () => {}
|
|
9
9
|
});
|
|
@@ -47,7 +47,7 @@ export const RouteCache = t0 => {
|
|
|
47
47
|
useEffect(t2, t3);
|
|
48
48
|
let t4;
|
|
49
49
|
if ($[7] !== children || $[8] !== clearRouteCache) {
|
|
50
|
-
t4 = _jsx(Context
|
|
50
|
+
t4 = _jsx(Context, {
|
|
51
51
|
value: {
|
|
52
52
|
clearRouteCache
|
|
53
53
|
},
|
|
@@ -61,7 +61,5 @@ export const RouteCache = t0 => {
|
|
|
61
61
|
}
|
|
62
62
|
return t4;
|
|
63
63
|
};
|
|
64
|
-
export const useRouteCache = () =>
|
|
65
|
-
return useContext(Context);
|
|
66
|
-
};
|
|
64
|
+
export const useRouteCache = () => use(Context);
|
|
67
65
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","usePathname","useRouter","React","createContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","usePathname","useRouter","React","createContext","use","useCallback","useEffect","Context","clearRouteCache","RouteCache","t0","$","children","pathname","router","t1","refresh","t2","t3","t4","_jsx","value","useRouteCache"],"sources":["../../../src/providers/RouteCache/index.tsx"],"sourcesContent":["'use client'\n\nimport { usePathname, useRouter } from 'next/navigation.js'\nimport React, { createContext, use, useCallback, useEffect } from 'react'\n\nexport type RouteCacheContext = {\n clearRouteCache: () => void\n}\n\nconst Context = createContext<RouteCacheContext>({\n clearRouteCache: () => {},\n})\n\nexport const RouteCache: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const pathname = usePathname()\n const router = useRouter()\n\n const clearRouteCache = useCallback(() => {\n router.refresh()\n }, [router])\n\n useEffect(() => {\n clearRouteCache()\n }, [pathname, clearRouteCache])\n\n return <Context value={{ clearRouteCache }}>{children}</Context>\n}\n\nexport const useRouteCache = () => use(Context)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,WAAW,EAAEC,SAAS,QAAQ;AACvC,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,QAAQ;AAMlE,MAAMC,OAAA,gBAAUJ,aAAA,CAAiC;EAC/CK,eAAA,EAAiBA,CAAA,MAAO;AAC1B;AAEA,OAAO,MAAMC,UAAA,GAAsDC,EAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAAC;IAAAa;EAAA,IAAAF,EAAY;EAC9E,MAAAG,QAAA,GAAiBb,WAAA;EACjB,MAAAc,MAAA,GAAeb,SAAA;EAAA,IAAAc,EAAA;EAAA,IAAAJ,CAAA,QAAAG,MAAA;IAEqBC,EAAA,GAAAA,CAAA;MAClCD,MAAA,CAAAE,OAAA,CAAc;IAAA;IAChBL,CAAA,MAAAG,MAAA;IAAAH,CAAA,MAAAI,EAAA;EAAA;IAAAA,EAAA,GAAAJ,CAAA;EAAA;EAFA,MAAAH,eAAA,GAAwBO,EAEb;EAAA,IAAAE,EAAA;EAAA,IAAAN,CAAA,QAAAH,eAAA;IAEDS,EAAA,GAAAA,CAAA;MACRT,eAAA;IAAA;IACFG,CAAA,MAAAH,eAAA;IAAAG,CAAA,MAAAM,EAAA;EAAA;IAAAA,EAAA,GAAAN,CAAA;EAAA;EAAA,IAAAO,EAAA;EAAA,IAAAP,CAAA,QAAAH,eAAA,IAAAG,CAAA,QAAAE,QAAA;IAAGK,EAAA,IAACL,QAAA,EAAUL,eAAA;IAAgBG,CAAA,MAAAH,eAAA;IAAAG,CAAA,MAAAE,QAAA;IAAAF,CAAA,MAAAO,EAAA;EAAA;IAAAA,EAAA,GAAAP,CAAA;EAAA;EAF9BL,SAAA,CAAUW,EAEV,EAAGC,EAA2B;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,QAAA,IAAAD,CAAA,QAAAH,eAAA;IAEvBW,EAAA,GAAAC,IAAA,CAAAb,OAAA;MAAAc,KAAA;QAAAb;MAAA;MAAAI;IAAA,C;;;;;;;SAAAO,E;CACT;AAEA,OAAO,MAAMG,aAAA,GAAgBA,CAAA,KAAMlB,GAAA,CAAIG,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/RouteTransition/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAyE,MAAM,OAAO,CAAA;AAE7F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/RouteTransition/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAyE,MAAM,OAAO,CAAA;AAE7F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA6DlE,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,KAAK,oBAAoB,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAE3D,KAAK,2BAA2B,GAAG;IACjC,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,kBAAkB,mCAA0C,CAAA"}
|
|
@@ -83,7 +83,7 @@ export const RouteTransitionProvider = t0 => {
|
|
|
83
83
|
const startRouteTransition = t4;
|
|
84
84
|
let t5;
|
|
85
85
|
if ($[6] !== children || $[7] !== isTransitioning || $[8] !== startRouteTransition || $[9] !== transitionProgress) {
|
|
86
|
-
t5 = _jsx(RouteTransitionContext
|
|
86
|
+
t5 = _jsx(RouteTransitionContext, {
|
|
87
87
|
value: {
|
|
88
88
|
isTransitioning,
|
|
89
89
|
startRouteTransition,
|
|
@@ -127,7 +127,5 @@ const RouteTransitionContext = /*#__PURE__*/React.createContext({
|
|
|
127
127
|
* // ...
|
|
128
128
|
* }
|
|
129
129
|
*/
|
|
130
|
-
export const useRouteTransition = () =>
|
|
131
|
-
return React.useContext(RouteTransitionContext);
|
|
132
|
-
};
|
|
130
|
+
export const useRouteTransition = () => React.use(RouteTransitionContext);
|
|
133
131
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","startTransition","useCallback","useEffect","useOptimistic","useRef","RouteTransitionProvider","t0","$","children","isTransitioning","setIsTransitioning","transitionProgress","setTransitionProgress","useState","transitionProgressRef","timerID","t1","Symbol","for","current","setInterval","newProgress","Math","random","pow","log","initiateProgress","t2","t3","clearInterval","t4","callback","startRouteTransition","t5","_jsx","RouteTransitionContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","startTransition","useCallback","useEffect","useOptimistic","useRef","RouteTransitionProvider","t0","$","children","isTransitioning","setIsTransitioning","transitionProgress","setTransitionProgress","useState","transitionProgressRef","timerID","t1","Symbol","for","current","setInterval","newProgress","Math","random","pow","log","initiateProgress","t2","t3","clearInterval","t4","callback","startRouteTransition","t5","_jsx","RouteTransitionContext","value","createContext","undefined","useRouteTransition","use"],"sources":["../../../src/providers/RouteTransition/index.tsx"],"sourcesContent":["'use client'\nimport React, { startTransition, useCallback, useEffect, useOptimistic, useRef } from 'react'\n\n/**\n * Route transitions are useful in showing immediate visual feedback to the user when navigating between pages. This is especially useful on slow networks when navigating to data heavy or process intensive pages.\n * To use route transitions, place the `RouteTransitionProvider` at the root of your application, outside of the `ProgressBar` component.\n * To trigger a route transition, use the `Link` component from `@payloadcms/ui`,\n * or wrap a callback function with the `startRouteTransition` method.\n * To gain access to the `RouteTransitionContext`, call the `useRouteTransition` hook in your component.\n * @returns A context provider with methods and state for transitioning between routes, including `isTransitioning`, `startRouteTransition`, and `transitionProgress`.\n * @example\n * import { RouteTransitionProvider, ProgressBar, Link } from '@payloadcms/ui'\n * const App = () => (\n * <RouteTransitionProvider>\n * <ProgressBar />\n * <Link href=\"/somewhere\">Go Somewhere</Link>\n * </RouteTransitionProvider>\n * )\n */\nexport const RouteTransitionProvider: React.FC<RouteTransitionProps> = ({ children }) => {\n const [isTransitioning, setIsTransitioning] = useOptimistic(false)\n const [transitionProgress, setTransitionProgress] = React.useState<number>(0)\n\n const transitionProgressRef = useRef(transitionProgress)\n\n const timerID = useRef(null)\n\n const initiateProgress = useCallback(() => {\n timerID.current = setInterval(() => {\n // randomly update progress using an exponential curve\n // cap the progress to ensure it never fully reaches completion\n // accelerate quickly then decelerate slowly\n const maxProgress = 0.93\n const jumpFactor = 0.2 // lower to reduce jumps in progress\n const growthFactor = 0.75 // adjust to control acceleration\n const slowdownFactor = 0.75 // adjust to control deceleration\n\n const newProgress =\n transitionProgressRef.current +\n (maxProgress - transitionProgressRef.current) *\n Math.random() *\n jumpFactor *\n Math.pow(Math.log(1 + (1 - transitionProgressRef.current) * growthFactor), slowdownFactor)\n\n setTransitionProgress(newProgress)\n transitionProgressRef.current = newProgress\n }, 250) // every n ms, update progress\n }, [])\n\n useEffect(() => {\n setTransitionProgress(0)\n transitionProgressRef.current = 0\n\n if (isTransitioning) {\n initiateProgress()\n } else {\n if (timerID.current) {\n clearInterval(timerID.current)\n }\n }\n }, [isTransitioning, initiateProgress])\n\n const startRouteTransition: StartRouteTransition = useCallback(\n (callback?: () => void) => {\n startTransition(() => {\n setIsTransitioning(true)\n\n if (typeof callback === 'function') {\n callback()\n }\n })\n },\n [setIsTransitioning],\n )\n\n return (\n <RouteTransitionContext value={{ isTransitioning, startRouteTransition, transitionProgress }}>\n {children}\n </RouteTransitionContext>\n )\n}\n\ntype RouteTransitionProps = {\n children: React.ReactNode\n}\n\ntype StartRouteTransition = (callback?: () => void) => void\n\ntype RouteTransitionContextValue = {\n isTransitioning: boolean\n startRouteTransition: StartRouteTransition\n transitionProgress: number\n}\n\nconst RouteTransitionContext = React.createContext<RouteTransitionContextValue>({\n isTransitioning: false,\n startRouteTransition: () => undefined,\n transitionProgress: 0,\n})\n\n/**\n * Use this hook to access the `RouteTransitionContext` provided by the `RouteTransitionProvider`.\n * To start a transition, fire the `startRouteTransition` method with a provided callback to run while the transition takes place.\n * @returns The `RouteTransitionContext` needed for transitioning between routes, including `isTransitioning`, `startRouteTransition`, and `transitionProgress`.\n * @example\n * 'use client'\n * import React, { useCallback } from 'react'\n * import { useTransition } from '@payloadcms/ui'\n * import { useRouter } from 'next/navigation'\n *\n * const MyComponent: React.FC = () => {\n * const router = useRouter()\n * const { startRouteTransition } = useRouteTransition()\n *\n * const redirectSomewhere = useCallback(() => {\n * startRouteTransition(() => router.push('/somewhere'))\n * }, [startRouteTransition, router])\n *\n * // ...\n * }\n */\nexport const useRouteTransition = () => React.use(RouteTransitionContext)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,eAAe,EAAEC,WAAW,EAAEC,SAAS,EAAEC,aAAa,EAAEC,MAAM,QAAQ;AAEtF;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMC,uBAAA,GAA0DC,EAAA;EAAA,MAAAC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;EAAA;IAAAD,EAAA,GAAApB,CAAA;IAAAqB,EAAA,GAAArB,CAAA;EAAA;EAXtCL,SAAA,CAAUyB,EAWV,EAAGC,EAAmC;EAAA,IAAAE,EAAA;EAAA,IAAAvB,CAAA,QAAAG,kBAAA;IAGpCoB,EAAA,GAAAC,QAAA;MACE/B,eAAA;QACEU,kBAAA,KAAmB;QAAA,IAEf,OAAOqB,QAAA,KAAa;UACtBA,QAAA;QAAA;MAAA,CAEJ;IAAA;IACFxB,CAAA,MAAAG,kBAAA;IAAAH,CAAA,MAAAuB,EAAA;EAAA;IAAAA,EAAA,GAAAvB,CAAA;EAAA;EATF,MAAAyB,oBAAA,GAAmDF,EAU7B;EAAA,IAAAG,EAAA;EAAA,IAAA1B,CAAA,QAAAC,QAAA,IAAAD,CAAA,QAAAE,eAAA,IAAAF,CAAA,QAAAyB,oBAAA,IAAAzB,CAAA,QAAAI,kBAAA;IAIpBsB,EAAA,GAAAC,IAAA,CAAAC,sBAAA;MAAAC,KAAA;QAAA3B,eAAA;QAAAuB,oBAAA;QAAArB;MAAA;MAAAH;IAAA,C;;;;;;;;;SAAAyB,E;CAIJ;AAcA,MAAME,sBAAA,gBAAyBpC,KAAA,CAAMsC,aAAa,CAA8B;EAC9E5B,eAAA,EAAiB;EACjBuB,oBAAA,EAAsBA,CAAA,KAAMM,SAAA;EAC5B3B,kBAAA,EAAoB;AACtB;AAEA;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,MAAM4B,kBAAA,GAAqBA,CAAA,KAAMxC,KAAA,CAAMyC,GAAG,CAACL,sBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/SearchParams/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/SearchParams/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,KAA6B,MAAM,OAAO,CAAA;AAEjD,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,EAAE,CAAC,QAAQ,CAAA;IACzB,eAAe,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;QAAE,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,MAAM,CAAA;CAC7F,CAAA;AASD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CA2BzE,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,QAAO,mBAAmC,CAAA"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { useSearchParams as useNextSearchParams } from 'next/navigation.js';
|
|
5
5
|
import * as qs from 'qs-esm';
|
|
6
|
-
import React, { createContext,
|
|
6
|
+
import React, { createContext, use } from 'react';
|
|
7
7
|
const initialContext = {
|
|
8
8
|
searchParams: {},
|
|
9
9
|
stringifyParams: () => ''
|
|
@@ -37,7 +37,7 @@ export const SearchParamsProvider = ({
|
|
|
37
37
|
addQueryPrefix: true
|
|
38
38
|
});
|
|
39
39
|
}, [searchParams]);
|
|
40
|
-
return /*#__PURE__*/_jsx(Context
|
|
40
|
+
return /*#__PURE__*/_jsx(Context, {
|
|
41
41
|
value: {
|
|
42
42
|
searchParams,
|
|
43
43
|
stringifyParams
|
|
@@ -58,7 +58,5 @@ export const SearchParamsProvider = ({
|
|
|
58
58
|
* const parsedSearchParams = parseSearchParams(searchParams)
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export const useSearchParams = () =>
|
|
62
|
-
return useContext(Context);
|
|
63
|
-
};
|
|
61
|
+
export const useSearchParams = () => use(Context);
|
|
64
62
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useSearchParams","useNextSearchParams","qs","React","createContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["useSearchParams","useNextSearchParams","qs","React","createContext","use","initialContext","searchParams","stringifyParams","Context","SearchParamsProvider","children","nextSearchParams","searchString","toString","useMemo","parse","depth","ignoreQueryPrefix","useCallback","params","replace","stringify","addQueryPrefix","_jsx","value"],"sources":["../../../src/providers/SearchParams/index.tsx"],"sourcesContent":["'use client'\n\nimport { useSearchParams as useNextSearchParams } from 'next/navigation.js'\nimport * as qs from 'qs-esm'\nimport React, { createContext, use } from 'react'\n\nexport type SearchParamsContext = {\n searchParams: qs.ParsedQs\n stringifyParams: ({ params, replace }: { params: qs.ParsedQs; replace?: boolean }) => string\n}\n\nconst initialContext: SearchParamsContext = {\n searchParams: {},\n stringifyParams: () => '',\n}\n\nconst Context = createContext(initialContext)\n\n/**\n * @deprecated\n * The SearchParamsProvider is deprecated and will be removed in the next major release. Instead, use the `useSearchParams` hook from `next/navigation` directly. See https://github.com/payloadcms/payload/pull/9581.\n * @example\n * ```tsx\n * import { useSearchParams } from 'next/navigation'\n * ```\n */\nexport const SearchParamsProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const nextSearchParams = useNextSearchParams()\n const searchString = nextSearchParams.toString()\n\n const searchParams = React.useMemo(\n () =>\n qs.parse(searchString, {\n depth: 10,\n ignoreQueryPrefix: true,\n }),\n [searchString],\n )\n\n const stringifyParams = React.useCallback(\n ({ params, replace = false }: { params: qs.ParsedQs; replace?: boolean }) => {\n return qs.stringify(\n {\n ...(replace ? {} : searchParams),\n ...params,\n },\n { addQueryPrefix: true },\n )\n },\n [searchParams],\n )\n\n return <Context value={{ searchParams, stringifyParams }}>{children}</Context>\n}\n\n/**\n * @deprecated\n * The `useSearchParams` hook is deprecated and will be removed in the next major release. Instead, use the `useSearchParams` hook from `next/navigation` directly. See https://github.com/payloadcms/payload/pull/9581.\n * @example\n * ```tsx\n * import { useSearchParams } from 'next/navigation'\n * ```\n * If you need to parse the `where` query, you can do so with the `parseSearchParams` utility.\n * ```tsx\n * import { parseSearchParams } from '@payloadcms/ui'\n * const parsedSearchParams = parseSearchParams(searchParams)\n * ```\n */\nexport const useSearchParams = (): SearchParamsContext => use(Context)\n"],"mappings":"AAAA;;;AAEA,SAASA,eAAA,IAAmBC,mBAAmB,QAAQ;AACvD,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,QAAQ;AAO1C,MAAMC,cAAA,GAAsC;EAC1CC,YAAA,EAAc,CAAC;EACfC,eAAA,EAAiBA,CAAA,KAAM;AACzB;AAEA,MAAMC,OAAA,gBAAUL,aAAA,CAAcE,cAAA;AAE9B;;;;;;;;AAQA,OAAO,MAAMI,oBAAA,GAAiEA,CAAC;EAAEC;AAAQ,CAAE;EACzF,MAAMC,gBAAA,GAAmBX,mBAAA;EACzB,MAAMY,YAAA,GAAeD,gBAAA,CAAiBE,QAAQ;EAE9C,MAAMP,YAAA,GAAeJ,KAAA,CAAMY,OAAO,CAChC,MACEb,EAAA,CAAGc,KAAK,CAACH,YAAA,EAAc;IACrBI,KAAA,EAAO;IACPC,iBAAA,EAAmB;EACrB,IACF,CAACL,YAAA,CAAa;EAGhB,MAAML,eAAA,GAAkBL,KAAA,CAAMgB,WAAW,CACvC,CAAC;IAAEC,MAAM;IAAEC,OAAA,GAAU;EAAK,CAA8C;IACtE,OAAOnB,EAAA,CAAGoB,SAAS,CACjB;MACE,IAAID,OAAA,GAAU,CAAC,IAAId,YAAY;MAC/B,GAAGa;IACL,GACA;MAAEG,cAAA,EAAgB;IAAK;EAE3B,GACA,CAAChB,YAAA,CAAa;EAGhB,oBAAOiB,IAAA,CAACf,OAAA;IAAQgB,KAAA,EAAO;MAAElB,YAAA;MAAcC;IAAgB;cAAIG;;AAC7D;AAEA;;;;;;;;;;;;;AAaA,OAAO,MAAMX,eAAA,GAAkBA,CAAA,KAA2BK,GAAA,CAAII,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Selection/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIhD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Selection/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIhD,OAAO,KAAuE,MAAM,OAAO,CAAA;AAK3F,oBAAY,eAAe;IACzB,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,cAAc,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,KAAK,MAAM,CAAA;IACpD,SAAS,EAAE,eAAe,CAAA;IAC1B,QAAQ,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAA;IACvC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAA;IAC3C,SAAS,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAID,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IAElC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAoK7C,CAAA;AAED,eAAO,MAAM,YAAY,QAAO,gBAAgC,CAAA"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { useSearchParams } from 'next/navigation.js';
|
|
5
5
|
import * as qs from 'qs-esm';
|
|
6
|
-
import React, { createContext,
|
|
6
|
+
import React, { createContext, use, useCallback, useEffect, useRef, useState } from 'react';
|
|
7
7
|
import { parseSearchParams } from '../../utilities/parseSearchParams.js';
|
|
8
8
|
import { useLocale } from '../Locale/index.js';
|
|
9
9
|
export var SelectAllStatus = /*#__PURE__*/function (SelectAllStatus) {
|
|
@@ -159,12 +159,10 @@ export const SelectionProvider = ({
|
|
|
159
159
|
toggleAll,
|
|
160
160
|
totalDocs
|
|
161
161
|
};
|
|
162
|
-
return /*#__PURE__*/_jsx(Context
|
|
162
|
+
return /*#__PURE__*/_jsx(Context, {
|
|
163
163
|
value: contextRef.current,
|
|
164
164
|
children: children
|
|
165
165
|
});
|
|
166
166
|
};
|
|
167
|
-
export const useSelection = () =>
|
|
168
|
-
return useContext(Context);
|
|
169
|
-
};
|
|
167
|
+
export const useSelection = () => use(Context);
|
|
170
168
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useSearchParams","qs","React","createContext","useCallback","useContext","useEffect","useRef","useState","parseSearchParams","useLocale","SelectAllStatus","Context","SelectionProvider","children","docs","totalDocs","user","contextRef","code","locale","selected","setSelected","rows","Map","forEach","id","set","selectAll","setSelectAll","count","setCount","searchParams","toggleAll","allAvailable","_isLocked","_userEditing","setSelection","doc","find","existingValue","get","isSelected","newMap","getQueryParams","additionalWhereParams","where","params","not_equals","ids","key","value","push","in","and","stringify","addQueryPrefix","some","all","size","_","length","newCount","current","_jsx","Provider","useSelection"],"sources":["../../../src/providers/Selection/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientUser, Where } from 'payload'\n\nimport { useSearchParams } from 'next/navigation.js'\nimport * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'\n\nimport { parseSearchParams } from '../../utilities/parseSearchParams.js'\nimport { useLocale } from '../Locale/index.js'\n\nexport enum SelectAllStatus {\n AllAvailable = 'allAvailable',\n AllInPage = 'allInPage',\n None = 'none',\n Some = 'some',\n}\n\ntype SelectionContext = {\n count: number\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n getQueryParams: (additionalParams?: Where) => string\n selectAll: SelectAllStatus\n selected: Map<number | string, boolean>\n setSelection: (id: number | string) => void\n toggleAll: (allAvailable?: boolean) => void\n totalDocs: number\n}\n\nconst Context = createContext({} as SelectionContext)\n\ntype Props = {\n readonly children: React.ReactNode\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly docs: any[]\n readonly totalDocs: number\n user: ClientUser\n}\n\nexport const SelectionProvider: React.FC<Props> = ({ children, docs = [], totalDocs, user }) => {\n const contextRef = useRef({} as SelectionContext)\n\n const { code: locale } = useLocale()\n\n const [selected, setSelected] = useState<SelectionContext['selected']>(() => {\n const rows = new Map()\n docs.forEach(({ id }) => {\n rows.set(id, false)\n })\n return rows\n })\n\n const [selectAll, setSelectAll] = useState<SelectAllStatus>(SelectAllStatus.None)\n const [count, setCount] = useState(0)\n const searchParams = useSearchParams()\n\n const toggleAll = useCallback(\n (allAvailable = false) => {\n const rows = new Map()\n if (allAvailable) {\n setSelectAll(SelectAllStatus.AllAvailable)\n docs.forEach(({ id, _isLocked, _userEditing }) => {\n if (!_isLocked || _userEditing?.id === user?.id) {\n rows.set(id, true)\n }\n })\n } else if (\n selectAll === SelectAllStatus.AllAvailable ||\n selectAll === SelectAllStatus.AllInPage\n ) {\n setSelectAll(SelectAllStatus.None)\n } else {\n docs.forEach(({ id, _isLocked, _userEditing }) => {\n if (!_isLocked || _userEditing?.id === user?.id) {\n rows.set(id, selectAll !== SelectAllStatus.Some)\n }\n })\n }\n\n setSelected(rows)\n },\n [docs, selectAll, user?.id],\n )\n\n const setSelection = useCallback(\n (id) => {\n const doc = docs.find((doc) => doc.id === id)\n\n if (doc?._isLocked && user?.id !== doc?._userEditing.id) {\n return // Prevent selection if the document is locked\n }\n\n const existingValue = selected.get(id)\n const isSelected = typeof existingValue === 'boolean' ? !existingValue : true\n\n const newMap = new Map(selected.set(id, isSelected))\n\n // If previously selected all and now deselecting, adjust status\n if (selectAll === SelectAllStatus.AllAvailable && !isSelected) {\n setSelectAll(SelectAllStatus.Some)\n }\n\n setSelected(newMap)\n },\n [selected, docs, selectAll, user?.id],\n )\n\n const getQueryParams = useCallback(\n (additionalWhereParams?: Where): string => {\n let where: Where\n\n if (selectAll === SelectAllStatus.AllAvailable) {\n const params = parseSearchParams(searchParams)?.where as Where\n\n where = params || {\n id: { not_equals: '' },\n }\n } else {\n const ids = []\n\n for (const [key, value] of selected) {\n if (value) {\n ids.push(key)\n }\n }\n\n where = {\n id: {\n in: ids,\n },\n }\n }\n\n if (additionalWhereParams) {\n where = {\n and: [{ ...additionalWhereParams }, where],\n }\n }\n\n return qs.stringify(\n {\n locale,\n where,\n },\n { addQueryPrefix: true },\n )\n },\n [selectAll, selected, locale, searchParams],\n )\n\n useEffect(() => {\n if (selectAll === SelectAllStatus.AllAvailable) {\n return\n }\n let some = false\n let all = true\n\n if (!selected.size) {\n all = false\n some = false\n } else {\n for (const [_, value] of selected) {\n all = all && value\n some = some || value\n }\n }\n\n if (all && selected.size === docs.length) {\n setSelectAll(SelectAllStatus.AllInPage)\n } else if (some) {\n setSelectAll(SelectAllStatus.Some)\n } else {\n setSelectAll(SelectAllStatus.None)\n }\n }, [selectAll, selected, totalDocs, docs])\n\n useEffect(() => {\n let newCount = 0\n\n if (selectAll === SelectAllStatus.AllAvailable) {\n newCount = totalDocs\n } else {\n for (const [_, value] of selected) {\n if (value) {\n newCount++\n }\n }\n }\n\n setCount(newCount)\n }, [selectAll, selected, totalDocs])\n\n contextRef.current = {\n count,\n getQueryParams,\n selectAll,\n selected,\n setSelection,\n toggleAll,\n totalDocs,\n }\n\n return <Context.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const useSelection = (): SelectionContext => useContext(Context)\n"],"mappings":"AAAA;;;AAGA,SAASA,eAAe,QAAQ;AAChC,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAE3F,SAASC,iBAAiB,QAAQ;AAClC,SAASC,SAAS,QAAQ;AAE1B,OAAO,IAAAC,eAAK,0BAAAA,eAAA;;;;;SAAAA,eAAA;;AAmBZ,MAAMC,OAAA,gBAAUT,aAAA,CAAc,CAAC;AAU/B,OAAO,MAAMU,iBAAA,GAAqCA,CAAC;EAAEC,QAAQ;EAAEC,IAAA,GAAO,EAAE;EAAEC,SAAS;EAAEC;AAAI,CAAE;EACzF,MAAMC,UAAA,GAAaX,MAAA,CAAO,CAAC;EAE3B,MAAM;IAAEY,IAAA,EAAMC;EAAM,CAAE,GAAGV,SAAA;EAEzB,MAAM,CAACW,QAAA,EAAUC,WAAA,CAAY,GAAGd,QAAA,CAAuC;IACrE,MAAMe,IAAA,GAAO,IAAIC,GAAA;IACjBT,IAAA,CAAKU,OAAO,CAAC,CAAC;MAAEC;IAAE,CAAE;MAClBH,IAAA,CAAKI,GAAG,CAACD,EAAA,EAAI;IACf;IACA,OAAOH,IAAA;EACT;EAEA,MAAM,CAACK,SAAA,EAAWC,YAAA,CAAa,GAAGrB,QAAA;EAClC,MAAM,CAACsB,KAAA,EAAOC,QAAA,CAAS,GAAGvB,QAAA,CAAS;EACnC,MAAMwB,YAAA,GAAehC,eAAA;EAErB,MAAMiC,SAAA,GAAY7B,WAAA,CAChB,CAA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AAA,EAAGT,OAAA,CAAM,IAAI9B,QAAA,EAAU;QACjCqC,GAAA,GAAMA,GAAA,IAAOP,OAAA;QACbM,IAAA,GAAOA,IAAA,IAAQN,OAAA;MACjB;IACF;IAEA,IAAIO,GAAA,IAAOrC,QAAA,CAASsC,IAAI,KAAK5C,IAAA,CAAK8C,MAAM,EAAE;MACxChC,YAAA;IACF,OAAO,IAAI4B,IAAA,EAAM;MACf5B,YAAA;IACF,OAAO;MACLA,YAAA;IACF;EACF,GAAG,CAACD,SAAA,EAAWP,QAAA,EAAUL,SAAA,EAAWD,IAAA,CAAK;EAEzCT,SAAA,CAAU;IACR,IAAIwD,QAAA,GAAW;IAEf,IAAIlC,SAAA,qBAA4C;MAC9CkC,QAAA,GAAW9C,SAAA;IACb,OAAO;MACL,KAAK,MAAM,CAAC4C,GAAA,EAAGT,OAAA,CAAM,IAAI9B,QAAA,EAAU;QACjC,IAAI8B,OAAA,EAAO;UACTW,QAAA;QACF;MACF;IACF;IAEA/B,QAAA,CAAS+B,QAAA;EACX,GAAG,CAAClC,SAAA,EAAWP,QAAA,EAAUL,SAAA,CAAU;EAEnCE,UAAA,CAAW6C,OAAO,GAAG;IACnBjC,KAAA;IACAc,cAAA;IACAhB,SAAA;IACAP,QAAA;IACAgB,YAAA;IACAJ,SAAA;IACAjB;EACF;EAEA,oBAAOgD,IAAA,CAACpD,OAAA,CAAQqD,QAAQ;IAACd,KAAA,EAAOjC,UAAA,CAAW6C,OAAO;cAAGjD;;AACvD;AAEA,OAAO,MAAMoD,YAAA,GAAeA,CAAA;EAAA,OAAwB7D,UAAA,CAAAO,OAAW;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useSearchParams","qs","React","createContext","use","useCallback","useEffect","useRef","useState","parseSearchParams","useLocale","SelectAllStatus","Context","SelectionProvider","children","docs","totalDocs","user","contextRef","code","locale","selected","setSelected","rows","Map","forEach","id","set","selectAll","setSelectAll","count","setCount","searchParams","toggleAll","allAvailable","_isLocked","_userEditing","setSelection","doc","find","existingValue","get","isSelected","newMap","getQueryParams","additionalWhereParams","where","params","not_equals","ids","key","value","push","in","and","stringify","addQueryPrefix","some","all","size","_","length","newCount","current","_jsx","useSelection"],"sources":["../../../src/providers/Selection/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientUser, Where } from 'payload'\n\nimport { useSearchParams } from 'next/navigation.js'\nimport * as qs from 'qs-esm'\nimport React, { createContext, use, useCallback, useEffect, useRef, useState } from 'react'\n\nimport { parseSearchParams } from '../../utilities/parseSearchParams.js'\nimport { useLocale } from '../Locale/index.js'\n\nexport enum SelectAllStatus {\n AllAvailable = 'allAvailable',\n AllInPage = 'allInPage',\n None = 'none',\n Some = 'some',\n}\n\ntype SelectionContext = {\n count: number\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n getQueryParams: (additionalParams?: Where) => string\n selectAll: SelectAllStatus\n selected: Map<number | string, boolean>\n setSelection: (id: number | string) => void\n toggleAll: (allAvailable?: boolean) => void\n totalDocs: number\n}\n\nconst Context = createContext({} as SelectionContext)\n\ntype Props = {\n readonly children: React.ReactNode\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly docs: any[]\n readonly totalDocs: number\n user: ClientUser\n}\n\nexport const SelectionProvider: React.FC<Props> = ({ children, docs = [], totalDocs, user }) => {\n const contextRef = useRef({} as SelectionContext)\n\n const { code: locale } = useLocale()\n\n const [selected, setSelected] = useState<SelectionContext['selected']>(() => {\n const rows = new Map()\n docs.forEach(({ id }) => {\n rows.set(id, false)\n })\n return rows\n })\n\n const [selectAll, setSelectAll] = useState<SelectAllStatus>(SelectAllStatus.None)\n const [count, setCount] = useState(0)\n const searchParams = useSearchParams()\n\n const toggleAll = useCallback(\n (allAvailable = false) => {\n const rows = new Map()\n if (allAvailable) {\n setSelectAll(SelectAllStatus.AllAvailable)\n docs.forEach(({ id, _isLocked, _userEditing }) => {\n if (!_isLocked || _userEditing?.id === user?.id) {\n rows.set(id, true)\n }\n })\n } else if (\n selectAll === SelectAllStatus.AllAvailable ||\n selectAll === SelectAllStatus.AllInPage\n ) {\n setSelectAll(SelectAllStatus.None)\n } else {\n docs.forEach(({ id, _isLocked, _userEditing }) => {\n if (!_isLocked || _userEditing?.id === user?.id) {\n rows.set(id, selectAll !== SelectAllStatus.Some)\n }\n })\n }\n\n setSelected(rows)\n },\n [docs, selectAll, user?.id],\n )\n\n const setSelection = useCallback(\n (id) => {\n const doc = docs.find((doc) => doc.id === id)\n\n if (doc?._isLocked && user?.id !== doc?._userEditing.id) {\n return // Prevent selection if the document is locked\n }\n\n const existingValue = selected.get(id)\n const isSelected = typeof existingValue === 'boolean' ? !existingValue : true\n\n const newMap = new Map(selected.set(id, isSelected))\n\n // If previously selected all and now deselecting, adjust status\n if (selectAll === SelectAllStatus.AllAvailable && !isSelected) {\n setSelectAll(SelectAllStatus.Some)\n }\n\n setSelected(newMap)\n },\n [selected, docs, selectAll, user?.id],\n )\n\n const getQueryParams = useCallback(\n (additionalWhereParams?: Where): string => {\n let where: Where\n\n if (selectAll === SelectAllStatus.AllAvailable) {\n const params = parseSearchParams(searchParams)?.where as Where\n\n where = params || {\n id: { not_equals: '' },\n }\n } else {\n const ids = []\n\n for (const [key, value] of selected) {\n if (value) {\n ids.push(key)\n }\n }\n\n where = {\n id: {\n in: ids,\n },\n }\n }\n\n if (additionalWhereParams) {\n where = {\n and: [{ ...additionalWhereParams }, where],\n }\n }\n\n return qs.stringify(\n {\n locale,\n where,\n },\n { addQueryPrefix: true },\n )\n },\n [selectAll, selected, locale, searchParams],\n )\n\n useEffect(() => {\n if (selectAll === SelectAllStatus.AllAvailable) {\n return\n }\n let some = false\n let all = true\n\n if (!selected.size) {\n all = false\n some = false\n } else {\n for (const [_, value] of selected) {\n all = all && value\n some = some || value\n }\n }\n\n if (all && selected.size === docs.length) {\n setSelectAll(SelectAllStatus.AllInPage)\n } else if (some) {\n setSelectAll(SelectAllStatus.Some)\n } else {\n setSelectAll(SelectAllStatus.None)\n }\n }, [selectAll, selected, totalDocs, docs])\n\n useEffect(() => {\n let newCount = 0\n\n if (selectAll === SelectAllStatus.AllAvailable) {\n newCount = totalDocs\n } else {\n for (const [_, value] of selected) {\n if (value) {\n newCount++\n }\n }\n }\n\n setCount(newCount)\n }, [selectAll, selected, totalDocs])\n\n contextRef.current = {\n count,\n getQueryParams,\n selectAll,\n selected,\n setSelection,\n toggleAll,\n totalDocs,\n }\n\n return <Context value={contextRef.current}>{children}</Context>\n}\n\nexport const useSelection = (): SelectionContext => use(Context)\n"],"mappings":"AAAA;;;AAGA,SAASA,eAAe,QAAQ;AAChC,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEpF,SAASC,iBAAiB,QAAQ;AAClC,SAASC,SAAS,QAAQ;AAE1B,OAAO,IAAAC,eAAK,0BAAAA,eAAA;;;;;SAAAA,eAAA;;AAmBZ,MAAMC,OAAA,gBAAUT,aAAA,CAAc,CAAC;AAU/B,OAAO,MAAMU,iBAAA,GAAqCA,CAAC;EAAEC,QAAQ;EAAEC,IAAA,GAAO,EAAE;EAAEC,SAAS;EAAEC;AAAI,CAAE;EACzF,MAAMC,UAAA,GAAaX,MAAA,CAAO,CAAC;EAE3B,MAAM;IAAEY,IAAA,EAAMC;EAAM,CAAE,GAAGV,SAAA;EAEzB,MAAM,CAACW,QAAA,EAAUC,WAAA,CAAY,GAAGd,QAAA,CAAuC;IACrE,MAAMe,IAAA,GAAO,IAAIC,GAAA;IACjBT,IAAA,CAAKU,OAAO,CAAC,CAAC;MAAEC;IAAE,CAAE;MAClBH,IAAA,CAAKI,GAAG,CAACD,EAAA,EAAI;IACf;IACA,OAAOH,IAAA;EACT;EAEA,MAAM,CAACK,SAAA,EAAWC,YAAA,CAAa,GAAGrB,QAAA;EAClC,MAAM,CAACsB,KAAA,EAAOC,QAAA,CAAS,GAAGvB,QAAA,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C,IAAI,EAAE;MAClBD,GAAA,GAAM;MACND,IAAA,GAAO;IACT,OAAO;MACL,KAAK,MAAM,CAACG,CAAA,EAAGT,OAAA,CAAM,IAAI9B,QAAA,EAAU;QACjCqC,GAAA,GAAMA,GAAA,IAAOP,OAAA;QACbM,IAAA,GAAOA,IAAA,IAAQN,OAAA;MACjB;IACF;IAEA,IAAIO,GAAA,IAAOrC,QAAA,CAASsC,IAAI,KAAK5C,IAAA,CAAK8C,MAAM,EAAE;MACxChC,YAAA;IACF,OAAO,IAAI4B,IAAA,EAAM;MACf5B,YAAA;IACF,OAAO;MACLA,YAAA;IACF;EACF,GAAG,CAACD,SAAA,EAAWP,QAAA,EAAUL,SAAA,EAAWD,IAAA,CAAK;EAEzCT,SAAA,CAAU;IACR,IAAIwD,QAAA,GAAW;IAEf,IAAIlC,SAAA,qBAA4C;MAC9CkC,QAAA,GAAW9C,SAAA;IACb,OAAO;MACL,KAAK,MAAM,CAAC4C,GAAA,EAAGT,OAAA,CAAM,IAAI9B,QAAA,EAAU;QACjC,IAAI8B,OAAA,EAAO;UACTW,QAAA;QACF;MACF;IACF;IAEA/B,QAAA,CAAS+B,QAAA;EACX,GAAG,CAAClC,SAAA,EAAWP,QAAA,EAAUL,SAAA,CAAU;EAEnCE,UAAA,CAAW6C,OAAO,GAAG;IACnBjC,KAAA;IACAc,cAAA;IACAhB,SAAA;IACAP,QAAA;IACAgB,YAAA;IACAJ,SAAA;IACAjB;EACF;EAEA,oBAAOgD,IAAA,CAACpD,OAAA;IAAQuC,KAAA,EAAOjC,UAAA,CAAW6C,OAAO;cAAGjD;;AAC9C;AAEA,OAAO,MAAMmD,YAAA,GAAeA,CAAA,KAAwB7D,GAAA,CAAIQ,OAAA","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import React, { createContext, useCallback } from 'react';
|
|
3
3
|
export const ServerFunctionsContext = /*#__PURE__*/createContext(undefined);
|
|
4
4
|
export const useServerFunctions = () => {
|
|
5
|
-
const context = React.
|
|
5
|
+
const context = React.use(ServerFunctionsContext);
|
|
6
6
|
if (context === undefined) {
|
|
7
7
|
throw new Error('useServerFunctions must be used within a ServerFunctionsProvider');
|
|
8
8
|
}
|
|
@@ -139,7 +139,7 @@ export const ServerFunctionsProvider = ({
|
|
|
139
139
|
;
|
|
140
140
|
}
|
|
141
141
|
}, [serverFunction]);
|
|
142
|
-
return /*#__PURE__*/_jsx(ServerFunctionsContext
|
|
142
|
+
return /*#__PURE__*/_jsx(ServerFunctionsContext, {
|
|
143
143
|
value: {
|
|
144
144
|
copyDataFromLocale,
|
|
145
145
|
getDocumentSlots,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","createContext","useCallback","ServerFunctionsContext","undefined","useServerFunctions","context","useContext","Error","ServerFunctionsProvider","children","serverFunction","getDocumentSlots","args","name","schedulePublish","signal","remoteSignal","rest","aborted","result","_err","console","error","type","doc","value","relationTo","getFormState","fallbackLocale","state","getTableState","renderDocument","copyDataFromLocale","_jsx","Provider"],"sources":["../../../src/providers/ServerFunctions/index.tsx"],"sourcesContent":["import type {\n BuildFormStateArgs,\n BuildTableStateArgs,\n Data,\n DocumentSlots,\n ErrorResult,\n Locale,\n ServerFunctionClient,\n} from 'payload'\n\nimport React, { createContext, useCallback } from 'react'\n\nimport type { buildFormStateHandler } from '../../utilities/buildFormState.js'\nimport type { buildTableStateHandler } from '../../utilities/buildTableState.js'\nimport type { CopyDataFromLocaleArgs } from '../../utilities/copyDataFromLocale.js'\nimport type {\n schedulePublishHandler,\n SchedulePublishHandlerArgs,\n} from '../../utilities/schedulePublishHandler.js'\n\ntype GetFormStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildFormStateHandler>\n\ntype SchedulePublishClient = (\n args: {\n signal?: AbortSignal\n } & Omit<SchedulePublishHandlerArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof schedulePublishHandler>\n\ntype GetTableStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildTableStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildTableStateHandler>\n\ntype RenderDocument = (args: {\n collectionSlug: string\n disableActions?: boolean\n docID?: number | string\n drawerSlug?: string\n initialData?: Data\n locale?: Locale\n overrideEntityVisibility?: boolean\n redirectAfterDelete?: boolean\n redirectAfterDuplicate?: boolean\n signal?: AbortSignal\n}) => Promise<\n { data: Data; Document: React.ReactNode } | ({ data: never; Document: never } & ErrorResult)\n>\n\ntype CopyDataFromLocaleClient = (\n args: {\n signal?: AbortSignal\n } & Omit<CopyDataFromLocaleArgs, 'req'>,\n) => Promise<{ data: Data }>\n\ntype GetDocumentSlots = (args: {\n collectionSlug: string\n signal?: AbortSignal\n}) => Promise<DocumentSlots>\n\ntype ServerFunctionsContextType = {\n copyDataFromLocale: CopyDataFromLocaleClient\n getDocumentSlots: GetDocumentSlots\n getFormState: GetFormStateClient\n getTableState: GetTableStateClient\n renderDocument: RenderDocument\n schedulePublish: SchedulePublishClient\n serverFunction: ServerFunctionClient\n}\n\nexport const ServerFunctionsContext = createContext<ServerFunctionsContextType | undefined>(\n undefined,\n)\n\nexport const useServerFunctions = () => {\n const context = React.useContext(ServerFunctionsContext)\n if (context === undefined) {\n throw new Error('useServerFunctions must be used within a ServerFunctionsProvider')\n }\n return context\n}\n\nexport const ServerFunctionsProvider: React.FC<{\n children: React.ReactNode\n serverFunction: ServerFunctionClient\n}> = ({ children, serverFunction }) => {\n if (!serverFunction) {\n throw new Error('ServerFunctionsProvider requires a serverFunction prop')\n }\n\n const getDocumentSlots = useCallback<GetDocumentSlots>(\n async (args) =>\n await serverFunction({\n name: 'render-document-slots',\n args,\n }),\n [serverFunction],\n )\n\n const schedulePublish = useCallback<SchedulePublishClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'schedule-publish',\n args: { ...rest },\n })) as Awaited<ReturnType<typeof schedulePublishHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n let error = `Error scheduling ${rest.type}`\n\n if (rest.doc) {\n error += ` for document with ID ${rest.doc.value} in collection ${rest.doc.relationTo}`\n }\n\n return { error: '' }\n },\n [serverFunction],\n )\n\n const getFormState = useCallback<GetFormStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'form-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildFormStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n return { state: null }\n },\n [serverFunction],\n )\n\n const getTableState = useCallback<GetTableStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'table-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildTableStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n // return { state: args.formState }\n },\n [serverFunction],\n )\n\n const renderDocument = useCallback<RenderDocument>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'render-document',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof renderDocument>> // TODO: infer this type when `strictNullChecks` is enabled\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const copyDataFromLocale = useCallback<CopyDataFromLocaleClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'copy-data-from-locale',\n args: rest,\n })) as { data: Data }\n\n if (!remoteSignal?.aborted) {\n return result\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n return (\n <ServerFunctionsContext.Provider\n value={{\n copyDataFromLocale,\n getDocumentSlots,\n getFormState,\n getTableState,\n renderDocument,\n schedulePublish,\n serverFunction,\n }}\n >\n {children}\n </ServerFunctionsContext.Provider>\n )\n}\n"],"mappings":";AAUA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,QAAQ;AAgElD,OAAO,MAAMC,sBAAA,gBAAyBF,aAAA,CACpCG,SAAA;AAGF,OAAO,MAAMC,kBAAA,GAAqBA,CAAA;EAChC,MAAMC,OAAA,GAAUN,KAAA,CAAMO,UAAU,CAACJ,sBAAA;EACjC,IAAIG,OAAA,KAAYF,SAAA,EAAW;IACzB,MAAM,IAAII,KAAA,CAAM;EAClB;EACA,OAAOF,OAAA;AACT;AAEA,OAAO,MAAMG,uBAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC;AAAc,CAAE;EAChC,IAAI,CAACA,cAAA,EAAgB;IACnB,MAAM,IAAIH,KAAA,CAAM;EAClB;EAEA,MAAMI,gBAAA,GAAmBV,WAAA,CACvB,MAAOW,IAAA,IACL,MAAMF,cAAA,CAAe;IACnBG,IAAA,EAAM;IACND;EACF,IACF,CAACF,cAAA,CAAe;EAGlB,MAAMI,eAAA,GAAkBb,WAAA,CACtB,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA;IAE1C,IAAI;MACF,IAAI,CAACI,YAAA,EAAcE,OAAA,EAAS;QAC1B,MAAMC,MAAA,GAAU,MAAMT,cAAA,CAAe;UACnCG,IAAA,EAAM;UACND,IAAA,EAAM;YAAE,GAAGK;UAAK;QAClB;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AO;MACLO,kBAAA;MACArB,gBAAA;MACAgB,YAAA;MACAG,aAAA;MACAC,cAAA;MACAjB,eAAA;MACAJ;IACF;cAECD;;AAGP","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","createContext","useCallback","ServerFunctionsContext","undefined","useServerFunctions","context","use","Error","ServerFunctionsProvider","children","serverFunction","getDocumentSlots","args","name","schedulePublish","signal","remoteSignal","rest","aborted","result","_err","console","error","type","doc","value","relationTo","getFormState","fallbackLocale","state","getTableState","renderDocument","copyDataFromLocale","_jsx"],"sources":["../../../src/providers/ServerFunctions/index.tsx"],"sourcesContent":["import type {\n BuildFormStateArgs,\n BuildTableStateArgs,\n Data,\n DocumentSlots,\n ErrorResult,\n Locale,\n ServerFunctionClient,\n} from 'payload'\n\nimport React, { createContext, useCallback } from 'react'\n\nimport type { buildFormStateHandler } from '../../utilities/buildFormState.js'\nimport type { buildTableStateHandler } from '../../utilities/buildTableState.js'\nimport type { CopyDataFromLocaleArgs } from '../../utilities/copyDataFromLocale.js'\nimport type {\n schedulePublishHandler,\n SchedulePublishHandlerArgs,\n} from '../../utilities/schedulePublishHandler.js'\n\ntype GetFormStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildFormStateHandler>\n\ntype SchedulePublishClient = (\n args: {\n signal?: AbortSignal\n } & Omit<SchedulePublishHandlerArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof schedulePublishHandler>\n\ntype GetTableStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildTableStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildTableStateHandler>\n\ntype RenderDocument = (args: {\n collectionSlug: string\n disableActions?: boolean\n docID?: number | string\n drawerSlug?: string\n initialData?: Data\n locale?: Locale\n overrideEntityVisibility?: boolean\n redirectAfterDelete?: boolean\n redirectAfterDuplicate?: boolean\n signal?: AbortSignal\n}) => Promise<\n { data: Data; Document: React.ReactNode } | ({ data: never; Document: never } & ErrorResult)\n>\n\ntype CopyDataFromLocaleClient = (\n args: {\n signal?: AbortSignal\n } & Omit<CopyDataFromLocaleArgs, 'req'>,\n) => Promise<{ data: Data }>\n\ntype GetDocumentSlots = (args: {\n collectionSlug: string\n signal?: AbortSignal\n}) => Promise<DocumentSlots>\n\ntype ServerFunctionsContextType = {\n copyDataFromLocale: CopyDataFromLocaleClient\n getDocumentSlots: GetDocumentSlots\n getFormState: GetFormStateClient\n getTableState: GetTableStateClient\n renderDocument: RenderDocument\n schedulePublish: SchedulePublishClient\n serverFunction: ServerFunctionClient\n}\n\nexport const ServerFunctionsContext = createContext<ServerFunctionsContextType | undefined>(\n undefined,\n)\n\nexport const useServerFunctions = () => {\n const context = React.use(ServerFunctionsContext)\n if (context === undefined) {\n throw new Error('useServerFunctions must be used within a ServerFunctionsProvider')\n }\n return context\n}\n\nexport const ServerFunctionsProvider: React.FC<{\n children: React.ReactNode\n serverFunction: ServerFunctionClient\n}> = ({ children, serverFunction }) => {\n if (!serverFunction) {\n throw new Error('ServerFunctionsProvider requires a serverFunction prop')\n }\n\n const getDocumentSlots = useCallback<GetDocumentSlots>(\n async (args) =>\n await serverFunction({\n name: 'render-document-slots',\n args,\n }),\n [serverFunction],\n )\n\n const schedulePublish = useCallback<SchedulePublishClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'schedule-publish',\n args: { ...rest },\n })) as Awaited<ReturnType<typeof schedulePublishHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n let error = `Error scheduling ${rest.type}`\n\n if (rest.doc) {\n error += ` for document with ID ${rest.doc.value} in collection ${rest.doc.relationTo}`\n }\n\n return { error: '' }\n },\n [serverFunction],\n )\n\n const getFormState = useCallback<GetFormStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'form-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildFormStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n return { state: null }\n },\n [serverFunction],\n )\n\n const getTableState = useCallback<GetTableStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'table-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildTableStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n // return { state: args.formState }\n },\n [serverFunction],\n )\n\n const renderDocument = useCallback<RenderDocument>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'render-document',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof renderDocument>> // TODO: infer this type when `strictNullChecks` is enabled\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const copyDataFromLocale = useCallback<CopyDataFromLocaleClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'copy-data-from-locale',\n args: rest,\n })) as { data: Data }\n\n if (!remoteSignal?.aborted) {\n return result\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n return (\n <ServerFunctionsContext\n value={{\n copyDataFromLocale,\n getDocumentSlots,\n getFormState,\n getTableState,\n renderDocument,\n schedulePublish,\n serverFunction,\n }}\n >\n {children}\n </ServerFunctionsContext>\n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AA,CACrB,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA,IAAQ,CAAC;IAEnD,IAAI;MACF,MAAMO,MAAA,GAAU,MAAMT,cAAA,CAAe;QACnCG,IAAA,EAAM;QACND,IAAA,EAAM;UAAEgB,cAAA,EAAgB;UAAO,GAAGX;QAAK;MACzC;MAAkD;MAElD,OAAOE,MAAA;IACT,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,EAAM;MAAA;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,MAAMsB,kBAAA,GAAqB/B,WAAA,CACzB,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA,IAAQ,CAAC;IAEnD,IAAI;MACF,MAAMO,MAAA,GAAU,MAAMT,cAAA,CAAe;QACnCG,IAAA,EAAM;QACND,IAAA,EAAMK;MACR;MAEA,IAAI,CAACD,YAAA,EAAcE,OAAA,EAAS;QAC1B,OAAOC,MAAA;MACT;IACF,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,EAAM;MAAA;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,oBACEuB,IAAA,CAAC/B,sBAAA;IACCuB,KAAA,EAAO;MACLO,kBAAA;MACArB,gBAAA;MACAgB,YAAA;MACAG,aAAA;MACAC,cAAA;MACAjB,eAAA;MACAJ;IACF;cAECD;;AAGP","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Theme/index.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Theme/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA+D,MAAM,OAAO,CAAA;AAInF,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;AAEpC,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AA4CD,eAAO,MAAM,YAAY,UAAU,CAAA;AAEnC,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CA2CA,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,YAA4B,CAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
import React, { createContext,
|
|
5
|
+
import React, { createContext, use, useCallback, useEffect, useState } from 'react';
|
|
6
6
|
import { useConfig } from '../Config/index.js';
|
|
7
7
|
const initialContext = {
|
|
8
8
|
autoMode: true,
|
|
@@ -94,7 +94,7 @@ export const ThemeProvider = t0 => {
|
|
|
94
94
|
const setTheme = t3;
|
|
95
95
|
let t4;
|
|
96
96
|
if ($[6] !== autoMode || $[7] !== children || $[8] !== setTheme || $[9] !== theme) {
|
|
97
|
-
t4 = _jsx(Context
|
|
97
|
+
t4 = _jsx(Context, {
|
|
98
98
|
value: {
|
|
99
99
|
autoMode,
|
|
100
100
|
setTheme,
|
|
@@ -112,7 +112,5 @@ export const ThemeProvider = t0 => {
|
|
|
112
112
|
}
|
|
113
113
|
return t4;
|
|
114
114
|
};
|
|
115
|
-
export const useTheme = () =>
|
|
116
|
-
return useContext(Context);
|
|
117
|
-
};
|
|
115
|
+
export const useTheme = () => use(Context);
|
|
118
116
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","createContext","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useState","useConfig","initialContext","autoMode","setTheme","theme","Context","setCookie","cname","cvalue","exdays","d","Date","setTime","getTime","expires","toUTCString","document","cookie","getTheme","cookieKey","themeFromCookies","window","split","find","row","startsWith","matchMedia","matches","documentElement","setAttribute","defaultTheme","ThemeProvider","t0","$","children","initialTheme","config","preselectedTheme","admin","cookiePrefix","setThemeState","setAutoMode","t1","t2","theme_0","t3","themeToSet","themeFromOS","t4","_jsx","value","useTheme"],"sources":["../../../src/providers/Theme/index.tsx"],"sourcesContent":["'use client'\nimport React, { createContext, use, useCallback, useEffect, useState } from 'react'\n\nimport { useConfig } from '../Config/index.js'\n\nexport type Theme = 'dark' | 'light'\n\nexport type ThemeContext = {\n autoMode: boolean\n setTheme: (theme: Theme) => void\n theme: Theme\n}\n\nconst initialContext: ThemeContext = {\n autoMode: true,\n setTheme: () => null,\n theme: 'light',\n}\n\nconst Context = createContext(initialContext)\n\nfunction setCookie(cname, cvalue, exdays) {\n const d = new Date()\n d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)\n const expires = 'expires=' + d.toUTCString()\n document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'\n}\n\nconst getTheme = (\n cookieKey,\n): {\n theme: Theme\n themeFromCookies: null | string\n} => {\n let theme: Theme\n\n const themeFromCookies = window.document.cookie\n .split('; ')\n .find((row) => row.startsWith(`${cookieKey}=`))\n ?.split('=')[1]\n\n if (themeFromCookies === 'light' || themeFromCookies === 'dark') {\n theme = themeFromCookies\n } else {\n theme =\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light'\n }\n\n document.documentElement.setAttribute('data-theme', theme)\n\n return { theme, themeFromCookies }\n}\n\nexport const defaultTheme = 'light'\n\nexport const ThemeProvider: React.FC<{\n children?: React.ReactNode\n theme?: Theme\n}> = ({ children, theme: initialTheme }) => {\n const { config } = useConfig()\n\n const preselectedTheme = config.admin.theme\n const cookieKey = `${config.cookiePrefix || 'payload'}-theme`\n\n const [theme, setThemeState] = useState<Theme>(initialTheme || defaultTheme)\n\n const [autoMode, setAutoMode] = useState<boolean>()\n\n useEffect(() => {\n if (preselectedTheme !== 'all') {\n return\n }\n\n const { theme, themeFromCookies } = getTheme(cookieKey)\n setThemeState(theme)\n setAutoMode(!themeFromCookies)\n }, [preselectedTheme, cookieKey])\n\n const setTheme = useCallback(\n (themeToSet: 'auto' | Theme) => {\n if (themeToSet === 'light' || themeToSet === 'dark') {\n setThemeState(themeToSet)\n setAutoMode(false)\n setCookie(cookieKey, themeToSet, 365)\n document.documentElement.setAttribute('data-theme', themeToSet)\n } else if (themeToSet === 'auto') {\n // to delete the cookie, we set an expired date\n setCookie(cookieKey, themeToSet, -1)\n const themeFromOS =\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light'\n document.documentElement.setAttribute('data-theme', themeFromOS)\n setAutoMode(true)\n setThemeState(themeFromOS)\n }\n },\n [cookieKey],\n )\n\n return <Context value={{ autoMode, setTheme, theme }}>{children}</Context>\n}\n\nexport const useTheme = (): ThemeContext => use(Context)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAE5E,SAASC,SAAS,QAAQ;AAU1B,MAAMC,cAAA,GAA+B;EACnCC,QAAA,EAAU;EACVC,QAAA,EAAUA,CAAA,KAAM;EAChBC,KAAA,EAAO;AACT;AAEA,MAAMC,OAAA,gBAAUV,aAAA,CAAcM,cAAA;AAE9B,SAASK,UAAUC,KAAK,EAAEC,MAAM,EAAEC,MAAM;EACtC,MAAMC,CAAA,GAAI,IAAIC,IAAA;EACdD,CAAA,CAAEE,OAAO,CAACF,CAAA,CAAEG,OAAO,KAAKJ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MAAA9B,QAAA,GAAiB0C,EAmBJ;EAAA,IAAAG,EAAA;EAAA,IAAAf,CAAA,QAAA/B,QAAA,IAAA+B,CAAA,QAAAC,QAAA,IAAAD,CAAA,QAAA9B,QAAA,IAAA8B,CAAA,QAAA7B,KAAA;IAGN4C,EAAA,GAAAC,IAAA,CAAA5C,OAAA;MAAA6C,KAAA;QAAAhD,QAAA;QAAAC,QAAA;QAAAC;MAAA;MAAA8B;IAAA,C;;;;;;;;;SAAAc,E;CACT;AAEA,OAAO,MAAMG,QAAA,GAAWA,CAAA,KAAoBvD,GAAA,CAAIS,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Translation/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACV,MAAM,0BAA0B,CAAA;AAEjC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAK9C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Translation/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACV,MAAM,0BAA0B,CAAA;AAEjC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAK9C,OAAO,KAAkD,MAAM,OAAO,CAAA;AAEtE,KAAK,WAAW,CACd,uBAAuB,GAAG,EAAE,EAC5B,gCAAgC,SAAS,MAAM,GAAG,KAAK,IACrD;IACF,IAAI,EAAE,CAAC,gCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpD,UAAU,GACV,uBAAuB,SAAS,MAAM,GACpC,UAAU,CAAC,uBAAuB,EAAE,gCAAgC,C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