@payloadcms/ui 3.0.2-canary.f4f29e6 → 3.0.3-canary.27acdae
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/elements/IDLabel/index.d.ts.map +1 -1
- package/dist/elements/IDLabel/index.js +2 -1
- package/dist/elements/IDLabel/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js +1 -1
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/shared/index.d.ts +1 -0
- package/dist/exports/shared/index.d.ts.map +1 -1
- package/dist/exports/shared/index.js +2 -2
- package/dist/exports/shared/index.js.map +4 -4
- 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/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +1 -0
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
- package/dist/forms/Form/fieldReducer.js +1 -0
- package/dist/forms/Form/fieldReducer.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/dist/utilities/sanitizeID.d.ts +2 -0
- package/dist/utilities/sanitizeID.d.ts.map +1 -0
- package/dist/utilities/sanitizeID.js +10 -0
- package/dist/utilities/sanitizeID.js.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["calculateDefaultValues","iterateFields","fieldSchemasToFormState","args","id","collectionSlug","data","fields","fieldSchemaMap","operation","permissions","preferences","previousFormState","renderAllFields","renderFieldFn","req","schemaPath","length","state","dataWithDefaultValues","locale","siblingData","user","addErrorPathToParent","fullData","parentIndexPath","parentPassesCondition","parentPath","parentSchemaPath"],"sources":["../../../src/forms/fieldSchemasToFormState/index.tsx"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FormState,\n FormStateWithoutComponents,\n PayloadRequest,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["calculateDefaultValues","iterateFields","fieldSchemasToFormState","args","id","collectionSlug","data","fields","fieldSchemaMap","operation","permissions","preferences","previousFormState","renderAllFields","renderFieldFn","req","schemaPath","length","state","dataWithDefaultValues","locale","siblingData","user","addErrorPathToParent","fullData","parentIndexPath","parentPassesCondition","parentPath","parentSchemaPath"],"sources":["../../../src/forms/fieldSchemasToFormState/index.tsx"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FormState,\n FormStateWithoutComponents,\n PayloadRequest,\n SanitizedFieldsPermissions,\n} from 'payload'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { calculateDefaultValues } from './calculateDefaultValues/index.js'\nimport { iterateFields } from './iterateFields.js'\n\ntype Args = {\n collectionSlug?: string\n data?: Data\n fields: Field[] | undefined\n /**\n * The field schema map is required for field rendering.\n * If fields should not be rendered (=> `renderFieldFn` is not provided),\n * then the field schema map is not required.\n */\n fieldSchemaMap: FieldSchemaMap | undefined\n id?: number | string\n operation?: 'create' | 'update'\n permissions: SanitizedFieldsPermissions\n preferences: DocumentPreferences\n /**\n * Optionally accept the previous form state,\n * to be able to determine if custom fields need to be re-rendered.\n */\n previousFormState?: FormState\n /**\n * If renderAllFields is true, then no matter what is in previous form state,\n * all custom fields will be re-rendered.\n */\n renderAllFields: boolean\n renderFieldFn?: RenderFieldMethod\n req: PayloadRequest\n schemaPath: string\n}\n\nexport const fieldSchemasToFormState = async (args: Args): Promise<FormState> => {\n const {\n id,\n collectionSlug,\n data = {},\n fields,\n fieldSchemaMap,\n operation,\n permissions,\n preferences,\n previousFormState,\n renderAllFields,\n renderFieldFn,\n req,\n schemaPath,\n } = args\n\n if (fields && fields.length) {\n const state: FormStateWithoutComponents = {}\n\n const dataWithDefaultValues = { ...data }\n\n await calculateDefaultValues({\n id,\n data: dataWithDefaultValues,\n fields,\n locale: req.locale,\n siblingData: dataWithDefaultValues,\n user: req.user,\n })\n\n await iterateFields({\n id,\n addErrorPathToParent: null,\n collectionSlug,\n data: dataWithDefaultValues,\n fields,\n fieldSchemaMap,\n fullData: dataWithDefaultValues,\n operation,\n parentIndexPath: '',\n parentPassesCondition: true,\n parentPath: '',\n parentSchemaPath: schemaPath,\n permissions,\n preferences,\n previousFormState,\n renderAllFields,\n renderFieldFn,\n req,\n state,\n })\n\n return state\n }\n\n return {}\n}\n\nexport { iterateFields }\n"],"mappings":"AAaA,SAASA,sBAAsB,QAAQ;AACvC,SAASC,aAAa,QAAQ;AA+B9B,OAAO,MAAMC,uBAAA,GAA0B,MAAOC,IAAA;EAC5C,MAAM;IACJC,EAAE;IACFC,cAAc;IACdC,IAAA,GAAO,CAAC,CAAC;IACTC,MAAM;IACNC,cAAc;IACdC,SAAS;IACTC,WAAW;IACXC,WAAW;IACXC,iBAAiB;IACjBC,eAAe;IACfC,aAAa;IACbC,GAAG;IACHC;EAAU,CACX,GAAGb,IAAA;EAEJ,IAAII,MAAA,IAAUA,MAAA,CAAOU,MAAM,EAAE;IAC3B,MAAMC,KAAA,GAAoC,CAAC;IAE3C,MAAMC,qBAAA,GAAwB;MAAE,GAAGb;IAAK;IAExC,MAAMN,sBAAA,CAAuB;MAC3BI,EAAA;MACAE,IAAA,EAAMa,qBAAA;MACNZ,MAAA;MACAa,MAAA,EAAQL,GAAA,CAAIK,MAAM;MAClBC,WAAA,EAAaF,qBAAA;MACbG,IAAA,EAAMP,GAAA,CAAIO;IACZ;IAEA,MAAMrB,aAAA,CAAc;MAClBG,EAAA;MACAmB,oBAAA,EAAsB;MACtBlB,cAAA;MACAC,IAAA,EAAMa,qBAAA;MACNZ,MAAA;MACAC,cAAA;MACAgB,QAAA,EAAUL,qBAAA;MACVV,SAAA;MACAgB,eAAA,EAAiB;MACjBC,qBAAA,EAAuB;MACvBC,UAAA,EAAY;MACZC,gBAAA,EAAkBZ,UAAA;MAClBN,WAAA;MACAC,WAAA;MACAC,iBAAA;MACAC,eAAA;MACAC,aAAA;MACAC,GAAA;MACAG;IACF;IAEA,OAAOA,KAAA;EACT;EAEA,OAAO,CAAC;AACV;AAEA,SAASjB,aAAa","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data, DocumentPreferences, Field as FieldSchema, FieldSchemaMap, FormState, FormStateWithoutComponents, PayloadRequest,
|
|
1
|
+
import type { Data, DocumentPreferences, Field as FieldSchema, FieldSchemaMap, FormState, FormStateWithoutComponents, PayloadRequest, SanitizedFieldsPermissions } from 'payload';
|
|
2
2
|
import type { AddFieldStatePromiseArgs } from './addFieldStatePromise.js';
|
|
3
3
|
import type { RenderFieldMethod } from './types.js';
|
|
4
4
|
type Args = {
|
|
@@ -34,9 +34,7 @@ type Args = {
|
|
|
34
34
|
parentPassesCondition?: boolean;
|
|
35
35
|
parentPath: string;
|
|
36
36
|
parentSchemaPath: string;
|
|
37
|
-
permissions:
|
|
38
|
-
[fieldName: string]: SanitizedFieldPermissions;
|
|
39
|
-
} | null | SanitizedFieldPermissions;
|
|
37
|
+
permissions: SanitizedFieldsPermissions;
|
|
40
38
|
preferences?: DocumentPreferences;
|
|
41
39
|
previousFormState: FormState;
|
|
42
40
|
renderAllFields: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterateFields.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/iterateFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,mBAAmB,EACnB,KAAK,IAAI,WAAW,EACpB,cAAc,EACd,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"iterateFields.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/iterateFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,mBAAmB,EACnB,KAAK,IAAI,WAAW,EACpB,cAAc,EACd,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACd,0BAA0B,EAC3B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAInD,KAAK,IAAI,GAAG;IACV,oBAAoB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IACjD;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,cAAc,EAAE,cAAc,CAAA;IAC9B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,wBAAwB,KAAK,OAAO,CAAA;IACpD;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,EAAE,IAAI,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,eAAe,EAAE,MAAM,CAAA;IACvB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,WAAW,EAAE,0BAA0B,CAAA;IACvC,WAAW,CAAC,EAAE,mBAAmB,CAAA;IACjC,iBAAiB,EAAE,SAAS,CAAA;IAC5B,eAAe,EAAE,OAAO,CAAA;IACxB,aAAa,EAAE,iBAAiB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,CAAC,EAAE,0BAA0B,CAAA;CACnC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,yZA2BvB,IAAI,KAAG,OAAO,CAAC,IAAI,CA+CrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterateFields.js","names":["addFieldStatePromise","iterateFields","id","addErrorPathToParent","addErrorPathToParentArg","anyParentLocalized","collectionSlug","data","fields","fieldSchemaMap","filter","forceFullValue","fullData","includeSchema","omitParents","operation","parentIndexPath","parentPassesCondition","parentPath","parentSchemaPath","permissions","preferences","previousFormState","renderAllFields","renderFieldFn","req","skipConditionChecks","skipValidation","state","promises","forEach","field","fieldIndex","passesCondition","Boolean","admin","condition","user","push","Promise","all"],"sources":["../../../src/forms/fieldSchemasToFormState/iterateFields.ts"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field as FieldSchema,\n FieldSchemaMap,\n FormState,\n FormStateWithoutComponents,\n PayloadRequest,\n
|
|
1
|
+
{"version":3,"file":"iterateFields.js","names":["addFieldStatePromise","iterateFields","id","addErrorPathToParent","addErrorPathToParentArg","anyParentLocalized","collectionSlug","data","fields","fieldSchemaMap","filter","forceFullValue","fullData","includeSchema","omitParents","operation","parentIndexPath","parentPassesCondition","parentPath","parentSchemaPath","permissions","preferences","previousFormState","renderAllFields","renderFieldFn","req","skipConditionChecks","skipValidation","state","promises","forEach","field","fieldIndex","passesCondition","Boolean","admin","condition","user","push","parentPermissions","Promise","all"],"sources":["../../../src/forms/fieldSchemasToFormState/iterateFields.ts"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field as FieldSchema,\n FieldSchemaMap,\n FormState,\n FormStateWithoutComponents,\n PayloadRequest,\n SanitizedFieldsPermissions,\n} from 'payload'\n\nimport type { AddFieldStatePromiseArgs } from './addFieldStatePromise.js'\nimport type { RenderFieldMethod } from './types.js'\n\nimport { addFieldStatePromise } from './addFieldStatePromise.js'\n\ntype Args = {\n addErrorPathToParent: (fieldPath: string) => void\n /**\n * if any parents is localized, then the field is localized. @default false\n */\n anyParentLocalized?: boolean\n collectionSlug?: string\n data: Data\n fields: FieldSchema[]\n fieldSchemaMap: FieldSchemaMap\n filter?: (args: AddFieldStatePromiseArgs) => boolean\n /**\n * Force the value of fields like arrays or blocks to be the full value instead of the length @default false\n */\n forceFullValue?: boolean\n fullData: Data\n id?: number | string\n /**\n * Whether the field schema should be included in the state. @default false\n */\n includeSchema?: boolean\n /**\n * Whether to omit parent fields in the state. @default false\n */\n omitParents?: boolean\n /**\n * operation is only needed for validation\n */\n operation: 'create' | 'update'\n parentIndexPath: string\n parentPassesCondition?: boolean\n parentPath: string\n parentSchemaPath: string\n permissions: SanitizedFieldsPermissions\n preferences?: DocumentPreferences\n previousFormState: FormState\n renderAllFields: boolean\n renderFieldFn: RenderFieldMethod\n req: PayloadRequest\n /**\n * Whether to skip checking the field's condition. @default false\n */\n skipConditionChecks?: boolean\n /**\n * Whether to skip validating the field. @default false\n */\n skipValidation?: boolean\n state?: FormStateWithoutComponents\n}\n\n/**\n * Flattens the fields schema and fields data\n */\nexport const iterateFields = async ({\n id,\n addErrorPathToParent: addErrorPathToParentArg,\n anyParentLocalized = false,\n collectionSlug,\n data,\n fields,\n fieldSchemaMap,\n filter,\n forceFullValue = false,\n fullData,\n includeSchema = false,\n omitParents = false,\n operation,\n parentIndexPath,\n parentPassesCondition = true,\n parentPath,\n parentSchemaPath,\n permissions,\n preferences,\n previousFormState,\n renderAllFields,\n renderFieldFn: renderFieldFn,\n req,\n skipConditionChecks = false,\n skipValidation = false,\n state = {},\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field, fieldIndex) => {\n let passesCondition = true\n if (!skipConditionChecks) {\n passesCondition = Boolean(\n (field?.admin?.condition\n ? Boolean(field.admin.condition(fullData || {}, data || {}, { user: req.user }))\n : true) && parentPassesCondition,\n )\n }\n\n promises.push(\n addFieldStatePromise({\n id,\n addErrorPathToParent: addErrorPathToParentArg,\n anyParentLocalized,\n collectionSlug,\n data,\n field,\n fieldIndex,\n fieldSchemaMap,\n filter,\n forceFullValue,\n fullData,\n includeSchema,\n omitParents,\n operation,\n parentIndexPath,\n parentPath,\n parentPermissions: permissions,\n parentSchemaPath,\n passesCondition,\n preferences,\n previousFormState,\n renderAllFields,\n renderFieldFn,\n req,\n skipConditionChecks,\n skipValidation,\n state,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"mappings":"AAcA,SAASA,oBAAoB,QAAQ;AAoDrC;;;AAGA,OAAO,MAAMC,aAAA,GAAgB,MAAAA,CAAO;EAClCC,EAAE;EACFC,oBAAA,EAAsBC,uBAAuB;EAC7CC,kBAAA,GAAqB,KAAK;EAC1BC,cAAc;EACdC,IAAI;EACJC,MAAM;EACNC,cAAc;EACdC,MAAM;EACNC,cAAA,GAAiB,KAAK;EACtBC,QAAQ;EACRC,aAAA,GAAgB,KAAK;EACrBC,WAAA,GAAc,KAAK;EACnBC,SAAS;EACTC,eAAe;EACfC,qBAAA,GAAwB,IAAI;EAC5BC,UAAU;EACVC,gBAAgB;EAChBC,WAAW;EACXC,WAAW;EACXC,iBAAiB;EACjBC,eAAe;EACfC,aAAA,EAAeA,aAAa;EAC5BC,GAAG;EACHC,mBAAA,GAAsB,KAAK;EAC3BC,cAAA,GAAiB,KAAK;EACtBC,KAAA,GAAQ,CAAC;AAAC,CACL;EACL,MAAMC,QAAA,GAAW,EAAE;EAEnBrB,MAAA,CAAOsB,OAAO,CAAC,CAACC,KAAA,EAAOC,UAAA;IACrB,IAAIC,eAAA,GAAkB;IACtB,IAAI,CAACP,mBAAA,EAAqB;MACxBO,eAAA,GAAkBC,OAAA,CAChB,CAACH,KAAA,EAAOI,KAAA,EAAOC,SAAA,GACXF,OAAA,CAAQH,KAAA,CAAMI,KAAK,CAACC,SAAS,CAACxB,QAAA,IAAY,CAAC,GAAGL,IAAA,IAAQ,CAAC,GAAG;QAAE8B,IAAA,EAAMZ,GAAA,CAAIY;MAAK,MAC3E,IAAG,KAAMpB,qBAAA;IAEjB;IAEAY,QAAA,CAASS,IAAI,CACXtC,oBAAA,CAAqB;MACnBE,EAAA;MACAC,oBAAA,EAAsBC,uBAAA;MACtBC,kBAAA;MACAC,cAAA;MACAC,IAAA;MACAwB,KAAA;MACAC,UAAA;MACAvB,cAAA;MACAC,MAAA;MACAC,cAAA;MACAC,QAAA;MACAC,aAAA;MACAC,WAAA;MACAC,SAAA;MACAC,eAAA;MACAE,UAAA;MACAqB,iBAAA,EAAmBnB,WAAA;MACnBD,gBAAA;MACAc,eAAA;MACAZ,WAAA;MACAC,iBAAA;MACAC,eAAA;MACAC,aAAA;MACAC,GAAA;MACAC,mBAAA;MACAC,cAAA;MACAC;IACF;EAEJ;EAEA,MAAMY,OAAA,CAAQC,GAAG,CAACZ,QAAA;AACpB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderField.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderField.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAanD,eAAO,MAAM,WAAW,EAAE,iBA6NzB,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getTranslation } from '@payloadcms/translations';
|
|
3
3
|
import { createClientField, deepCopyObjectSimple, MissingEditorProp } from 'payload';
|
|
4
|
-
import { fieldAffectsData } from 'payload/shared';
|
|
5
4
|
import { RenderServerComponent } from '../../elements/RenderServerComponent/index.js';
|
|
6
5
|
// eslint-disable-next-line payload/no-imports-from-exports-dir -- need this to reference already existing bundle. Otherwise, bundle size increases., payload/no-imports-from-exports-dir
|
|
7
6
|
import { FieldDescription } from '../../exports/client/index.js';
|
|
@@ -19,15 +18,12 @@ export const renderField = ({
|
|
|
19
18
|
parentPath,
|
|
20
19
|
parentSchemaPath,
|
|
21
20
|
path,
|
|
22
|
-
permissions
|
|
21
|
+
permissions,
|
|
23
22
|
preferences,
|
|
24
23
|
req,
|
|
25
24
|
schemaPath,
|
|
26
25
|
siblingData
|
|
27
26
|
}) => {
|
|
28
|
-
// TODO (ALESSIO): why are we passing the fieldConfig twice?
|
|
29
|
-
// and especially, why are we deepCopyObject -here- instead of inside the createClientField func,
|
|
30
|
-
// so no one screws this up in the future?
|
|
31
27
|
const clientField = createClientField({
|
|
32
28
|
clientField: deepCopyObjectSimple(fieldConfig),
|
|
33
29
|
defaultIDType: req.payload.config.db.defaultIDType,
|
|
@@ -35,12 +31,11 @@ export const renderField = ({
|
|
|
35
31
|
i18n: req.i18n,
|
|
36
32
|
importMap: req.payload.importMap
|
|
37
33
|
});
|
|
38
|
-
const permissions = incomingPermissions === true ? true : fieldAffectsData(fieldConfig) ? incomingPermissions?.[fieldConfig.name] : {};
|
|
39
34
|
const clientProps = {
|
|
40
35
|
customComponents: fieldState?.customComponents || {},
|
|
41
36
|
field: clientField,
|
|
42
37
|
path,
|
|
43
|
-
readOnly: permissions
|
|
38
|
+
readOnly: typeof permissions === 'boolean' ? !permissions : !permissions?.[operation],
|
|
44
39
|
schemaPath
|
|
45
40
|
};
|
|
46
41
|
// fields with subfields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderField.js","names":["getTranslation","createClientField","deepCopyObjectSimple","MissingEditorProp","fieldAffectsData","RenderServerComponent","FieldDescription","defaultUIFieldComponentKeys","renderField","id","collectionSlug","data","fieldConfig","fieldSchemaMap","fieldState","formState","indexPath","operation","parentPath","parentSchemaPath","path","permissions","incomingPermissions","preferences","req","schemaPath","siblingData","clientField","defaultIDType","payload","config","db","field","i18n","importMap","name","clientProps","customComponents","readOnly","includes","type","serverProps","user","rows","forEach","row","rowIndex","admin","components","RowLabels","Component","RowLabel","rowLabel","labels","singular","String","padStart","rowNumber","editor","Error","Field","FieldComponent","key","description","Description","_jsx","t","AfterInput","afterInput","BeforeInput","beforeInput","Label"],"sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"sourcesContent":["import type {\n ClientComponentProps,\n ClientField,\n FieldPaths,\n SanitizedFieldPermissions,\n ServerComponentProps,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { createClientField, deepCopyObjectSimple, MissingEditorProp } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { RenderServerComponent } from '../../elements/RenderServerComponent/index.js'\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- need this to reference already existing bundle. Otherwise, bundle size increases., payload/no-imports-from-exports-dir\nimport { FieldDescription } from '../../exports/client/index.js'\n\nconst defaultUIFieldComponentKeys: Array<'Cell' | 'Description' | 'Field' | 'Filter'> = [\n 'Cell',\n 'Description',\n 'Field',\n 'Filter',\n]\n\nexport const renderField: RenderFieldMethod = ({\n id,\n collectionSlug,\n data,\n fieldConfig,\n fieldSchemaMap,\n fieldState,\n formState,\n indexPath,\n operation,\n parentPath,\n parentSchemaPath,\n path,\n permissions: incomingPermissions,\n preferences,\n req,\n schemaPath,\n siblingData,\n}) => {\n // TODO (ALESSIO): why are we passing the fieldConfig twice?\n // and especially, why are we deepCopyObject -here- instead of inside the createClientField func,\n // so no one screws this up in the future?\n const clientField = createClientField({\n clientField: deepCopyObjectSimple(fieldConfig) as ClientField,\n defaultIDType: req.payload.config.db.defaultIDType,\n field: fieldConfig,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n })\n\n const permissions =\n incomingPermissions === true\n ? true\n : fieldAffectsData(fieldConfig)\n ? incomingPermissions?.[fieldConfig.name]\n : ({} as SanitizedFieldPermissions)\n\n const clientProps: ClientComponentProps & Partial<FieldPaths> = {\n customComponents: fieldState?.customComponents || {},\n field: clientField,\n path,\n readOnly: permissions !== true && !permissions?.[operation],\n schemaPath,\n }\n\n // fields with subfields\n if (['array', 'blocks', 'collapsible', 'group', 'row', 'tabs'].includes(fieldConfig.type)) {\n clientProps.indexPath = indexPath\n clientProps.parentPath = parentPath\n clientProps.parentSchemaPath = parentSchemaPath\n }\n\n const serverProps: ServerComponentProps = {\n id,\n clientField,\n data,\n field: fieldConfig,\n fieldSchemaMap,\n permissions,\n // TODO: Should we pass explicit values? initialValue, value, valid\n // value and initialValue should be typed\n collectionSlug,\n formState,\n i18n: req.i18n,\n operation,\n payload: req.payload,\n preferences,\n req,\n siblingData,\n user: req.user,\n }\n\n if (!fieldState?.customComponents) {\n fieldState.customComponents = {}\n }\n\n switch (fieldConfig.type) {\n // TODO: handle block row labels as well in a similar fashion\n case 'array': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n if (fieldConfig.admin?.components && 'RowLabel' in fieldConfig.admin.components) {\n if (!fieldState.customComponents.RowLabels) {\n fieldState.customComponents.RowLabels = []\n }\n\n fieldState.customComponents.RowLabels[rowIndex] = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.RowLabel,\n importMap: req.payload.importMap,\n serverProps: {\n ...serverProps,\n rowLabel: `${getTranslation(fieldConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n },\n })\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!fieldConfig?.editor) {\n throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof fieldConfig?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!fieldConfig.admin) {\n fieldConfig.admin = {}\n }\n\n if (!fieldConfig.admin.components) {\n fieldConfig.admin.components = {}\n }\n\n fieldState.customComponents.Field = RenderServerComponent({\n clientProps,\n Component: fieldConfig.editor.FieldComponent,\n importMap: req.payload.importMap,\n serverProps,\n })\n\n break\n }\n\n case 'ui': {\n if (fieldConfig?.admin?.components) {\n // Render any extra, untyped components\n for (const key in fieldConfig.admin.components) {\n if (key in defaultUIFieldComponentKeys) {\n continue\n }\n const Component = fieldConfig.admin.components[key]\n fieldState.customComponents[key] = RenderServerComponent({\n clientProps,\n Component,\n importMap: req.payload.importMap,\n key: `field.admin.components.${key}`,\n serverProps,\n })\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldConfig.admin) {\n if ('description' in fieldConfig.admin) {\n if (typeof fieldConfig.admin?.description === 'function') {\n fieldState.customComponents.Description = (\n <FieldDescription\n description={fieldConfig.admin?.description({\n t: req.i18n.t,\n })}\n path={path}\n />\n )\n }\n }\n\n if (fieldConfig.admin?.components) {\n if ('afterInput' in fieldConfig.admin.components) {\n fieldState.customComponents.AfterInput = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.afterInput,\n importMap: req.payload.importMap,\n key: 'field.admin.components.afterInput',\n serverProps,\n })\n }\n\n if ('beforeInput' in fieldConfig.admin.components) {\n fieldState.customComponents.BeforeInput = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.beforeInput,\n importMap: req.payload.importMap,\n key: 'field.admin.components.beforeInput',\n serverProps,\n })\n }\n\n if ('Description' in fieldConfig.admin.components) {\n fieldState.customComponents.Description = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Description,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Description',\n serverProps,\n })\n }\n\n if ('Error' in fieldConfig.admin.components) {\n fieldState.customComponents.Error = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Error,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Error',\n serverProps,\n })\n }\n\n if ('Label' in fieldConfig.admin.components) {\n fieldState.customComponents.Label = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Label,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Label',\n serverProps,\n })\n }\n\n if ('Field' in fieldConfig.admin.components) {\n fieldState.customComponents.Field = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Field,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Field',\n serverProps,\n })\n }\n }\n }\n}\n"],"mappings":";AAQA,SAASA,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,oBAAoB,EAAEC,iBAAiB,QAAQ;AAC3E,SAASC,gBAAgB,QAAQ;AAIjC,SAASC,qBAAqB,QAAQ;AACtC;AACA,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,2BAAA,GAAkF,CACtF,QACA,eACA,SACA,SACD;AAED,OAAO,MAAMC,WAAA,GAAiCA,CAAC;EAC7CC,EAAE;EACFC,cAAc;EACdC,IAAI;EACJC,WAAW;EACXC,cAAc;EACdC,UAAU;EACVC,SAAS;EACTC,SAAS;EACTC,SAAS;EACTC,UAAU;EACVC,gBAAgB;EAChBC,IAAI;EACJC,WAAA,EAAaC,mBAAmB;EAChCC,WAAW;EACXC,GAAG;EACHC,UAAU;EACVC;AAAW,CACZ;EACC;EACA;EACA;EACA,MAAMC,WAAA,GAAc1B,iBAAA,CAA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AAW7B,WAAA,CAAYmC,KAAK,CAACC,UAAU,EAAE;QAC3ClC,UAAA,CAAWuB,gBAAgB,CAACkC,KAAK,GAAGlE,qBAAA,CAAsB;UACxD+B,WAAA;UACAc,SAAA,EAAWtC,WAAA,CAAYmC,KAAK,CAACC,UAAU,CAACuB,KAAK;UAC7CrC,SAAA,EAAWV,GAAA,CAAIK,OAAO,CAACK,SAAS;UAChC4B,GAAA,EAAK;UACLrB;QACF;MACF;MAEA,IAAI,WAAW7B,WAAA,CAAYmC,KAAK,CAACC,UAAU,EAAE;QAC3ClC,UAAA,CAAWuB,gBAAgB,CAACuB,KAAK,GAAGvD,qBAAA,CAAsB;UACxD+B,WAAA;UACAc,SAAA,EAAWtC,WAAA,CAAYmC,KAAK,CAACC,UAAU,CAACY,KAAK;UAC7C1B,SAAA,EAAWV,GAAA,CAAIK,OAAO,CAACK,SAAS;UAChC4B,GAAA,EAAK;UACLrB;QACF;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"renderField.js","names":["getTranslation","createClientField","deepCopyObjectSimple","MissingEditorProp","RenderServerComponent","FieldDescription","defaultUIFieldComponentKeys","renderField","id","collectionSlug","data","fieldConfig","fieldSchemaMap","fieldState","formState","indexPath","operation","parentPath","parentSchemaPath","path","permissions","preferences","req","schemaPath","siblingData","clientField","defaultIDType","payload","config","db","field","i18n","importMap","clientProps","customComponents","readOnly","includes","type","serverProps","user","rows","forEach","row","rowIndex","admin","components","RowLabels","Component","RowLabel","rowLabel","labels","singular","String","padStart","rowNumber","editor","Error","Field","FieldComponent","key","description","Description","_jsx","t","AfterInput","afterInput","BeforeInput","beforeInput","Label"],"sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"sourcesContent":["import type { ClientComponentProps, ClientField, FieldPaths, ServerComponentProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { createClientField, deepCopyObjectSimple, MissingEditorProp } from 'payload'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { RenderServerComponent } from '../../elements/RenderServerComponent/index.js'\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- need this to reference already existing bundle. Otherwise, bundle size increases., payload/no-imports-from-exports-dir\nimport { FieldDescription } from '../../exports/client/index.js'\n\nconst defaultUIFieldComponentKeys: Array<'Cell' | 'Description' | 'Field' | 'Filter'> = [\n 'Cell',\n 'Description',\n 'Field',\n 'Filter',\n]\n\nexport const renderField: RenderFieldMethod = ({\n id,\n collectionSlug,\n data,\n fieldConfig,\n fieldSchemaMap,\n fieldState,\n formState,\n indexPath,\n operation,\n parentPath,\n parentSchemaPath,\n path,\n permissions,\n preferences,\n req,\n schemaPath,\n siblingData,\n}) => {\n const clientField = createClientField({\n clientField: deepCopyObjectSimple(fieldConfig) as ClientField,\n defaultIDType: req.payload.config.db.defaultIDType,\n field: fieldConfig,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n })\n\n const clientProps: ClientComponentProps & Partial<FieldPaths> = {\n customComponents: fieldState?.customComponents || {},\n field: clientField,\n path,\n readOnly: typeof permissions === 'boolean' ? !permissions : !permissions?.[operation],\n schemaPath,\n }\n\n // fields with subfields\n if (['array', 'blocks', 'collapsible', 'group', 'row', 'tabs'].includes(fieldConfig.type)) {\n clientProps.indexPath = indexPath\n clientProps.parentPath = parentPath\n clientProps.parentSchemaPath = parentSchemaPath\n }\n\n const serverProps: ServerComponentProps = {\n id,\n clientField,\n data,\n field: fieldConfig,\n fieldSchemaMap,\n permissions,\n // TODO: Should we pass explicit values? initialValue, value, valid\n // value and initialValue should be typed\n collectionSlug,\n formState,\n i18n: req.i18n,\n operation,\n payload: req.payload,\n preferences,\n req,\n siblingData,\n user: req.user,\n }\n\n if (!fieldState?.customComponents) {\n fieldState.customComponents = {}\n }\n\n switch (fieldConfig.type) {\n // TODO: handle block row labels as well in a similar fashion\n case 'array': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n if (fieldConfig.admin?.components && 'RowLabel' in fieldConfig.admin.components) {\n if (!fieldState.customComponents.RowLabels) {\n fieldState.customComponents.RowLabels = []\n }\n\n fieldState.customComponents.RowLabels[rowIndex] = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.RowLabel,\n importMap: req.payload.importMap,\n serverProps: {\n ...serverProps,\n rowLabel: `${getTranslation(fieldConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n },\n })\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!fieldConfig?.editor) {\n throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof fieldConfig?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!fieldConfig.admin) {\n fieldConfig.admin = {}\n }\n\n if (!fieldConfig.admin.components) {\n fieldConfig.admin.components = {}\n }\n\n fieldState.customComponents.Field = RenderServerComponent({\n clientProps,\n Component: fieldConfig.editor.FieldComponent,\n importMap: req.payload.importMap,\n serverProps,\n })\n\n break\n }\n\n case 'ui': {\n if (fieldConfig?.admin?.components) {\n // Render any extra, untyped components\n for (const key in fieldConfig.admin.components) {\n if (key in defaultUIFieldComponentKeys) {\n continue\n }\n const Component = fieldConfig.admin.components[key]\n fieldState.customComponents[key] = RenderServerComponent({\n clientProps,\n Component,\n importMap: req.payload.importMap,\n key: `field.admin.components.${key}`,\n serverProps,\n })\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldConfig.admin) {\n if ('description' in fieldConfig.admin) {\n if (typeof fieldConfig.admin?.description === 'function') {\n fieldState.customComponents.Description = (\n <FieldDescription\n description={fieldConfig.admin?.description({\n t: req.i18n.t,\n })}\n path={path}\n />\n )\n }\n }\n\n if (fieldConfig.admin?.components) {\n if ('afterInput' in fieldConfig.admin.components) {\n fieldState.customComponents.AfterInput = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.afterInput,\n importMap: req.payload.importMap,\n key: 'field.admin.components.afterInput',\n serverProps,\n })\n }\n\n if ('beforeInput' in fieldConfig.admin.components) {\n fieldState.customComponents.BeforeInput = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.beforeInput,\n importMap: req.payload.importMap,\n key: 'field.admin.components.beforeInput',\n serverProps,\n })\n }\n\n if ('Description' in fieldConfig.admin.components) {\n fieldState.customComponents.Description = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Description,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Description',\n serverProps,\n })\n }\n\n if ('Error' in fieldConfig.admin.components) {\n fieldState.customComponents.Error = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Error,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Error',\n serverProps,\n })\n }\n\n if ('Label' in fieldConfig.admin.components) {\n fieldState.customComponents.Label = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Label,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Label',\n serverProps,\n })\n }\n\n if ('Field' in fieldConfig.admin.components) {\n fieldState.customComponents.Field = RenderServerComponent({\n clientProps,\n Component: fieldConfig.admin.components.Field,\n importMap: req.payload.importMap,\n key: 'field.admin.components.Field',\n serverProps,\n })\n }\n }\n }\n}\n"],"mappings":";AAEA,SAASA,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,oBAAoB,EAAEC,iBAAiB,QAAQ;AAI3E,SAASC,qBAAqB,QAAQ;AACtC;AACA,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,2BAAA,GAAkF,CACtF,QACA,eACA,SACA,SACD;AAED,OAAO,MAAMC,WAAA,GAAiCA,CAAC;EAC7CC,EAAE;EACFC,cAAc;EACdC,IAAI;EACJC,WAAW;EACXC,cAAc;EACdC,UAAU;EACVC,SAAS;EACTC,SAAS;EACTC,SAAS;EACTC,UAAU;EACVC,gBAAgB;EAChBC,IAAI;EACJC,WAAW;EACXC,WAAW;EACXC,GAAG;EACHC,UAAU;EACVC;AAAW,CACZ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AAK,GAAGhE,qBAAA,CAAsB;UACxD6B,WAAA;UACAc,SAAA,EAAWpC,WAAA,CAAYiC,KAAK,CAACC,UAAU,CAACuB,KAAK;UAC7CpC,SAAA,EAAWV,GAAA,CAAIK,OAAO,CAACK,SAAS;UAChC2B,GAAA,EAAK;UACLrB;QACF;MACF;MAEA,IAAI,WAAW3B,WAAA,CAAYiC,KAAK,CAACC,UAAU,EAAE;QAC3ChC,UAAA,CAAWqB,gBAAgB,CAACuB,KAAK,GAAGrD,qBAAA,CAAsB;UACxD6B,WAAA;UACAc,SAAA,EAAWpC,WAAA,CAAYiC,KAAK,CAACC,UAAU,CAACY,KAAK;UAC7CzB,SAAA,EAAWV,GAAA,CAAIK,OAAO,CAACK,SAAS;UAChC2B,GAAA,EAAK;UACLrB;QACF;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -12,9 +12,7 @@ export type RenderFieldArgs = {
|
|
|
12
12
|
parentPath: string;
|
|
13
13
|
parentSchemaPath: string;
|
|
14
14
|
path: string;
|
|
15
|
-
permissions:
|
|
16
|
-
[fieldName: string]: SanitizedFieldPermissions;
|
|
17
|
-
} | null | SanitizedFieldPermissions;
|
|
15
|
+
permissions: SanitizedFieldPermissions;
|
|
18
16
|
preferences: DocumentPreferences;
|
|
19
17
|
previousFieldState: FieldState;
|
|
20
18
|
req: PayloadRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,KAAK,CAAA;IAClB,c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|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FieldState,\n FormState,\n Operation,\n PayloadRequest,\n SanitizedFieldPermissions,\n} from 'payload'\n\nexport type RenderFieldArgs = {\n collectionSlug: string\n data: Data\n fieldConfig: Field\n fieldSchemaMap: FieldSchemaMap\n fieldState: FieldState\n formState: FormState\n id?: number | string\n indexPath: string\n operation: Operation\n parentPath: string\n parentSchemaPath: string\n path: string\n permissions
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FieldState,\n FormState,\n Operation,\n PayloadRequest,\n SanitizedFieldPermissions,\n} from 'payload'\n\nexport type RenderFieldArgs = {\n collectionSlug: string\n data: Data\n fieldConfig: Field\n fieldSchemaMap: FieldSchemaMap\n fieldState: FieldState\n formState: FormState\n id?: number | string\n indexPath: string\n operation: Operation\n parentPath: string\n parentSchemaPath: string\n path: string\n permissions: SanitizedFieldPermissions\n preferences: DocumentPreferences\n previousFieldState: FieldState\n req: PayloadRequest\n schemaPath: string\n siblingData: Data\n}\n\nexport type RenderFieldMethod = (args: RenderFieldArgs) => void\n"],"mappings":"AAiCA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Actions/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8C,MAAM,OAAO,CAAA;AAElE,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;KAC/B,CAAA;IACD,cAAc,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;CACjE,CAAA;AAOD,eAAO,MAAM,UAAU,0BAAmC,CAAA;AAE1D,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;KAC/B,CAAA;IACD,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CACnC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Actions/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8C,MAAM,OAAO,CAAA;AAElE,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;KAC/B,CAAA;IACD,cAAc,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;CACjE,CAAA;AAOD,eAAO,MAAM,UAAU,0BAAmC,CAAA;AAE1D,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;KAC/B,CAAA;IACD,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CACnC,CAgBA,CAAA"}
|
|
@@ -11,26 +11,30 @@ export const useActions = () => {
|
|
|
11
11
|
return useContext(ActionsContext);
|
|
12
12
|
};
|
|
13
13
|
export const ActionsProvider = t0 => {
|
|
14
|
-
const $ = _c(
|
|
14
|
+
const $ = _c(4);
|
|
15
15
|
const {
|
|
16
16
|
Actions,
|
|
17
17
|
children
|
|
18
18
|
} = t0;
|
|
19
19
|
const [viewActions, setViewActions] = useState(Actions);
|
|
20
20
|
let t1;
|
|
21
|
-
if ($[0] !== viewActions || $[1] !== children) {
|
|
21
|
+
if ($[0] !== viewActions || $[1] !== Actions || $[2] !== children) {
|
|
22
22
|
t1 = _jsx(ActionsContext.Provider, {
|
|
23
23
|
value: {
|
|
24
|
-
Actions:
|
|
24
|
+
Actions: {
|
|
25
|
+
...viewActions,
|
|
26
|
+
...Actions
|
|
27
|
+
},
|
|
25
28
|
setViewActions
|
|
26
29
|
},
|
|
27
30
|
children
|
|
28
31
|
});
|
|
29
32
|
$[0] = viewActions;
|
|
30
|
-
$[1] =
|
|
31
|
-
$[2] =
|
|
33
|
+
$[1] = Actions;
|
|
34
|
+
$[2] = children;
|
|
35
|
+
$[3] = t1;
|
|
32
36
|
} else {
|
|
33
|
-
t1 = $[
|
|
37
|
+
t1 = $[3];
|
|
34
38
|
}
|
|
35
39
|
return t1;
|
|
36
40
|
};
|
|
@@ -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;AAEA,OAAO,MAAMK,mBAAA,GAAgEA,CAAC;EAAEC;AAAQ,CAAE;EACxF,MAAMC,UAAA,GAAahB,MAAA,CAAO,CAAC;EAC3B,MAAMiB,cAAA,GAAiBjB,MAAA,CAAO,CAAC;EAC/B,MAAMkB,aAAA,GAAgBlB,MAAA,CAAO,CAAC;EAC9B,MAAM;IAAEmB;EAAM,CAAE,GAAGd,SAAA;EACnB,MAAM;IAAEe;EAAI,CAAE,GAAGhB,OAAA;EACjB,MAAM;IAAEiB;EAAI,CAAE,GAAGpB,cAAA;EAEjB,MAAM;IACJqB,MAAA,EAAQ;MAAEC;IAAG,CAAE;IACfC;EAAS,CACV,GAAGL,MAAA;EAEJpB,SAAA,CAAU;IACR,IAAI,CAACqB,IAAA,EAAM;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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,EAAS;IACP,mBAAmBJ,QAAA;IACnB,gBAAgB;EAClB;AACF;AAEA,OAAO,MAAMK,mBAAA,GAAgEA,CAAC;EAAEC;AAAQ,CAAE;EACxF,MAAMC,UAAA,GAAahB,MAAA,CAAO,CAAC;EAC3B,MAAMiB,cAAA,GAAiBjB,MAAA,CAAO,CAAC;EAC/B,MAAMkB,aAAA,GAAgBlB,MAAA,CAAO,CAAC;EAC9B,MAAM;IAAEmB;EAAM,CAAE,GAAGd,SAAA;EACnB,MAAM;IAAEe;EAAI,CAAE,GAAGhB,OAAA;EACjB,MAAM;IAAEiB;EAAI,CAAE,GAAGpB,cAAA;EAEjB,MAAM;IACJqB,MAAA,EAAQ;MAAEC;IAAG,CAAE;IACfC;EAAS,CACV,GAAGL,MAA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AC1B,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,SAA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;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,EAAE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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 +1 @@
|
|
|
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,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,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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,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