@payloadcms/ui 3.0.2-canary.f4f29e6 → 3.0.3-canary.5a65a90
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/DeleteMany/index.d.ts.map +1 -1
- package/dist/elements/DeleteMany/index.js +11 -3
- package/dist/elements/DeleteMany/index.js.map +1 -1
- package/dist/elements/DocumentDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/elements/DocumentDrawer/DrawerContent.js +4 -2
- package/dist/elements/DocumentDrawer/DrawerContent.js.map +1 -1
- package/dist/elements/EditMany/index.d.ts.map +1 -1
- package/dist/elements/EditMany/index.js +17 -8
- package/dist/elements/EditMany/index.js.map +1 -1
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +3 -3
- package/dist/exports/shared/index.js +1 -1
- package/dist/exports/shared/index.js.map +2 -2
- package/dist/fields/Blocks/BlockRow.d.ts.map +1 -1
- package/dist/fields/Blocks/BlockRow.js +16 -5
- package/dist/fields/Blocks/BlockRow.js.map +1 -1
- package/dist/forms/RenderFields/index.d.ts +3 -3
- package/dist/forms/RenderFields/index.d.ts.map +1 -1
- package/dist/forms/RenderFields/index.js +16 -15
- package/dist/forms/RenderFields/index.js.map +1 -1
- package/dist/forms/RenderFields/types.d.ts +1 -1
- package/dist/forms/RenderFields/types.d.ts.map +1 -1
- package/dist/forms/RenderFields/types.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts +2 -4
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +25 -9
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/index.d.ts +2 -2
- package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts +2 -4
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +2 -7
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.d.ts +1 -3
- package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
- package/dist/providers/Actions/index.d.ts.map +1 -1
- package/dist/providers/Actions/index.js +10 -6
- package/dist/providers/Actions/index.js.map +1 -1
- package/dist/providers/Preferences/index.d.ts.map +1 -1
- package/dist/providers/Preferences/index.js +3 -1
- package/dist/providers/Preferences/index.js.map +1 -1
- package/dist/providers/Selection/index.d.ts.map +1 -1
- package/dist/providers/Selection/index.js.map +1 -1
- package/dist/providers/ServerFunctions/index.d.ts +1 -1
- package/dist/providers/ServerFunctions/index.d.ts.map +1 -1
- package/dist/providers/ServerFunctions/index.js +7 -11
- package/dist/providers/ServerFunctions/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/mergeListSearchAndWhere.d.ts +1 -1
- package/dist/utilities/mergeListSearchAndWhere.d.ts.map +1 -1
- package/dist/utilities/mergeListSearchAndWhere.js +1 -1
- package/dist/utilities/mergeListSearchAndWhere.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","createContext","useContext","useState","ActionsContext","Actions","setViewActions","useActions","ActionsProvider","t0","$","children","viewActions","t1","_jsx","Provider","value"],"sources":["../../../src/providers/Actions/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { createContext, useContext, useState } from 'react'\n\ntype ActionsContextType = {\n Actions: {\n [key: string]: React.ReactNode\n }\n setViewActions: (actions: ActionsContextType['Actions']) => void\n}\n\nconst ActionsContext = createContext<ActionsContextType>({\n Actions: {},\n setViewActions: () => {},\n})\n\nexport const useActions = () => useContext(ActionsContext)\n\nexport const ActionsProvider: React.FC<{\n readonly Actions?: {\n [key: string]: React.ReactNode\n }\n readonly children: React.ReactNode\n}> = ({ Actions, children }) => {\n const [viewActions, setViewActions] = useState(Actions)\n\n return (\n <ActionsContext.Provider
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","createContext","useContext","useState","ActionsContext","Actions","setViewActions","useActions","ActionsProvider","t0","$","children","viewActions","t1","_jsx","Provider","value"],"sources":["../../../src/providers/Actions/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { createContext, useContext, useState } from 'react'\n\ntype ActionsContextType = {\n Actions: {\n [key: string]: React.ReactNode\n }\n setViewActions: (actions: ActionsContextType['Actions']) => void\n}\n\nconst ActionsContext = createContext<ActionsContextType>({\n Actions: {},\n setViewActions: () => {},\n})\n\nexport const useActions = () => useContext(ActionsContext)\n\nexport const ActionsProvider: React.FC<{\n readonly Actions?: {\n [key: string]: React.ReactNode\n }\n readonly children: React.ReactNode\n}> = ({ Actions, children }) => {\n const [viewActions, setViewActions] = useState(Actions)\n\n return (\n <ActionsContext.Provider\n value={{\n Actions: {\n ...viewActions,\n ...Actions,\n },\n setViewActions,\n }}\n >\n {children}\n </ActionsContext.Provider>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,OAAOC,KAAA,IAASC,aAAa,EAAEC,UAAU,EAAEC,QAAQ,QAAQ;AAS3D,MAAMC,cAAA,gBAAiBH,aAAA,CAAkC;EACvDI,OAAA,EAAS,CAAC;EACVC,cAAA,EAAgBA,CAAA,MAAO;AACzB;AAEA,OAAO,MAAMC,UAAA,GAAaA,CAAA;EAAA,OAAML,UAAA,CAAAE,cAAW;AAAA;AAE3C,OAAO,MAAMI,eAAA,GAKRC,EAAA;EAAA,MAAAC,CAAA,GAAAX,EAAA;EAAC;IAAAM,OAAA;IAAAM;EAAA,IAAAF,EAAqB;EACzB,OAAAG,WAAA,EAAAN,cAAA,IAAsCH,QAAA,CAASE,OAAA;EAAA,IAAAQ,EAAA;EAAA,IAAAH,CAAA,QAAAE,WAAA,IAAAF,CAAA,QAAAL,OAAA,IAAAK,CAAA,QAAAC,QAAA;IAG7CE,EAAA,GAAAC,IAAA,CAAAV,cAAA,CAAAW,QAAA;MAAAC,KAAA;QAAAX,OAAA;UAAA,GAGSO,WAAW;UAAA,GACXP;QAAO;QAAAC;MAAA;MAAAK;IAAA,C;;;;;;;;SAJhBE,E;CAYJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Preferences/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoE,MAAM,OAAO,CAAA;AAQxF,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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Preferences/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoE,MAAM,OAAO,CAAA;AAQxF,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,CAyHxE,CAAA;AAED,eAAO,MAAM,cAAc,QAAO,kBAAyC,CAAA"}
|
|
@@ -80,7 +80,9 @@ export const PreferencesProvider = ({
|
|
|
80
80
|
// handle value objects where multiple values can be set under one key
|
|
81
81
|
if (typeof value_0 === 'object' && typeof currentPreference === 'object' && typeof newValue === 'object') {
|
|
82
82
|
// merge the value with any existing preference for the key
|
|
83
|
-
|
|
83
|
+
if (currentPreference) {
|
|
84
|
+
newValue = deepMergeSimple(currentPreference, newValue);
|
|
85
|
+
}
|
|
84
86
|
if (dequal(newValue, currentPreference)) {
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["dequal","React","createContext","useCallback","useContext","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","Provider","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, useCallback, useContext, 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 newValue = deepMergeSimple(currentPreference, newValue)\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 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.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const usePreferences = (): PreferencesContext => useContext(Context)\n"],"mappings":"AAAA;;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AACrC,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAEjF,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,CAAKC,SAAS,CAAC;IAAEJ;EAAM;EAC7BK,OAAA,EAAS;IACP,mBAAmBJ,QAAA;IACnB,gBAAgB;EAClB;AACF;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;QAC9BuB,OAAA,CAAQvB,KAAA;MACV;IACF;IACAoB,KAAK,CAACD,GAAA,CAAI,GAAGE,OAAA;IACb,OAAOA,OAAA;EACT,GACA,CAACR,IAAA,CAAKZ,QAAQ,EAAEc,GAAA,EAAKN,cAAA,EAAgBO,SAAA,CAAU;EAGjD,MAAMa,aAAA,GAAgBxC,WAAA,CACpB,OAAO8B,KAAA,EAAanB,OAAA,EAAgB8B,KAAA,GAAQ,KAAK;IAC/C,IAAIA,KAAA,KAAU,OAAO;MACnBrB,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAGnB,OAAA;MAE9B,MAAMN,QAAA,CAASqC,IAAI,CACjB,GAAGf,SAAA,GAAYD,GAAA,wBAA2BI,KAAA,EAAK,EAC/CpB,cAAA,CAAeC,OAAA,EAAOa,IAAA,CAAKZ,QAAQ;MAGrC;IACF;IAEA,IAAI+B,QAAA,GAAWhC,OAAA;IACf,MAAMiC,iBAAA,GAAoB,MAAMf,aAAA,CAAcC,KAAA;IAE9C;IACA,IACE,OAAOnB,OAAA,KAAU,YACjB,OAAOiC,iBAAA,KAAsB,YAC7B,OAAOD,QAAA,KAAa,UACpB;MACA;
|
|
1
|
+
{"version":3,"file":"index.js","names":["dequal","React","createContext","useCallback","useContext","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","Provider","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, useCallback, useContext, 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 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.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const usePreferences = (): PreferencesContext => useContext(Context)\n"],"mappings":"AAAA;;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AACrC,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAEjF,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,CAAKC,SAAS,CAAC;IAAEJ;EAAM;EAC7BK,OAAA,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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,CAyK7C,CAAA;AAED,eAAO,MAAM,YAAY,QAAO,gBAAuC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["qs","React","createContext","useCallback","useContext","useEffect","useRef","useState","useLocale","useSearchParams","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 * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'\n\nimport { useLocale } from '../Locale/index.js'\nimport { useSearchParams } from '../SearchParams/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 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 let newMap = new Map()\n\n if (isSelected) {\n newMap = new Map(selected.set(id, isSelected))\n } else {\n newMap = new Map(selected.set(id, false))\n }\n\n setSelected(newMap)\n },\n [selected, docs, user?.id],\n )\n\n const getQueryParams = useCallback(\n (additionalWhereParams?: Where): string => {\n let where: Where\n if (selectAll === SelectAllStatus.AllAvailable) {\n const params = searchParams?.where as Where\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 if (additionalWhereParams) {\n where = {\n and: [{ ...additionalWhereParams }, where],\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 // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setSelectAll(SelectAllStatus.AllInPage)\n } else if (some) {\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setSelectAll(SelectAllStatus.Some)\n } else {\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\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 // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\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,YAAYA,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAE3F,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;;WAEpBC,eAAA;;;;;GAAAA,eAAA,KAAAA,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,GAAGX,SAAA;EAEzB,MAAM,CAACY,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,MAAM;IAAEwB;EAAY,CAAE,GAAGtB,eAAA;EAEzB,MAAMuB,SAAA,GAAY7B,WAAA,CAChB,CAAC8B,YAAA,GAAe,KAAK;IACnB,MAAMX,MAAA,GAAO,IAAIC,GAAA;IACjB,IAAIU,YAAA,EAAc;MAChBL,YAAA;MACAd,IAAA,CAAKU,OAAO,CAAC,CAAC;QAAEC,EAAE,EAAFA,IAAE;QAAES,SAAS;QAAE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F;IAEA,IAAIO,GAAA,IAAOrC,QAAA,CAASsC,IAAI,KAAK5C,IAAA,CAAK8C,MAAM,EAAE;MACxC;MACAhC,YAAA;IACF,OAAO,IAAI4B,IAAA,EAAM;MACf;MACA5B,YAAA;IACF,OAAO;MACL;MACAA,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;IACA/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":["qs","React","createContext","useCallback","useContext","useEffect","useRef","useState","useLocale","useSearchParams","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 * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'\n\nimport { useLocale } from '../Locale/index.js'\nimport { useSearchParams } from '../SearchParams/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 let newMap = new Map()\n\n if (isSelected) {\n newMap = new Map(selected.set(id, isSelected))\n } else {\n newMap = new Map(selected.set(id, false))\n }\n\n setSelected(newMap)\n },\n [selected, docs, 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 = 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 // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setSelectAll(SelectAllStatus.AllInPage)\n } else if (some) {\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\n setSelectAll(SelectAllStatus.Some)\n } else {\n // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\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 // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect\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,YAAYA,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAE3F,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;;WAEpBC,eAAA;;;;;GAAAA,eAAA,KAAAA,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,GAAGX,SAAA;EAEzB,MAAM,CAACY,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,MAAM;IAA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":"","sources":["../../../src/providers/ServerFunctions/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,IAAI,EACJ,aAAa,EACb,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAqC,MAAM,OAAO,CAAA;AAEzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAEhF,KAAK,kBAAkB,GAAG,CACxB,IAAI,EAAE;IACJ,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,KAAK,CAAC,KACjD,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAA;AAE7C,KAAK,mBAAmB,GAAG,CACzB,IAAI,EAAE;IACJ,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,IAAI,CAAC,mBAAmB,EAAE,cAAc,GAAG,KAAK,CAAC,KAClD,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAE9C,KAAK,cAAc,GAAG,CAAC,IAAI,EAAE;IAC3B,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,KAAK,OAAO,CAAC;IAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/ServerFunctions/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,IAAI,EACJ,aAAa,EACb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,gBAAgB,CAAA;IAClC,YAAY,EAAE,kBAAkB,CAAA;IAChC,aAAa,EAAE,mBAAmB,CAAA;IAClC,cAAc,EAAE,cAAc,CAAA;IAC9B,cAAc,EAAE,oBAAoB,CAAA;CACrC,CAAA;AAED,eAAO,MAAM,sBAAsB,2CAElC,CAAA;AAED,eAAO,MAAM,kBAAkB,kCAM9B,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,cAAc,EAAE,oBAAoB,CAAA;CACrC,CA6FA,CAAA"}
|
|
@@ -77,18 +77,14 @@ export const ServerFunctionsProvider = ({
|
|
|
77
77
|
...rest
|
|
78
78
|
} = args || {};
|
|
79
79
|
try {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...rest
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
if (!remoteSignal?.aborted) {
|
|
89
|
-
return result;
|
|
80
|
+
const result = await serverFunction({
|
|
81
|
+
name: 'render-document',
|
|
82
|
+
args: {
|
|
83
|
+
fallbackLocale: false,
|
|
84
|
+
...rest
|
|
90
85
|
}
|
|
91
|
-
}
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
92
88
|
} catch (_err) {
|
|
93
89
|
console.error(_err) // eslint-disable-line no-console
|
|
94
90
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","createContext","useCallback","ServerFunctionsContext","undefined","useServerFunctions","context","useContext","Error","ServerFunctionsProvider","children","serverFunction","getDocumentSlots","args","name","getFormState","signal","remoteSignal","rest","aborted","result","fallbackLocale","_err","console","error","state","getTableState","renderDocument","_jsx","Provider","value"],"sources":["../../../src/providers/ServerFunctions/index.tsx"],"sourcesContent":["import type {\n BuildFormStateArgs,\n BuildTableStateArgs,\n Data,\n DocumentSlots,\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'\n\ntype GetFormStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildFormStateHandler>\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 redirectAfterDelete?: boolean\n redirectAfterDuplicate?: boolean\n signal?: AbortSignal\n}) => Promise<{
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","createContext","useCallback","ServerFunctionsContext","undefined","useServerFunctions","context","useContext","Error","ServerFunctionsProvider","children","serverFunction","getDocumentSlots","args","name","getFormState","signal","remoteSignal","rest","aborted","result","fallbackLocale","_err","console","error","state","getTableState","renderDocument","_jsx","Provider","value"],"sources":["../../../src/providers/ServerFunctions/index.tsx"],"sourcesContent":["import type {\n BuildFormStateArgs,\n BuildTableStateArgs,\n Data,\n DocumentSlots,\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'\n\ntype GetFormStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildFormStateHandler>\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 redirectAfterDelete?: boolean\n redirectAfterDuplicate?: boolean\n signal?: AbortSignal\n}) => Promise<{ data: Data; Document: React.ReactNode }>\n\ntype GetDocumentSlots = (args: {\n collectionSlug: string\n signal?: AbortSignal\n}) => Promise<DocumentSlots>\n\ntype ServerFunctionsContextType = {\n getDocumentSlots: GetDocumentSlots\n getFormState: GetFormStateClient\n getTableState: GetTableStateClient\n renderDocument: RenderDocument\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 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 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 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 { data: Data; Document: React.ReactNode }\n\n return result\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 getDocumentSlots,\n getFormState,\n getTableState,\n renderDocument,\n serverFunction,\n }}\n >\n {children}\n </ServerFunctionsContext.Provider>\n )\n}\n"],"mappings":";AAQA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,QAAQ;AAyClD,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,YAAA,GAAeb,WAAA,CACnB,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA,IAAQ,CAAC;IAEnD,IAAI;MACF,IAAI,CAACI,YAAA,EAAcE,OAAA,EAAS;QAC1B,MAAMC,MAAA,GAAU,MAAMT,cAAA,CAA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