payload 3.34.0 → 3.35.0-internal.b3d367c

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.
@@ -20,6 +20,8 @@ export type VersionField = {
20
20
  };
21
21
  /**
22
22
  * Taken from react-diff-viewer-continued
23
+ *
24
+ * @deprecated remove in 4.0 - react-diff-viewer-continued is no longer a dependency
23
25
  */
24
26
  export declare enum DiffMethod {
25
27
  CHARS = "diffChars",
@@ -34,10 +36,13 @@ export declare enum DiffMethod {
34
36
  export type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalType = ClientField> = {
35
37
  baseVersionField: BaseVersionField;
36
38
  /**
37
- * Field value from the version being compared
39
+ * Field value from the version being compared from
38
40
  */
39
41
  comparisonValue: unknown;
40
- diffMethod: DiffMethod;
42
+ /**
43
+ * @deprecated remove in 4.0. react-diff-viewer-continued is no longer a dependency
44
+ */
45
+ diffMethod: any;
41
46
  field: TClientField;
42
47
  fieldPermissions: {
43
48
  [key: string]: SanitizedFieldPermissions;
@@ -46,9 +51,11 @@ export type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalTyp
46
51
  * If this field is localized, this will be the locale of the field
47
52
  */
48
53
  locale?: string;
54
+ nestingLevel?: number;
49
55
  parentIsLocalized: boolean;
50
56
  /**
51
- * Field value from the current version
57
+ * Field value from the version being compared to
58
+ *
52
59
  */
53
60
  versionValue: unknown;
54
61
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Diff.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAA;AACvF,OAAO,KAAK,EACV,2BAA2B,EAC3B,cAAc,EACd,yBAAyB,EACzB,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAEvB,MA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A;IACb,IAAI,EAAE,UAAU,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAA;AAEvC,MAAM,MAAM,wBAAwB,CAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAAA;AAE3D,MAAM,MAAM,wBAAwB,CAClC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Diff.ts"],"sourcesContent":["// @ts-strict-ignore\n\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport type { ClientField, Field, FieldTypes, Tab } from '../../fields/config/types.js'\nimport type {\n ClientFieldWithOptionalType,\n PayloadRequest,\n SanitizedFieldPermissions,\n TypedLocale,\n} from '../../index.js'\n\nexport type VersionTab = {\n fields: VersionField[]\n name?: string\n} & Pick<Tab, 'label'>\n\nexport type BaseVersionField = {\n CustomComponent?: React.ReactNode\n fields: VersionField[]\n path: string\n rows?: VersionField[][]\n schemaPath: string\n tabs?: VersionTab[]\n type: FieldTypes\n}\n\nexport type VersionField = {\n field?: BaseVersionField\n fieldByLocale?: Record<TypedLocale, BaseVersionField>\n}\n\n/**\n * Taken from react-diff-viewer-continued\n */\nexport declare enum DiffMethod {\n CHARS = 'diffChars',\n CSS = 'diffCss',\n JSON = 'diffJson',\n LINES = 'diffLines',\n SENTENCES = 'diffSentences',\n TRIMMED_LINES = 'diffTrimmedLines',\n WORDS = 'diffWords',\n WORDS_WITH_SPACE = 'diffWordsWithSpace',\n}\n\nexport type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalType = ClientField> = {\n baseVersionField: BaseVersionField\n /**\n * Field value from the version being compared\n */\n comparisonValue: unknown\n diffMethod: DiffMethod\n field: TClientField\n fieldPermissions:\n | {\n [key: string]: SanitizedFieldPermissions\n }\n | true\n /**\n * If this field is localized, this will be the locale of the field\n */\n locale?: string\n parentIsLocalized: boolean\n /**\n * Field value from the current version\n */\n versionValue: unknown\n}\n\nexport type FieldDiffServerProps<\n TField extends Field = Field,\n TClientField extends ClientFieldWithOptionalType = ClientField,\n> = {\n clientField: TClientField\n field: TField\n i18n: I18nClient\n req: PayloadRequest\n selectedLocales: string[]\n} & Omit<FieldDiffClientProps, 'field'>\n\nexport type FieldDiffClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDiffClientProps<TFieldClient>>\n\nexport type FieldDiffServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDiffServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAAA,oBAAoB;AAqFpB,WAGyE"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Diff.ts"],"sourcesContent":["// @ts-strict-ignore\n\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport type { ClientField, Field, FieldTypes, Tab } from '../../fields/config/types.js'\nimport type {\n ClientFieldWithOptionalType,\n PayloadRequest,\n SanitizedFieldPermissions,\n TypedLocale,\n} from '../../index.js'\n\nexport type VersionTab = {\n fields: VersionField[]\n name?: string\n} & Pick<Tab, 'label'>\n\nexport type BaseVersionField = {\n CustomComponent?: React.ReactNode\n fields: VersionField[]\n path: string\n rows?: VersionField[][]\n schemaPath: string\n tabs?: VersionTab[]\n type: FieldTypes\n}\n\nexport type VersionField = {\n field?: BaseVersionField\n fieldByLocale?: Record<TypedLocale, BaseVersionField>\n}\n\n/**\n * Taken from react-diff-viewer-continued\n *\n * @deprecated remove in 4.0 - react-diff-viewer-continued is no longer a dependency\n */\nexport declare enum DiffMethod {\n CHARS = 'diffChars',\n CSS = 'diffCss',\n JSON = 'diffJson',\n LINES = 'diffLines',\n SENTENCES = 'diffSentences',\n TRIMMED_LINES = 'diffTrimmedLines',\n WORDS = 'diffWords',\n WORDS_WITH_SPACE = 'diffWordsWithSpace',\n}\n\nexport type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalType = ClientField> = {\n baseVersionField: BaseVersionField\n /**\n * Field value from the version being compared from\n */\n comparisonValue: unknown // TODO: change to valueFrom in 4.0\n /**\n * @deprecated remove in 4.0. react-diff-viewer-continued is no longer a dependency\n */\n diffMethod: any\n field: TClientField\n fieldPermissions:\n | {\n [key: string]: SanitizedFieldPermissions\n }\n | true\n /**\n * If this field is localized, this will be the locale of the field\n */\n locale?: string\n nestingLevel?: number\n parentIsLocalized: boolean\n /**\n * Field value from the version being compared to\n *\n */\n versionValue: unknown // TODO: change to valueTo in 4.0\n}\n\nexport type FieldDiffServerProps<\n TField extends Field = Field,\n TClientField extends ClientFieldWithOptionalType = ClientField,\n> = {\n clientField: TClientField\n field: TField\n i18n: I18nClient\n req: PayloadRequest\n selectedLocales: string[]\n} & Omit<FieldDiffClientProps, 'field'>\n\nexport type FieldDiffClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDiffClientProps<TFieldClient>>\n\nexport type FieldDiffServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDiffServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAAA,oBAAoB;AA4FpB,WAGyE"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/orderable/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAE3F,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,aAAa,CAAA;AAM5E;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,WAAY,eAAe,SAkDrD,CAAA;AAED,eAAO,MAAM,yBAAyB,eACxB,gBAAgB,uBACP,MAAM,EAAE,SAkE9B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAA;IAChC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAA;QACV,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF,CAAA;AAED,eAAO,MAAM,oBAAoB,WAAY,eAAe,SA+H3D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/orderable/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAE3F,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,aAAa,CAAA;AAM5E;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,WAAY,eAAe,SAkDrD,CAAA;AAED,eAAO,MAAM,yBAAyB,eACxB,gBAAgB,uBACP,MAAM,EAAE,SAiE9B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAA;IAChC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAA;QACV,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF,CAAA;AAED,eAAO,MAAM,oBAAoB,WAAY,eAAe,SA+H3D,CAAA"}
@@ -95,7 +95,6 @@ export const addOrderableFieldsAndHook = (collection, orderableFieldNames)=>{
95
95
  const orderBeforeChangeHook = async ({ data, originalDoc, req })=>{
96
96
  for (const orderableFieldName of orderableFieldNames){
97
97
  if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {
98
- console.log('do not enter');
99
98
  const lastDoc = await req.payload.find({
100
99
  collection: collection.slug,
101
100
  depth: 0,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/orderable/index.ts"],"sourcesContent":["import type { BeforeChangeHook, CollectionConfig } from '../../collections/config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { Endpoint, PayloadHandler, SanitizedConfig } from '../types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { traverseFields } from '../../utilities/traverseFields.js'\nimport { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js'\n\n/**\n * This function creates:\n * - N fields per collection, named `_order` or `_<collection>_<joinField>_order`\n * - 1 hook per collection\n * - 1 endpoint per app\n *\n * Also, if collection.defaultSort or joinField.defaultSort is not set, it will be set to the orderable field.\n */\nexport const setupOrderable = (config: SanitizedConfig) => {\n const fieldsToAdd = new Map<CollectionConfig, string[]>()\n\n config.collections.forEach((collection) => {\n if (collection.orderable) {\n const currentFields = fieldsToAdd.get(collection) || []\n fieldsToAdd.set(collection, [...currentFields, '_order'])\n collection.defaultSort = collection.defaultSort ?? '_order'\n }\n\n traverseFields({\n callback: ({ field, parentRef, ref }) => {\n if (field.type === 'array' || field.type === 'blocks') {\n return false\n }\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}`\n }\n if (field.type === 'join' && field.orderable === true) {\n if (Array.isArray(field.collection)) {\n throw new Error('Orderable joins must target a single collection')\n }\n const relationshipCollection = config.collections.find((c) => c.slug === field.collection)\n if (!relationshipCollection) {\n return false\n }\n field.defaultSort = field.defaultSort ?? `_${field.collection}_${field.name}_order`\n const currentFields = fieldsToAdd.get(relationshipCollection) || []\n // @ts-expect-error ref is untyped\n const prefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n fieldsToAdd.set(relationshipCollection, [\n ...currentFields,\n `_${field.collection}_${prefix}${field.name}_order`,\n ])\n }\n },\n fields: collection.fields,\n })\n })\n\n Array.from(fieldsToAdd.entries()).forEach(([collection, orderableFields]) => {\n addOrderableFieldsAndHook(collection, orderableFields)\n })\n\n if (fieldsToAdd.size > 0) {\n addOrderableEndpoint(config)\n }\n}\n\nexport const addOrderableFieldsAndHook = (\n collection: CollectionConfig,\n orderableFieldNames: string[],\n) => {\n // 1. Add field\n orderableFieldNames.forEach((orderableFieldName) => {\n const orderField: Field = {\n name: orderableFieldName,\n type: 'text',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n readOnly: true,\n },\n index: true,\n required: true,\n // override the schema to make order fields optional for payload.create()\n typescriptSchema: [\n () => ({\n type: 'string',\n required: false,\n }),\n ],\n unique: true,\n }\n\n collection.fields.unshift(orderField)\n })\n\n // 2. Add hook\n if (!collection.hooks) {\n collection.hooks = {}\n }\n if (!collection.hooks.beforeChange) {\n collection.hooks.beforeChange = []\n }\n\n const orderBeforeChangeHook: BeforeChangeHook = async ({ data, originalDoc, req }) => {\n for (const orderableFieldName of orderableFieldNames) {\n if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {\n console.log('do not enter')\n const lastDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n select: { [orderableFieldName]: true },\n sort: `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n exists: true,\n },\n },\n })\n\n const lastOrderValue = lastDoc.docs[0]?.[orderableFieldName] || null\n data[orderableFieldName] = generateKeyBetween(lastOrderValue, null)\n }\n }\n\n return data\n }\n\n collection.hooks.beforeChange.push(orderBeforeChangeHook)\n}\n\n/**\n * The body of the reorder endpoint.\n * @internal\n */\nexport type OrderableEndpointBody = {\n collectionSlug: string\n docsToMove: string[]\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: string\n }\n}\n\nexport const addOrderableEndpoint = (config: SanitizedConfig) => {\n // 3. Add endpoint\n const reorderHandler: PayloadHandler = async (req) => {\n const body = (await req.json?.()) as OrderableEndpointBody\n\n const { collectionSlug, docsToMove, newKeyWillBe, orderableFieldName, target } = body\n\n if (!Array.isArray(docsToMove) || docsToMove.length === 0) {\n return new Response(JSON.stringify({ error: 'docsToMove must be a non-empty array' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (\n typeof target !== 'object' ||\n typeof target.id === 'undefined' ||\n typeof target.key !== 'string'\n ) {\n return new Response(JSON.stringify({ error: 'target must be an object with id and key' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (newKeyWillBe !== 'greater' && newKeyWillBe !== 'less') {\n return new Response(JSON.stringify({ error: 'newKeyWillBe must be \"greater\" or \"less\"' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n const collection = config.collections.find((c) => c.slug === collectionSlug)\n if (!collection) {\n return new Response(JSON.stringify({ error: `Collection ${collectionSlug} not found` }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (typeof orderableFieldName !== 'string') {\n return new Response(JSON.stringify({ error: 'orderableFieldName must be a string' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n // Prevent reordering if user doesn't have editing permissions\n if (collection.access?.update) {\n await executeAccess(\n {\n // Currently only one doc can be moved at a time. We should review this if we want to allow\n // multiple docs to be moved at once in the future.\n id: docsToMove[0],\n data: {},\n req,\n },\n collection.access.update,\n )\n }\n\n const targetId = target.id\n let targetKey = target.key\n\n // If targetKey = pending, we need to find its current key.\n // This can only happen if the user reorders rows quickly with a slow connection.\n if (targetKey === 'pending') {\n const beforeDoc = await req.payload.findByID({\n id: targetId,\n collection: collection.slug,\n depth: 0,\n select: { [orderableFieldName]: true },\n })\n targetKey = beforeDoc?.[orderableFieldName] || null\n }\n\n // The reason the endpoint does not receive this docId as an argument is that there\n // are situations where the user may not see or know what the next or previous one is. For\n // example, access control restrictions, if docBefore is the last one on the page, etc.\n const adjacentDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: { [orderableFieldName]: true },\n sort: newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n [newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: targetKey,\n },\n },\n })\n const adjacentDocKey = adjacentDoc.docs?.[0]?.[orderableFieldName] || null\n\n // Currently N (= docsToMove.length) is always 1. Maybe in the future we will\n // allow dragging and reordering multiple documents at once via the UI.\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length)\n\n // Update each document with its new order value\n for (const [index, id] of docsToMove.entries()) {\n await req.payload.update({\n id,\n collection: collection.slug,\n data: {\n [orderableFieldName]: orderValues[index],\n },\n depth: 0,\n req,\n select: { id: true },\n })\n }\n\n return new Response(JSON.stringify({ orderValues, success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n const reorderEndpoint: Endpoint = {\n handler: reorderHandler,\n method: 'post',\n path: '/reorder',\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n config.endpoints.push(reorderEndpoint)\n}\n"],"names":["executeAccess","traverseFields","generateKeyBetween","generateNKeysBetween","setupOrderable","config","fieldsToAdd","Map","collections","forEach","collection","orderable","currentFields","get","set","defaultSort","callback","field","parentRef","ref","type","parentPrefix","prefix","name","Array","isArray","Error","relationshipCollection","find","c","slug","fields","from","entries","orderableFields","addOrderableFieldsAndHook","size","addOrderableEndpoint","orderableFieldNames","orderableFieldName","orderField","admin","disableBulkEdit","disabled","disableListColumn","disableListFilter","hidden","readOnly","index","required","typescriptSchema","unique","unshift","hooks","beforeChange","orderBeforeChangeHook","data","originalDoc","req","console","log","lastDoc","payload","depth","limit","pagination","select","sort","where","exists","lastOrderValue","docs","push","reorderHandler","body","json","collectionSlug","docsToMove","newKeyWillBe","target","length","Response","JSON","stringify","error","headers","status","id","key","access","update","targetId","targetKey","beforeDoc","findByID","adjacentDoc","adjacentDocKey","orderValues","success","reorderEndpoint","handler","method","path","endpoints"],"mappings":"AAIA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,2BAA0B;AAEnF;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAMC,cAAc,IAAIC;IAExBF,OAAOG,WAAW,CAACC,OAAO,CAAC,CAACC;QAC1B,IAAIA,WAAWC,SAAS,EAAE;YACxB,MAAMC,gBAAgBN,YAAYO,GAAG,CAACH,eAAe,EAAE;YACvDJ,YAAYQ,GAAG,CAACJ,YAAY;mBAAIE;gBAAe;aAAS;YACxDF,WAAWK,WAAW,GAAGL,WAAWK,WAAW,IAAI;QACrD;QAEAd,eAAe;YACbe,UAAU,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;gBAClC,IAAIF,MAAMG,IAAI,KAAK,WAAWH,MAAMG,IAAI,KAAK,UAAU;oBACrD,OAAO;gBACT;gBACA,IAAIH,MAAMG,IAAI,KAAK,WAAWH,MAAMG,IAAI,KAAK,OAAO;oBAClD,kCAAkC;oBAClC,MAAMC,eAAeH,WAAWI,SAAS,GAAGJ,UAAUI,MAAM,CAAC,CAAC,CAAC,GAAG;oBAClE,kCAAkC;oBAClCH,IAAIG,MAAM,GAAG,GAAGD,eAAeJ,MAAMM,IAAI,EAAE;gBAC7C;gBACA,IAAIN,MAAMG,IAAI,KAAK,UAAUH,MAAMN,SAAS,KAAK,MAAM;oBACrD,IAAIa,MAAMC,OAAO,CAACR,MAAMP,UAAU,GAAG;wBACnC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4B,MAAM,CAAC;gBACvBH;gBACA7E,YAAYA,WAAWoB,IAAI;gBAC3B0B,MAAM;oBACJ,CAACjB,mBAAmB,EAAE0D,WAAW,CAACjD,MAAM;gBAC1C;gBACAe,OAAO;gBACPL;gBACAQ,QAAQ;oBAAEqB,IAAI;gBAAK;YACrB;QACF;QAEA,OAAO,IAAIN,SAASC,KAAKC,SAAS,CAAC;YAAEc;YAAaC,SAAS;QAAK,IAAI;YAClEb,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,QAAQ;QACV;IACF;IAEA,MAAMa,kBAA4B;QAChCC,SAAS3B;QACT4B,QAAQ;QACRC,MAAM;IACR;IAEA,IAAI,CAACjG,OAAOkG,SAAS,EAAE;QACrBlG,OAAOkG,SAAS,GAAG,EAAE;IACvB;IACAlG,OAAOkG,SAAS,CAAC/B,IAAI,CAAC2B;AACxB,EAAC"}
1
+ {"version":3,"sources":["../../../src/config/orderable/index.ts"],"sourcesContent":["import type { BeforeChangeHook, CollectionConfig } from '../../collections/config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { Endpoint, PayloadHandler, SanitizedConfig } from '../types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { traverseFields } from '../../utilities/traverseFields.js'\nimport { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js'\n\n/**\n * This function creates:\n * - N fields per collection, named `_order` or `_<collection>_<joinField>_order`\n * - 1 hook per collection\n * - 1 endpoint per app\n *\n * Also, if collection.defaultSort or joinField.defaultSort is not set, it will be set to the orderable field.\n */\nexport const setupOrderable = (config: SanitizedConfig) => {\n const fieldsToAdd = new Map<CollectionConfig, string[]>()\n\n config.collections.forEach((collection) => {\n if (collection.orderable) {\n const currentFields = fieldsToAdd.get(collection) || []\n fieldsToAdd.set(collection, [...currentFields, '_order'])\n collection.defaultSort = collection.defaultSort ?? '_order'\n }\n\n traverseFields({\n callback: ({ field, parentRef, ref }) => {\n if (field.type === 'array' || field.type === 'blocks') {\n return false\n }\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}`\n }\n if (field.type === 'join' && field.orderable === true) {\n if (Array.isArray(field.collection)) {\n throw new Error('Orderable joins must target a single collection')\n }\n const relationshipCollection = config.collections.find((c) => c.slug === field.collection)\n if (!relationshipCollection) {\n return false\n }\n field.defaultSort = field.defaultSort ?? `_${field.collection}_${field.name}_order`\n const currentFields = fieldsToAdd.get(relationshipCollection) || []\n // @ts-expect-error ref is untyped\n const prefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n fieldsToAdd.set(relationshipCollection, [\n ...currentFields,\n `_${field.collection}_${prefix}${field.name}_order`,\n ])\n }\n },\n fields: collection.fields,\n })\n })\n\n Array.from(fieldsToAdd.entries()).forEach(([collection, orderableFields]) => {\n addOrderableFieldsAndHook(collection, orderableFields)\n })\n\n if (fieldsToAdd.size > 0) {\n addOrderableEndpoint(config)\n }\n}\n\nexport const addOrderableFieldsAndHook = (\n collection: CollectionConfig,\n orderableFieldNames: string[],\n) => {\n // 1. Add field\n orderableFieldNames.forEach((orderableFieldName) => {\n const orderField: Field = {\n name: orderableFieldName,\n type: 'text',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n readOnly: true,\n },\n index: true,\n required: true,\n // override the schema to make order fields optional for payload.create()\n typescriptSchema: [\n () => ({\n type: 'string',\n required: false,\n }),\n ],\n unique: true,\n }\n\n collection.fields.unshift(orderField)\n })\n\n // 2. Add hook\n if (!collection.hooks) {\n collection.hooks = {}\n }\n if (!collection.hooks.beforeChange) {\n collection.hooks.beforeChange = []\n }\n\n const orderBeforeChangeHook: BeforeChangeHook = async ({ data, originalDoc, req }) => {\n for (const orderableFieldName of orderableFieldNames) {\n if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {\n const lastDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n select: { [orderableFieldName]: true },\n sort: `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n exists: true,\n },\n },\n })\n\n const lastOrderValue = lastDoc.docs[0]?.[orderableFieldName] || null\n data[orderableFieldName] = generateKeyBetween(lastOrderValue, null)\n }\n }\n\n return data\n }\n\n collection.hooks.beforeChange.push(orderBeforeChangeHook)\n}\n\n/**\n * The body of the reorder endpoint.\n * @internal\n */\nexport type OrderableEndpointBody = {\n collectionSlug: string\n docsToMove: string[]\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: string\n }\n}\n\nexport const addOrderableEndpoint = (config: SanitizedConfig) => {\n // 3. Add endpoint\n const reorderHandler: PayloadHandler = async (req) => {\n const body = (await req.json?.()) as OrderableEndpointBody\n\n const { collectionSlug, docsToMove, newKeyWillBe, orderableFieldName, target } = body\n\n if (!Array.isArray(docsToMove) || docsToMove.length === 0) {\n return new Response(JSON.stringify({ error: 'docsToMove must be a non-empty array' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (\n typeof target !== 'object' ||\n typeof target.id === 'undefined' ||\n typeof target.key !== 'string'\n ) {\n return new Response(JSON.stringify({ error: 'target must be an object with id and key' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (newKeyWillBe !== 'greater' && newKeyWillBe !== 'less') {\n return new Response(JSON.stringify({ error: 'newKeyWillBe must be \"greater\" or \"less\"' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n const collection = config.collections.find((c) => c.slug === collectionSlug)\n if (!collection) {\n return new Response(JSON.stringify({ error: `Collection ${collectionSlug} not found` }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (typeof orderableFieldName !== 'string') {\n return new Response(JSON.stringify({ error: 'orderableFieldName must be a string' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n // Prevent reordering if user doesn't have editing permissions\n if (collection.access?.update) {\n await executeAccess(\n {\n // Currently only one doc can be moved at a time. We should review this if we want to allow\n // multiple docs to be moved at once in the future.\n id: docsToMove[0],\n data: {},\n req,\n },\n collection.access.update,\n )\n }\n\n const targetId = target.id\n let targetKey = target.key\n\n // If targetKey = pending, we need to find its current key.\n // This can only happen if the user reorders rows quickly with a slow connection.\n if (targetKey === 'pending') {\n const beforeDoc = await req.payload.findByID({\n id: targetId,\n collection: collection.slug,\n depth: 0,\n select: { [orderableFieldName]: true },\n })\n targetKey = beforeDoc?.[orderableFieldName] || null\n }\n\n // The reason the endpoint does not receive this docId as an argument is that there\n // are situations where the user may not see or know what the next or previous one is. For\n // example, access control restrictions, if docBefore is the last one on the page, etc.\n const adjacentDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: { [orderableFieldName]: true },\n sort: newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n [newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: targetKey,\n },\n },\n })\n const adjacentDocKey = adjacentDoc.docs?.[0]?.[orderableFieldName] || null\n\n // Currently N (= docsToMove.length) is always 1. Maybe in the future we will\n // allow dragging and reordering multiple documents at once via the UI.\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length)\n\n // Update each document with its new order value\n for (const [index, id] of docsToMove.entries()) {\n await req.payload.update({\n id,\n collection: collection.slug,\n data: {\n [orderableFieldName]: orderValues[index],\n },\n depth: 0,\n req,\n select: { id: true },\n })\n }\n\n return new Response(JSON.stringify({ orderValues, success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n const reorderEndpoint: Endpoint = {\n handler: reorderHandler,\n method: 'post',\n path: '/reorder',\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n config.endpoints.push(reorderEndpoint)\n}\n"],"names":["executeAccess","traverseFields","generateKeyBetween","generateNKeysBetween","setupOrderable","config","fieldsToAdd","Map","collections","forEach","collection","orderable","currentFields","get","set","defaultSort","callback","field","parentRef","ref","type","parentPrefix","prefix","name","Array","isArray","Error","relationshipCollection","find","c","slug","fields","from","entries","orderableFields","addOrderableFieldsAndHook","size","addOrderableEndpoint","orderableFieldNames","orderableFieldName","orderField","admin","disableBulkEdit","disabled","disableListColumn","disableListFilter","hidden","readOnly","index","required","typescriptSchema","unique","unshift","hooks","beforeChange","orderBeforeChangeHook","data","originalDoc","req","lastDoc","payload","depth","limit","pagination","select","sort","where","exists","lastOrderValue","docs","push","reorderHandler","body","json","collectionSlug","docsToMove","newKeyWillBe","target","length","Response","JSON","stringify","error","headers","status","id","key","access","update","targetId","targetKey","beforeDoc","findByID","adjacentDoc","adjacentDocKey","orderValues","success","reorderEndpoint","handler","method","path","endpoints"],"mappings":"AAIA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,2BAA0B;AAEnF;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAMC,cAAc,IAAIC;IAExBF,OAAOG,WAAW,CAACC,OAAO,CAAC,CAACC;QAC1B,IAAIA,WAAWC,SAAS,EAAE;YACxB,MAAMC,gBAAgBN,YAAYO,GAAG,CAACH,eAAe,EAAE;YACvDJ,YAAYQ,GAAG,CAACJ,YAAY;mBAAIE;gBAAe;aAAS;YACxDF,WAAWK,WAAW,GAAGL,WAAWK,WAAW,IAAI;QACrD;QAEAd,eAAe;YACbe,UAAU,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAEC,GAAG,EAAE;gBAClC,IAAIF,MAAMG,IAAI,KAAK,WAAWH,MAAMG,IAAI,KAAK,UAAU;oBACrD,OAAO;gBACT;gBACA,IAAIH,MAAMG,IAAI,KAAK,W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AE,EAAE,CAAC9B,mBAAmB,IAAI;QAEtE,6EAA6E;QAC7E,uEAAuE;QACvE,MAAMwD,cACJnB,iBAAiB,YACbzE,qBAAqBuF,WAAWI,gBAAgBnB,WAAWG,MAAM,IACjE3E,qBAAqB2F,gBAAgBJ,WAAWf,WAAWG,MAAM;QAEvE,gDAAgD;QAChD,KAAK,MAAM,CAAC9B,OAAOqC,GAAG,IAAIV,WAAW1C,OAAO,GAAI;YAC9C,MAAMyB,IAAIE,OAAO,CAAC4B,MAAM,CAAC;gBACvBH;gBACA3E,YAAYA,WAAWoB,IAAI;gBAC3B0B,MAAM;oBACJ,CAACjB,mBAAmB,EAAEwD,WAAW,CAAC/C,MAAM;gBAC1C;gBACAa,OAAO;gBACPH;gBACAM,QAAQ;oBAAEqB,IAAI;gBAAK;YACrB;QACF;QAEA,OAAO,IAAIN,SAASC,KAAKC,SAAS,CAAC;YAAEc;YAAaC,SAAS;QAAK,IAAI;YAClEb,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,QAAQ;QACV;IACF;IAEA,MAAMa,kBAA4B;QAChCC,SAAS3B;QACT4B,QAAQ;QACRC,MAAM;IACR;IAEA,IAAI,CAAC/F,OAAOgG,SAAS,EAAE;QACrBhG,OAAOgG,SAAS,GAAG,EAAE;IACvB;IACAhG,OAAOgG,SAAS,CAAC/B,IAAI,CAAC2B;AACxB,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.34.0",
3
+ "version": "3.35.0-internal.b3d367c",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -99,7 +99,7 @@
99
99
  "tsx": "4.19.2",
100
100
  "uuid": "10.0.0",
101
101
  "ws": "^8.16.0",
102
- "@payloadcms/translations": "3.34.0"
102
+ "@payloadcms/translations": "3.35.0-internal.b3d367c"
103
103
  },
104
104
  "devDependencies": {
105
105
  "@hyrious/esbuild-plugin-commonjs": "^0.2.4",