{"version":3,"sources":["../../../../src/fields/baseFields/slug/index.ts"],"sourcesContent":["import type { TextFieldClientProps } from '../../../admin/types.js'\nimport type { TypeWithID } from '../../../collections/config/types.js'\nimport type { FieldAdmin, RowField, TextField } from '../../../fields/config/types.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\nimport { generateSlug } from './generateSlug.js'\n\nexport type Slugify = (args: {\n data: T\n req: PayloadRequest\n valueToSlugify?: any\n}) => Promise | string | undefined\n\nexport type SlugFieldArgs = {\n /**\n * Override for the `generateSlug` checkbox field name.\n * @default 'generateSlug'\n */\n checkboxName?: string\n /**\n * @deprecated use `useAsSlug` instead.\n */\n fieldToUse?: string\n /**\n * Enable localization for the slug field.\n */\n localized?: TextField['localized']\n /**\n * Override for the `slug` field name.\n * @default 'slug'\n */\n name?: string\n /**\n * A function used to override the slug field(s) at a granular level.\n * Passes the row field to you to manipulate beyond the exposed options.\n * @example\n * ```ts\n * slugField({\n * overrides: (field) => {\n * field.fields[1].label = 'Custom Slug Label'\n * return field\n * }\n * })\n * ```\n */\n overrides?: (field: RowField) => RowField\n position?: FieldAdmin['position']\n /**\n * Whether or not the `slug` field is required.\n * @default true\n */\n required?: TextField['required']\n /**\n * Provide your own slugify function to override the default.\n */\n slugify?: Slugify\n /**\n * The name of the top-level field to generate the slug from, when applicable.\n * @default 'title'\n */\n useAsSlug?: string\n}\n\nexport type SlugField = (args?: SlugFieldArgs) => RowField\n\nexport type SlugFieldClientPropsOnly = Pick\n/**\n * These are the props that the `SlugField` client component accepts.\n * The `SlugField` server component is responsible for passing down the `slugify` function.\n */\nexport type SlugFieldClientProps = SlugFieldClientPropsOnly & TextFieldClientProps\n\n/**\n * A slug is a unique, indexed, URL-friendly string that identifies a particular document, often used to construct the URL of a webpage.\n * The `slug` field auto-generates its value based on another field, e.g. \"My Title\" → \"my-title\".\n *\n * The slug should continue to be generated through:\n * 1. The `create` operation, unless the user has modified the slug manually\n * 2. The `update` operation, if:\n * a. Autosave is _not_ enabled and there is no slug\n * b. Autosave _is_ enabled, the doc is unpublished, and the user has not modified the slug manually\n *\n * The slug should stabilize after all above criteria have been met, because the URL is typically derived from the slug.\n * This is to protect modifying potentially live URLs, breaking links, etc. without explicit intent.\n *\n * @experimental This field is experimental and may change or be removed in the future. Use at your own risk.\n */\nexport const slugField: SlugField = ({\n name: slugFieldName = 'slug',\n checkboxName = 'generateSlug',\n fieldToUse,\n localized,\n overrides,\n position = 'sidebar',\n required = true,\n slugify,\n useAsSlug: useAsSlugFromArgs = 'title',\n} = {}) => {\n const useAsSlug = fieldToUse || useAsSlugFromArgs\n\n const baseField: RowField = {\n type: 'row',\n admin: {\n position,\n },\n fields: [\n {\n name: checkboxName,\n type: 'checkbox',\n admin: {\n description:\n 'When enabled, the slug will auto-generate from the title field on save and autosave.',\n disableBulkEdit: true,\n disableGroupBy: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n },\n defaultValue: true,\n hooks: {\n beforeChange: [generateSlug({ slugFieldName, slugify, useAsSlug })],\n },\n localized,\n },\n {\n name: slugFieldName,\n type: 'text',\n admin: {\n components: {\n Field: {\n clientProps: {\n useAsSlug,\n } satisfies SlugFieldClientPropsOnly,\n path: '@payloadcms/next/client#SlugField',\n },\n },\n width: '100%',\n },\n custom: {\n /**\n * This is needed so we can access it from the `slugifyHandler` server function.\n */\n slugify,\n },\n index: true,\n localized,\n required,\n unique: true,\n },\n ],\n }\n\n if (typeof overrides === 'function') {\n return overrides(baseField)\n }\n\n return baseField\n}\n"],"names":["generateSlug","slugField","name","slugFieldName","checkboxName","fieldToUse","localized","overrides","position","required","slugify","useAsSlug","useAsSlugFromArgs","baseField","type","admin","fields","description","disableBulkEdit","disableGroupBy","disableListColumn","disableListFilter","hidden","defaultValue","hooks","beforeChange","components","Field","clientProps","path","width","custom","index","unique"],"mappings":"AAKA,SAASA,YAAY,QAAQ,oBAAmB;AAmEhD;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,YAAuB,CAAC,EACnCC,MAAMC,gBAAgB,MAAM,EAC5BC,eAAe,cAAc,EAC7BC,UAAU,EACVC,SAAS,EACTC,SAAS,EACTC,WAAW,SAAS,EACpBC,WAAW,IAAI,EACfC,OAAO,EACPC,WAAWC,oBAAoB,OAAO,EACvC,GAAG,CAAC,CAAC;IACJ,MAAMD,YAAYN,cAAcO;IAEhC,MAAMC,YAAsB;QAC1BC,MAAM;QACNC,OAAO;YACLP;QACF;QACAQ,QAAQ;YACN;gBACEd,MAAME;gBACNU,MAAM;gBACNC,OAAO;oBACLE,aACE;oBACFC,iBAAiB;oBACjBC,gBAAgB;oBAChBC,mBAAmB;oBACnBC,mBAAmB;oBACnBC,QAAQ;gBACV;gBACAC,cAAc;gBACdC,OAAO;oBACLC,cAAc;wBAACzB,aAAa;4BAAEG;4BAAeO;4BAASC;wBAAU;qBAAG;gBACrE;gBACAL;YACF;YACA;gBACEJ,MAAMC;gBACNW,MAAM;gBACNC,OAAO;oBACLW,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXjB;4BACF;4BACAkB,MAAM;wBACR;oBACF;oBACAC,OAAO;gBACT;gBACAC,QAAQ;oBACN;;WAEC,GACDrB;gBACF;gBACAsB,OAAO;gBACP1B;gBACAG;gBACAwB,QAAQ;YACV;SACD;IACH;IAEA,IAAI,OAAO1B,cAAc,YAAY;QACnC,OAAOA,UAAUM;IACnB;IAEA,OAAOA;AACT,EAAC"}