@payloadcms/ui 3.0.0-beta.46 → 3.0.0-beta.48

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.
Files changed (116) hide show
  1. package/dist/elements/DocumentControls/index.d.ts.map +1 -1
  2. package/dist/elements/DocumentControls/index.js +28 -21
  3. package/dist/elements/DocumentControls/index.js.map +1 -1
  4. package/dist/elements/DocumentDrawer/DrawerContent.js +1 -1
  5. package/dist/elements/DocumentDrawer/DrawerContent.js.map +1 -1
  6. package/dist/elements/DuplicateDocument/index.d.ts.map +1 -1
  7. package/dist/elements/DuplicateDocument/index.js +2 -2
  8. package/dist/elements/DuplicateDocument/index.js.map +1 -1
  9. package/dist/elements/ListDrawer/DrawerContent.d.ts.map +1 -1
  10. package/dist/elements/ListDrawer/DrawerContent.js +1 -1
  11. package/dist/elements/ListDrawer/DrawerContent.js.map +1 -1
  12. package/dist/elements/ReactSelect/index.d.ts +1 -1
  13. package/dist/elements/ReactSelect/index.d.ts.map +1 -1
  14. package/dist/elements/ReactSelect/index.js.map +1 -1
  15. package/dist/elements/ReactSelect/types.d.ts +4 -4
  16. package/dist/elements/ReactSelect/types.d.ts.map +1 -1
  17. package/dist/elements/ReactSelect/types.js.map +1 -1
  18. package/dist/elements/SortComplex/index.d.ts.map +1 -1
  19. package/dist/elements/SortComplex/index.js.map +1 -1
  20. package/dist/elements/TableColumns/index.d.ts +0 -2
  21. package/dist/elements/TableColumns/index.d.ts.map +1 -1
  22. package/dist/elements/TableColumns/index.js +83 -85
  23. package/dist/elements/TableColumns/index.js.map +1 -1
  24. package/dist/elements/Thumbnail/index.d.ts.map +1 -1
  25. package/dist/elements/Thumbnail/index.js +2 -2
  26. package/dist/elements/Thumbnail/index.js.map +1 -1
  27. package/dist/elements/Upload/index.d.ts.map +1 -1
  28. package/dist/elements/Upload/index.js +4 -9
  29. package/dist/elements/Upload/index.js.map +1 -1
  30. package/dist/elements/Upload/index.scss +0 -11
  31. package/dist/elements/WhereBuilder/Condition/Relationship/index.js +3 -3
  32. package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
  33. package/dist/elements/WhereBuilder/Condition/index.d.ts +2 -1
  34. package/dist/elements/WhereBuilder/Condition/index.d.ts.map +1 -1
  35. package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
  36. package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
  37. package/dist/elements/WhereBuilder/index.js.map +1 -1
  38. package/dist/fields/Array/index.js +2 -2
  39. package/dist/fields/Array/index.js.map +1 -1
  40. package/dist/fields/Blocks/index.js +1 -1
  41. package/dist/fields/Blocks/index.js.map +1 -1
  42. package/dist/fields/Checkbox/index.js +1 -1
  43. package/dist/fields/Checkbox/index.js.map +1 -1
  44. package/dist/fields/Code/index.js +1 -1
  45. package/dist/fields/Code/index.js.map +1 -1
  46. package/dist/fields/Collapsible/index.js +1 -1
  47. package/dist/fields/Collapsible/index.js.map +1 -1
  48. package/dist/fields/DateTime/index.d.ts +1 -1
  49. package/dist/fields/DateTime/index.d.ts.map +1 -1
  50. package/dist/fields/DateTime/index.js +1 -1
  51. package/dist/fields/DateTime/index.js.map +1 -1
  52. package/dist/fields/Email/index.d.ts.map +1 -1
  53. package/dist/fields/Email/index.js +1 -1
  54. package/dist/fields/Email/index.js.map +1 -1
  55. package/dist/fields/JSON/index.d.ts +1 -1
  56. package/dist/fields/JSON/index.d.ts.map +1 -1
  57. package/dist/fields/JSON/index.js +1 -1
  58. package/dist/fields/JSON/index.js.map +1 -1
  59. package/dist/fields/Number/index.js +1 -1
  60. package/dist/fields/Number/index.js.map +1 -1
  61. package/dist/fields/Point/index.js +1 -1
  62. package/dist/fields/Point/index.js.map +1 -1
  63. package/dist/fields/RadioGroup/index.js +1 -1
  64. package/dist/fields/RadioGroup/index.js.map +1 -1
  65. package/dist/fields/Relationship/index.d.ts.map +1 -1
  66. package/dist/fields/Relationship/index.js +18 -10
  67. package/dist/fields/Relationship/index.js.map +1 -1
  68. package/dist/fields/Relationship/types.d.ts +1 -2
  69. package/dist/fields/Relationship/types.d.ts.map +1 -1
  70. package/dist/fields/Relationship/types.js.map +1 -1
  71. package/dist/fields/Select/Input.d.ts +3 -1
  72. package/dist/fields/Select/Input.d.ts.map +1 -1
  73. package/dist/fields/Select/Input.js.map +1 -1
  74. package/dist/fields/Select/index.d.ts +1 -1
  75. package/dist/fields/Select/index.d.ts.map +1 -1
  76. package/dist/fields/Select/index.js +4 -6
  77. package/dist/fields/Select/index.js.map +1 -1
  78. package/dist/fields/Tabs/index.js +1 -1
  79. package/dist/fields/Tabs/index.js.map +1 -1
  80. package/dist/fields/Text/Input.d.ts.map +1 -1
  81. package/dist/fields/Text/Input.js.map +1 -1
  82. package/dist/fields/Text/index.js +1 -1
  83. package/dist/fields/Text/index.js.map +1 -1
  84. package/dist/fields/Text/types.d.ts +9 -4
  85. package/dist/fields/Text/types.d.ts.map +1 -1
  86. package/dist/fields/Text/types.js.map +1 -1
  87. package/dist/fields/Textarea/index.js +1 -1
  88. package/dist/fields/Textarea/index.js.map +1 -1
  89. package/dist/fields/Upload/index.js +1 -1
  90. package/dist/fields/Upload/index.js.map +1 -1
  91. package/dist/forms/FieldError/index.js +1 -1
  92. package/dist/forms/FieldError/index.js.map +1 -1
  93. package/dist/forms/FieldPropsProvider/index.js +4 -4
  94. package/dist/forms/FieldPropsProvider/index.js.map +1 -1
  95. package/dist/forms/Form/index.js +1 -1
  96. package/dist/forms/Form/index.js.map +1 -1
  97. package/dist/forms/Form/types.d.ts +2 -3
  98. package/dist/forms/Form/types.d.ts.map +1 -1
  99. package/dist/forms/Form/types.js.map +1 -1
  100. package/dist/forms/withCondition/index.js +1 -1
  101. package/dist/forms/withCondition/index.js.map +1 -1
  102. package/dist/graphics/Account/index.d.ts +0 -1
  103. package/dist/graphics/Account/index.d.ts.map +1 -1
  104. package/dist/graphics/Account/index.js +5 -1
  105. package/dist/graphics/Account/index.js.map +1 -1
  106. package/dist/providers/ComponentMap/buildComponentMap/fields.d.ts.map +1 -1
  107. package/dist/providers/ComponentMap/buildComponentMap/fields.js +2 -1
  108. package/dist/providers/ComponentMap/buildComponentMap/fields.js.map +1 -1
  109. package/dist/providers/FormQueryParams/index.d.ts.map +1 -1
  110. package/dist/providers/FormQueryParams/index.js +8 -6
  111. package/dist/providers/FormQueryParams/index.js.map +1 -1
  112. package/package.json +4 -4
  113. package/dist/elements/TableColumns/columnReducer.d.ts +0 -24
  114. package/dist/elements/TableColumns/columnReducer.d.ts.map +0 -1
  115. package/dist/elements/TableColumns/columnReducer.js +0 -59
  116. package/dist/elements/TableColumns/columnReducer.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/elements/WhereBuilder/Condition/Relationship/index.tsx"],"sourcesContent":["'use client'\n/* eslint-disable @typescript-eslint/no-floating-promises */\nimport type { PaginatedDocs } from 'payload/database'\nimport type { Where } from 'payload/types'\n\nimport QueryString from 'qs'\nimport React, { useCallback, useEffect, useReducer, useState } from 'react'\n\nimport type { Option } from '../../../ReactSelect/types.js'\nimport type { Props, ValueWithRelation } from './types.js'\n\nimport { useDebounce } from '../../../../hooks/useDebounce.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { ReactSelect } from '../../../ReactSelect/index.js'\nimport './index.scss'\nimport optionsReducer from './optionsReducer.js'\n\nconst baseClass = 'condition-value-relationship'\n\nconst maxResultsPerRequest = 10\n\nexport const RelationshipField: React.FC<Props> = (props) => {\n const { admin: { isSortable } = {}, disabled, hasMany, onChange, relationTo, value } = props\n\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const hasMultipleRelations = Array.isArray(relationTo)\n const [options, dispatchOptions] = useReducer(optionsReducer, [])\n const [search, setSearch] = useState('')\n const [errorLoading, setErrorLoading] = useState('')\n const [hasLoadedFirstOptions, setHasLoadedFirstOptions] = useState(false)\n const debouncedSearch = useDebounce(search, 300)\n const { i18n, t } = useTranslation()\n const relationSlugs = hasMultipleRelations ? relationTo : [relationTo]\n const initialRelationMap = () => {\n const map: Map<string, number> = new Map()\n relationSlugs.forEach((relation) => {\n map.set(relation, 1)\n })\n return map\n }\n const nextPageByRelationshipRef = React.useRef<Map<string, number>>(initialRelationMap())\n const partiallyLoadedRelationshipSlugs = React.useRef<string[]>(relationSlugs)\n\n const addOptions = useCallback(\n (data, relation) => {\n const collection = collections.find((coll) => coll.slug === relation)\n dispatchOptions({ type: 'ADD', collection, data, hasMultipleRelations, i18n, relation })\n },\n [collections, hasMultipleRelations, i18n],\n )\n\n const loadRelationOptions = React.useCallback(\n async ({\n abortController,\n relationSlug,\n }: {\n abortController: AbortController\n relationSlug: string\n }) => {\n const collection = collections.find((coll) => coll.slug === relationSlug)\n const fieldToSearch = collection?.admin?.useAsTitle || 'id'\n const pageIndex = nextPageByRelationshipRef.current.get(relationSlug)\n\n if (partiallyLoadedRelationshipSlugs.current.includes(relationSlug)) {\n const query: {\n depth?: number\n limit?: number\n page?: number\n where: Where\n } = {\n depth: 0,\n limit: maxResultsPerRequest,\n page: pageIndex,\n where: {\n and: [],\n },\n }\n\n if (debouncedSearch) {\n query.where.and.push({\n [fieldToSearch]: {\n like: debouncedSearch,\n },\n })\n }\n\n try {\n const response = await fetch(\n `${serverURL}${api}/${relationSlug}${QueryString.stringify(query, { addQueryPrefix: true })}`,\n {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n signal: abortController.signal,\n },\n )\n\n if (response.ok) {\n const data: PaginatedDocs = await response.json()\n if (data.docs.length > 0) {\n addOptions(data, relationSlug)\n\n if (!debouncedSearch) {\n if (data.nextPage) {\n nextPageByRelationshipRef.current.set(relationSlug, data.nextPage)\n } else {\n partiallyLoadedRelationshipSlugs.current =\n partiallyLoadedRelationshipSlugs.current.filter(\n (partiallyLoadedRelation) => partiallyLoadedRelation !== relationSlug,\n )\n }\n }\n }\n } else {\n setErrorLoading(t('error:unspecific'))\n }\n } catch (e) {\n if (!abortController.signal.aborted) {\n console.error(e)\n }\n }\n }\n\n setHasLoadedFirstOptions(true)\n },\n [addOptions, api, collections, debouncedSearch, i18n.language, serverURL, t],\n )\n\n const loadMoreOptions = React.useCallback(() => {\n if (partiallyLoadedRelationshipSlugs.current.length > 0) {\n const abortController = new AbortController()\n loadRelationOptions({\n abortController,\n relationSlug: partiallyLoadedRelationshipSlugs.current[0],\n })\n }\n }, [loadRelationOptions])\n\n const findOptionsByValue = useCallback((): Option | Option[] => {\n if (value) {\n if (hasMany) {\n if (Array.isArray(value)) {\n return value.map((val) => {\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n options.forEach((opt) => {\n if (opt.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value === val.value) {\n matchedOption = subOpt\n return true\n }\n\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value === val)\n })\n }\n\n return undefined\n }\n\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n const valueWithRelation = value as ValueWithRelation\n\n options.forEach((opt) => {\n if (opt?.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value === valueWithRelation.value) {\n matchedOption = subOpt\n return true\n }\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value === value)\n }\n\n return undefined\n }, [hasMany, hasMultipleRelations, value, options])\n\n const handleInputChange = useCallback(\n (newSearch) => {\n if (search !== newSearch) {\n setSearch(newSearch)\n }\n },\n [search],\n )\n\n const addOptionByID = useCallback(\n async (id, relation) => {\n if (!errorLoading && id !== 'null' && id && relation) {\n const response = await fetch(`${serverURL}${api}/${relation}/${id}?depth=0`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n\n if (response.ok) {\n const data = await response.json()\n addOptions({ docs: [data] }, relation)\n } else {\n // eslint-disable-next-line no-console\n console.error(t('error:loadingDocument', { id }))\n }\n }\n },\n [i18n, addOptions, api, errorLoading, serverURL, t],\n )\n\n /**\n * 1. Trigger initial relationship options fetch\n * 2. When search changes, loadRelationOptions will\n * fire off again\n */\n useEffect(() => {\n const relations = Array.isArray(relationTo) ? relationTo : [relationTo]\n const abortControllers: AbortController[] = []\n relations.forEach((relation) => {\n const abortController = new AbortController()\n loadRelationOptions({\n abortController,\n relationSlug: relation,\n })\n abortControllers.push(abortController)\n })\n\n return () => {\n abortControllers.forEach((controller) => {\n if (controller.signal) controller.abort()\n })\n }\n }, [i18n, loadRelationOptions, relationTo])\n\n /**\n * Load any options that were not returned\n * in the first 10 of each relation fetch\n */\n useEffect(() => {\n if (value && hasLoadedFirstOptions) {\n if (hasMany) {\n const matchedOptions = findOptionsByValue()\n\n ;((matchedOptions as Option[]) || []).forEach((option, i) => {\n if (!option) {\n if (hasMultipleRelations) {\n addOptionByID(value[i].value, value[i].relationTo)\n } else {\n addOptionByID(value[i], relationTo)\n }\n }\n })\n } else {\n const matchedOption = findOptionsByValue()\n\n if (!matchedOption) {\n if (hasMultipleRelations) {\n const valueWithRelation = value as ValueWithRelation\n addOptionByID(valueWithRelation.value, valueWithRelation.relationTo)\n } else {\n addOptionByID(value, relationTo)\n }\n }\n }\n }\n }, [\n addOptionByID,\n findOptionsByValue,\n hasMany,\n hasMultipleRelations,\n relationTo,\n value,\n hasLoadedFirstOptions,\n ])\n\n const classes = ['field-type', baseClass, errorLoading && 'error-loading']\n .filter(Boolean)\n .join(' ')\n\n const valueToRender = (findOptionsByValue() || value) as Option\n\n return (\n <div className={classes}>\n {!errorLoading && (\n <ReactSelect\n disabled={disabled}\n isMulti={hasMany}\n isSortable={isSortable}\n onChange={(selected) => {\n if (!selected) {\n onChange(null)\n return\n }\n if (hasMany) {\n onChange(\n selected\n ? selected.map((option) => {\n if (hasMultipleRelations) {\n return {\n relationTo: option?.relationTo,\n value: option?.value,\n }\n }\n\n return option?.value\n })\n : null,\n )\n } else if (hasMultipleRelations) {\n onChange({\n relationTo: selected?.relationTo,\n value: selected?.value,\n })\n } else {\n onChange(selected?.value)\n }\n }}\n onInputChange={handleInputChange}\n onMenuScrollToBottom={loadMoreOptions}\n options={options}\n placeholder={t('general:selectValue')}\n value={valueToRender}\n />\n )}\n {errorLoading && <div className={`${baseClass}__error-loading`}>{errorLoading}</div>}\n </div>\n )\n}\n"],"names":["QueryString","React","useCallback","useEffect","useReducer","useState","useDebounce","useConfig","useTranslation","ReactSelect","optionsReducer","baseClass","maxResultsPerRequest","RelationshipField","props","admin","isSortable","disabled","hasMany","onChange","relationTo","value","collections","routes","api","serverURL","hasMultipleRelations","Array","isArray","options","dispatchOptions","search","setSearch","errorLoading","setErrorLoading","hasLoadedFirstOptions","setHasLoadedFirstOptions","debouncedSearch","i18n","t","relationSlugs","initialRelationMap","map","Map","forEach","relation","set","nextPageByRelationshipRef","useRef","partiallyLoadedRelationshipSlugs","addOptions","data","collection","find","coll","slug","type","loadRelationOptions","abortController","relationSlug","fieldToSearch","useAsTitle","pageIndex","current","get","includes","query","depth","limit","page","where","and","push","like","response","fetch","stringify","addQueryPrefix","credentials","headers","language","signal","ok","json","docs","length","nextPage","filter","partiallyLoadedRelation","e","aborted","console","error","loadMoreOptions","AbortController","findOptionsByValue","val","matchedOption","opt","some","subOpt","undefined","valueWithRelation","handleInputChange","newSearch","addOptionByID","id","relations","abortControllers","controller","abort","matchedOptions","option","i","classes","Boolean","join","valueToRender","div","className","isMulti","selected","onInputChange","onMenuScrollToBottom","placeholder"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC4B,SACPC,IAAI,CAAC;IAER,MAAMC,gBAAiBtB,wBAAwB1E;IAE/C,qBACE,MAACiG;QAAIC,WAAWL;;YACb,CAACjF,8BACA,KAACxB;gBACCQ,UAAUA;gBACVuG,SAAStG;gBACTF,YAAYA;gBACZG,UAAU,CAACsG;oBACT,IAAI,CAACA,UAAU;wBACbtG,SAAS;wBACT;oBACF;oBACA,IAAID,SAAS;wBACXC,SACEsG,WACIA,SAAS/E,GAAG,CAAC,CAACsE;4BACZ,IAAItF,sBAAsB;gCACxB,OAAO;oCACLN,YAAY4F,QAAQ5F;oCACpBC,OAAO2F,QAAQ3F;gCACjB;4BACF;4BAEA,OAAO2F,QAAQ3F;wBACjB,KACA;oBAER,OAAO,IAAIK,sBAAsB;wBAC/BP,SAAS;4BACPC,YAAYqG,UAAUrG;4BACtBC,OAAOoG,UAAUpG;wBACnB;oBACF,OAAO;wBACLF,SAASsG,UAAUpG;oBACrB;gBACF;gBACAqG,eAAenB;gBACfoB,sBAAsB9B;gBACtBhE,SAASA;gBACT+F,aAAarF,EAAE;gBACflB,OAAOgG;;YAGVpF,8BAAgB,KAACqF;gBAAIC,WAAW,CAAC,EAAE5G,UAAU,eAAe,CAAC;0BAAGsB;;;;AAGvE,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/elements/WhereBuilder/Condition/Relationship/index.tsx"],"sourcesContent":["'use client'\n/* eslint-disable @typescript-eslint/no-floating-promises */\nimport type { PaginatedDocs } from 'payload/database'\nimport type { Where } from 'payload/types'\n\nimport QueryString from 'qs'\nimport React, { useCallback, useEffect, useReducer, useState } from 'react'\n\nimport type { Option } from '../../../ReactSelect/types.js'\nimport type { Props, ValueWithRelation } from './types.js'\n\nimport { useDebounce } from '../../../../hooks/useDebounce.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { ReactSelect } from '../../../ReactSelect/index.js'\nimport './index.scss'\nimport optionsReducer from './optionsReducer.js'\n\nconst baseClass = 'condition-value-relationship'\n\nconst maxResultsPerRequest = 10\n\nexport const RelationshipField: React.FC<Props> = (props) => {\n const { admin: { isSortable } = {}, disabled, hasMany, onChange, relationTo, value } = props\n\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const hasMultipleRelations = Array.isArray(relationTo)\n const [options, dispatchOptions] = useReducer(optionsReducer, [])\n const [search, setSearch] = useState('')\n const [errorLoading, setErrorLoading] = useState('')\n const [hasLoadedFirstOptions, setHasLoadedFirstOptions] = useState(false)\n const debouncedSearch = useDebounce(search, 300)\n const { i18n, t } = useTranslation()\n const relationSlugs = hasMultipleRelations ? relationTo : [relationTo]\n const initialRelationMap = () => {\n const map: Map<string, number> = new Map()\n relationSlugs.forEach((relation) => {\n map.set(relation, 1)\n })\n return map\n }\n const nextPageByRelationshipRef = React.useRef<Map<string, number>>(initialRelationMap())\n const partiallyLoadedRelationshipSlugs = React.useRef<string[]>(relationSlugs)\n\n const addOptions = useCallback(\n (data, relation) => {\n const collection = collections.find((coll) => coll.slug === relation)\n dispatchOptions({ type: 'ADD', collection, data, hasMultipleRelations, i18n, relation })\n },\n [collections, hasMultipleRelations, i18n],\n )\n\n const loadRelationOptions = React.useCallback(\n async ({\n abortController,\n relationSlug,\n }: {\n abortController: AbortController\n relationSlug: string\n }) => {\n const collection = collections.find((coll) => coll.slug === relationSlug)\n const fieldToSearch = collection?.admin?.useAsTitle || 'id'\n const pageIndex = nextPageByRelationshipRef.current.get(relationSlug)\n\n if (partiallyLoadedRelationshipSlugs.current.includes(relationSlug)) {\n const query: {\n depth?: number\n limit?: number\n page?: number\n where: Where\n } = {\n depth: 0,\n limit: maxResultsPerRequest,\n page: pageIndex,\n where: {\n and: [],\n },\n }\n\n if (debouncedSearch) {\n query.where.and.push({\n [fieldToSearch]: {\n like: debouncedSearch,\n },\n })\n }\n\n try {\n const response = await fetch(\n `${serverURL}${api}/${relationSlug}${QueryString.stringify(query, { addQueryPrefix: true })}`,\n {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n signal: abortController.signal,\n },\n )\n\n if (response.ok) {\n const data: PaginatedDocs = await response.json()\n if (data.docs.length > 0) {\n addOptions(data, relationSlug)\n\n if (!debouncedSearch) {\n if (data.nextPage) {\n nextPageByRelationshipRef.current.set(relationSlug, data.nextPage)\n } else {\n partiallyLoadedRelationshipSlugs.current =\n partiallyLoadedRelationshipSlugs.current.filter(\n (partiallyLoadedRelation) => partiallyLoadedRelation !== relationSlug,\n )\n }\n }\n }\n } else {\n setErrorLoading(t('error:unspecific'))\n }\n } catch (e) {\n if (!abortController.signal.aborted) {\n console.error(e)\n }\n }\n }\n\n setHasLoadedFirstOptions(true)\n },\n [addOptions, api, collections, debouncedSearch, i18n.language, serverURL, t],\n )\n\n const loadMoreOptions = React.useCallback(() => {\n if (partiallyLoadedRelationshipSlugs.current.length > 0) {\n const abortController = new AbortController()\n loadRelationOptions({\n abortController,\n relationSlug: partiallyLoadedRelationshipSlugs.current[0],\n })\n }\n }, [loadRelationOptions])\n\n const findOptionsByValue = useCallback((): Option | Option[] => {\n if (value) {\n if (hasMany) {\n if (Array.isArray(value)) {\n return value.map((val) => {\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n options.forEach((opt) => {\n if (opt.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value === val.value) {\n matchedOption = subOpt\n return true\n }\n\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value === val)\n })\n }\n\n return undefined\n }\n\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n const valueWithRelation = value as ValueWithRelation\n\n options.forEach((opt) => {\n if (opt?.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value === valueWithRelation.value) {\n matchedOption = subOpt\n return true\n }\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value === value)\n }\n\n return undefined\n }, [hasMany, hasMultipleRelations, value, options])\n\n const handleInputChange = useCallback(\n (newSearch) => {\n if (search !== newSearch) {\n setSearch(newSearch)\n }\n },\n [search],\n )\n\n const addOptionByID = useCallback(\n async (id, relation) => {\n if (!errorLoading && id !== 'null' && id && relation) {\n const response = await fetch(`${serverURL}${api}/${relation}/${id}?depth=0`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n\n if (response.ok) {\n const data = await response.json()\n addOptions({ docs: [data] }, relation)\n } else {\n // eslint-disable-next-line no-console\n console.error(t('error:loadingDocument', { id }))\n }\n }\n },\n [i18n, addOptions, api, errorLoading, serverURL, t],\n )\n\n /**\n * 1. Trigger initial relationship options fetch\n * 2. When search changes, loadRelationOptions will\n * fire off again\n */\n useEffect(() => {\n const relations = Array.isArray(relationTo) ? relationTo : [relationTo]\n const abortControllers: AbortController[] = []\n relations.forEach((relation) => {\n const abortController = new AbortController()\n loadRelationOptions({\n abortController,\n relationSlug: relation,\n })\n abortControllers.push(abortController)\n })\n\n return () => {\n abortControllers.forEach((controller) => {\n if (controller.signal) controller.abort()\n })\n }\n }, [i18n, loadRelationOptions, relationTo])\n\n /**\n * Load any options that were not returned\n * in the first 10 of each relation fetch\n */\n useEffect(() => {\n if (value && hasLoadedFirstOptions) {\n if (hasMany) {\n const matchedOptions = findOptionsByValue()\n\n ;((matchedOptions as Option[]) || []).forEach((option, i) => {\n if (!option) {\n if (hasMultipleRelations) {\n addOptionByID(value[i].value, value[i].relationTo)\n } else {\n addOptionByID(value[i], relationTo)\n }\n }\n })\n } else {\n const matchedOption = findOptionsByValue()\n\n if (!matchedOption) {\n if (hasMultipleRelations) {\n const valueWithRelation = value as ValueWithRelation\n addOptionByID(valueWithRelation.value, valueWithRelation.relationTo)\n } else {\n addOptionByID(value, relationTo)\n }\n }\n }\n }\n }, [\n addOptionByID,\n findOptionsByValue,\n hasMany,\n hasMultipleRelations,\n relationTo,\n value,\n hasLoadedFirstOptions,\n ])\n\n const classes = ['field-type', baseClass, errorLoading && 'error-loading']\n .filter(Boolean)\n .join(' ')\n\n const valueToRender = (findOptionsByValue() || value) as Option\n\n return (\n <div className={classes}>\n {!errorLoading && (\n <ReactSelect\n disabled={disabled}\n isMulti={hasMany}\n isSortable={isSortable}\n onChange={(selected) => {\n if (!selected) {\n onChange(null)\n return\n }\n if (hasMany && Array.isArray(selected)) {\n onChange(\n selected\n ? selected.map((option) => {\n if (hasMultipleRelations) {\n return {\n relationTo: option?.relationTo,\n value: option?.value,\n }\n }\n\n return option?.value\n })\n : null,\n )\n } else if (hasMultipleRelations && !Array.isArray(selected)) {\n onChange({\n relationTo: selected?.relationTo,\n value: selected?.value,\n })\n } else if (!Array.isArray(selected)) {\n onChange(selected?.value)\n }\n }}\n onInputChange={handleInputChange}\n onMenuScrollToBottom={loadMoreOptions}\n options={options}\n placeholder={t('general:selectValue')}\n value={valueToRender}\n />\n )}\n {errorLoading && <div className={`${baseClass}__error-loading`}>{errorLoading}</div>}\n </div>\n )\n}\n"],"names":["QueryString","React","useCallback","useEffect","useReducer","useState","useDebounce","useConfig","useTranslation","ReactSelect","optionsReducer","baseClass","maxResultsPerRequest","RelationshipField","props","admin","isSortable","disabled","hasMany","onChange","relationTo","value","collections","routes","api","serverURL","hasMultipleRelations","Array","isArray","options","dispatchOptions","search","setSearch","errorLoading","setErrorLoading","hasLoadedFirstOptions","setHasLoadedFirstOptions","debouncedSearch","i18n","t","relationSlugs","initialRelationMap","map","Map","forEach","relation","set","nextPageByRelationshipRef","useRef","partiallyLoadedRelationshipSlugs","addOptions","data","collection","find","coll","slug","type","loadRelationOptions","abortController","relationSlug","fieldToSearch","useAsTitle","pageIndex","current","get","includes","query","depth","limit","page","where","and","push","like","response","fetch","stringify","addQueryPrefix","credentials","headers","language","signal","ok","json","docs","length","nextPage","filter","partiallyLoadedRelation","e","aborted","console","error","loadMoreOptions","AbortController","findOptionsByValue","val","matchedOption","opt","some","subOpt","undefined","valueWithRelation","handleInputChange","newSearch","addOptionByID","id","relations","abortControllers","controller","abort","matchedOptions","option","i","classes","Boolean","join","valueToRender","div","className","isMulti","selected","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gBAAIC,WAAW,CAAC,EAAE5G,UAAU,eAAe,CAAC;0BAAGsB;;;;AAGvE,EAAC"}
@@ -11,7 +11,7 @@ export type Props = {
11
11
  fieldName: string;
12
12
  fields: FieldCondition[];
13
13
  initialValue: string;
14
- operator: string;
14
+ operator: Operator;
15
15
  orIndex: number;
16
16
  removeCondition: ({ andIndex, orIndex }: {
17
17
  andIndex: number;
@@ -25,6 +25,7 @@ export type Props = {
25
25
  value: string;
26
26
  }) => void;
27
27
  };
28
+ import type { Operator } from 'payload/types';
28
29
  import './index.scss';
29
30
  export declare const Condition: React.FC<Props>;
30
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/WhereBuilder/Condition/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,MAAM,KAAK,GAAG;IAClB,YAAY,EAAE,CAAC,EACb,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,GACT,EAAE;QACD,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAA;KACvB,KAAK,IAAI,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACvF,eAAe,EAAE,CAAC,EAChB,QAAQ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,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,QAAQ,EAAE,MAAM,CAAA;QAChB,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,EAAE,MAAM,CAAA;KACd,KAAK,IAAI,CAAA;CACX,CAAA;AAED,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAa7C,OAAO,cAAc,CAAA;AAarB,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAgJrC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/elements/WhereBuilder/Condition/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FieldCondition } from '../types.js'\n\nexport type Props = {\n addCondition: ({\n andIndex,\n fieldName,\n orIndex,\n relation,\n }: {\n andIndex: number\n fieldName: string\n orIndex: number\n relation: 'and' | 'or'\n }) => void\n andIndex: number\n fieldName: string\n fields: FieldCondition[]\n initialValue: string\n operator: string\n orIndex: number\n removeCondition: ({ andIndex, orIndex }: { andIndex: number; orIndex: number }) => void\n updateCondition: ({\n andIndex,\n fieldName,\n operator,\n orIndex,\n value,\n }: {\n andIndex: number\n fieldName: string\n operator: string\n orIndex: number\n value: string\n }) => void\n}\n\nimport { RenderCustomClientComponent } from '../../../elements/RenderCustomClientComponent/index.js'\nimport { useDebounce } from '../../../hooks/useDebounce.js'\nimport { Button } from '../../Button/index.js'\nimport { ReactSelect } from '../../ReactSelect/index.js'\nimport { DateField } from './Date/index.js'\nimport { NumberField } from './Number/index.js'\nimport { RelationshipField } from './Relationship/index.js'\nimport { Select } from './Select/index.js'\nimport Text from './Text/index.js'\nimport './index.scss'\n\ntype ComponentType = 'Date' | 'Number' | 'Relationship' | 'Select' | 'Text'\nconst valueFields: Record<ComponentType, React.FC> = {\n Date: DateField,\n Number: NumberField,\n Relationship: RelationshipField,\n Select,\n Text,\n}\n\nconst baseClass = 'condition'\n\nexport const Condition: React.FC<Props> = (props) => {\n const {\n addCondition,\n andIndex,\n fieldName,\n fields,\n initialValue,\n operator,\n orIndex,\n removeCondition,\n updateCondition,\n } = props\n const [internalField, setInternalField] = useState<FieldCondition>(() =>\n fields.find((field) => fieldName === field.value),\n )\n const [internalOperatorOption, setInternalOperatorOption] = useState(operator)\n const [internalQueryValue, setInternalQueryValue] = useState<string>(initialValue)\n\n const debouncedValue = useDebounce(internalQueryValue, 300)\n\n useEffect(() => {\n // This is to trigger changes when the debounced value changes\n if (\n (internalField?.value || typeof internalField?.value === 'number') &&\n internalOperatorOption &&\n ![null, undefined].includes(debouncedValue)\n ) {\n updateCondition({\n andIndex,\n fieldName: internalField.value,\n operator: internalOperatorOption,\n orIndex,\n value: debouncedValue,\n })\n }\n }, [\n debouncedValue,\n andIndex,\n internalField?.value,\n internalOperatorOption,\n orIndex,\n updateCondition,\n operator,\n ])\n\n const booleanSelect =\n ['exists'].includes(internalOperatorOption) || internalField?.props?.type === 'checkbox'\n const ValueComponent = booleanSelect\n ? Select\n : valueFields[internalField?.component] || valueFields.Text\n\n let valueOptions\n if (booleanSelect) {\n valueOptions = ['true', 'false']\n } else if (internalField?.props && 'options' in internalField.props) {\n valueOptions = internalField.props.options\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__wrap`}>\n <div className={`${baseClass}__inputs`}>\n <div className={`${baseClass}__field`}>\n <ReactSelect\n isClearable={false}\n onChange={(field) => {\n setInternalField(fields.find((f) => f.value === field.value))\n setInternalOperatorOption(undefined)\n setInternalQueryValue(undefined)\n }}\n options={fields}\n value={fields.find((field) => internalField?.value === field.value) || fields[0]}\n />\n </div>\n <div className={`${baseClass}__operator`}>\n <ReactSelect\n disabled={!internalField?.value && typeof internalField?.value !== 'number'}\n isClearable={false}\n onChange={(operator) => {\n setInternalOperatorOption(operator.value)\n }}\n options={internalField?.operators}\n value={\n internalField?.operators.find(\n (operator) => internalOperatorOption === operator.value,\n ) || null\n }\n />\n </div>\n <div className={`${baseClass}__value`}>\n <RenderCustomClientComponent\n CustomComponent={internalField?.props?.admin?.components?.Filter}\n DefaultComponent={ValueComponent}\n componentProps={{\n ...internalField?.props,\n disabled: !internalOperatorOption,\n onChange: setInternalQueryValue,\n operator: internalOperatorOption,\n options: valueOptions,\n relationTo:\n internalField?.props?.type === 'relationship' &&\n 'cellProps' in internalField.props &&\n typeof internalField.props.cellProps === 'object' &&\n 'relationTo' in internalField.props.cellProps\n ? internalField.props.cellProps?.relationTo\n : undefined,\n value: internalQueryValue ?? '',\n }}\n />\n </div>\n </div>\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-remove`}\n icon=\"x\"\n iconStyle=\"with-border\"\n onClick={() =>\n removeCondition({\n andIndex,\n orIndex,\n })\n }\n round\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-add`}\n icon=\"plus\"\n iconStyle=\"with-border\"\n onClick={() =>\n addCondition({\n andIndex: andIndex + 1,\n fieldName: fields[0].value,\n orIndex,\n relation: 'and',\n })\n }\n round\n />\n </div>\n </div>\n </div>\n )\n}\n"],"names":["React","useEffect","useState","RenderCustomClientComponent","useDebounce","Button","ReactSelect","DateField","NumberField","RelationshipField","Select","Text","valueFields","Date","Number","Relationship","baseClass","Condition","props","addCondition","andIndex","fieldName","fields","initialValue","operator","orIndex","removeCondition","updateCondition","internalField","setInternalField","find","field","value","internalOperatorOption","setInternalOperatorOption","internalQueryValue","setInternalQueryValue","debouncedValue","undefined","includes","booleanSelect","type","ValueComponent","component","valueOptions","options","div","className","isClearable","onChange","f","disabled","operators","CustomComponent","admin","components","Filter","DefaultComponent","componentProps","relationTo","cellProps","buttonStyle","icon","iconStyle","onClick","round","relation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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WAAW,CAAC,EAAE/B,UAAU,OAAO,CAAC;sCACnC,cAAA,KAACb;gCACCkD,iBAAiBzB,eAAeV,OAAOoC,OAAOC,YAAYC;gCAC1DC,kBAAkBf;gCAClBgB,gBAAgB;oCACd,GAAG9B,eAAeV,KAAK;oCACvBiC,UAAU,CAAClB;oCACXgB,UAAUb;oCACVZ,UAAUS;oCACVY,SAASD;oCACTe,YACE/B,eAAeV,OAAOuB,SAAS,kBAC/B,eAAeb,cAAcV,KAAK,IAClC,OAAOU,cAAcV,KAAK,CAAC0C,SAAS,KAAK,YACzC,gBAAgBhC,cAAcV,KAAK,CAAC0C,SAAS,GACzChC,cAAcV,KAAK,CAAC0C,SAAS,EAAED,aAC/BrB;oCACNN,OAAOG,sBAAsB;gCAC/B;;;;;8BAIN,MAACW;oBAAIC,WAAW,CAAC,EAAE/B,UAAU,SAAS,CAAC;;sCACrC,KAACX;4BACCwD,aAAY;4BACZd,WAAW,CAAC,EAAE/B,UAAU,gBAAgB,CAAC;4BACzC8C,MAAK;4BACLC,WAAU;4BACVC,SAAS,IACPtC,gBAAgB;oCACdN;oCACAK;gCACF;4BAEFwC,KAAK;;sCAEP,KAAC5D;4BACCwD,aAAY;4BACZd,WAAW,CAAC,EAAE/B,UAAU,aAAa,CAAC;4BACtC8C,MAAK;4BACLC,WAAU;4BACVC,SAAS,IACP7C,aAAa;oCACXC,UAAUA,WAAW;oCACrBC,WAAWC,MAAM,CAAC,EAAE,CAACU,KAAK;oCAC1BP;oCACAyC,UAAU;gCACZ;4BAEFD,KAAK;;;;;;;AAMjB,EAAC"}
1
+ {"version":3,"sources":["../../../../src/elements/WhereBuilder/Condition/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FieldCondition } from '../types.js'\n\nexport type Props = {\n addCondition: ({\n andIndex,\n fieldName,\n orIndex,\n relation,\n }: {\n andIndex: number\n fieldName: string\n orIndex: number\n relation: 'and' | 'or'\n }) => void\n andIndex: number\n fieldName: string\n fields: FieldCondition[]\n initialValue: string\n operator: Operator\n orIndex: number\n removeCondition: ({ andIndex, orIndex }: { andIndex: number; orIndex: number }) => void\n updateCondition: ({\n andIndex,\n fieldName,\n operator,\n orIndex,\n value,\n }: {\n andIndex: number\n fieldName: string\n operator: string\n orIndex: number\n value: string\n }) => void\n}\n\nimport type { Operator } from 'payload/types'\n\nimport type { Option } from '../../ReactSelect/index.js'\n\nimport { RenderCustomClientComponent } from '../../../elements/RenderCustomClientComponent/index.js'\nimport { useDebounce } from '../../../hooks/useDebounce.js'\nimport { Button } from '../../Button/index.js'\nimport { ReactSelect } from '../../ReactSelect/index.js'\nimport { DateField } from './Date/index.js'\nimport { NumberField } from './Number/index.js'\nimport { RelationshipField } from './Relationship/index.js'\nimport { Select } from './Select/index.js'\nimport Text from './Text/index.js'\nimport './index.scss'\n\ntype ComponentType = 'Date' | 'Number' | 'Relationship' | 'Select' | 'Text'\nconst valueFields: Record<ComponentType, React.FC> = {\n Date: DateField,\n Number: NumberField,\n Relationship: RelationshipField,\n Select,\n Text,\n}\n\nconst baseClass = 'condition'\n\nexport const Condition: React.FC<Props> = (props) => {\n const {\n addCondition,\n andIndex,\n fieldName,\n fields,\n initialValue,\n operator,\n orIndex,\n removeCondition,\n updateCondition,\n } = props\n const [internalField, setInternalField] = useState<FieldCondition>(() =>\n fields.find((field) => fieldName === field.value),\n )\n const [internalOperatorOption, setInternalOperatorOption] = useState<Operator>(operator)\n const [internalQueryValue, setInternalQueryValue] = useState<string>(initialValue)\n\n const debouncedValue = useDebounce(internalQueryValue, 300)\n\n useEffect(() => {\n // This is to trigger changes when the debounced value changes\n if (\n (internalField?.value || typeof internalField?.value === 'number') &&\n internalOperatorOption &&\n ![null, undefined].includes(debouncedValue)\n ) {\n updateCondition({\n andIndex,\n fieldName: internalField.value,\n operator: internalOperatorOption,\n orIndex,\n value: debouncedValue,\n })\n }\n }, [\n debouncedValue,\n andIndex,\n internalField?.value,\n internalOperatorOption,\n orIndex,\n updateCondition,\n operator,\n ])\n\n const booleanSelect =\n ['exists'].includes(internalOperatorOption) || internalField?.props?.type === 'checkbox'\n const ValueComponent = booleanSelect\n ? Select\n : valueFields[internalField?.component] || valueFields.Text\n\n let valueOptions\n if (booleanSelect) {\n valueOptions = ['true', 'false']\n } else if (internalField?.props && 'options' in internalField.props) {\n valueOptions = internalField.props.options\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__wrap`}>\n <div className={`${baseClass}__inputs`}>\n <div className={`${baseClass}__field`}>\n <ReactSelect\n isClearable={false}\n onChange={(field: Option) => {\n setInternalField(fields.find((f) => f.value === field.value))\n setInternalOperatorOption(undefined)\n setInternalQueryValue(undefined)\n }}\n options={fields}\n value={fields.find((field) => internalField?.value === field.value) || fields[0]}\n />\n </div>\n <div className={`${baseClass}__operator`}>\n <ReactSelect\n disabled={!internalField?.value && typeof internalField?.value !== 'number'}\n isClearable={false}\n onChange={(operator: Option<Operator>) => {\n setInternalOperatorOption(operator.value)\n }}\n options={internalField?.operators}\n value={\n internalField?.operators.find(\n (operator) => internalOperatorOption === operator.value,\n ) || null\n }\n />\n </div>\n <div className={`${baseClass}__value`}>\n <RenderCustomClientComponent\n CustomComponent={internalField?.props?.admin?.components?.Filter}\n DefaultComponent={ValueComponent}\n componentProps={{\n ...internalField?.props,\n disabled: !internalOperatorOption,\n onChange: setInternalQueryValue,\n operator: internalOperatorOption,\n options: valueOptions,\n relationTo:\n internalField?.props?.type === 'relationship' &&\n 'cellProps' in internalField.props &&\n typeof internalField.props.cellProps === 'object' &&\n 'relationTo' in internalField.props.cellProps\n ? internalField.props.cellProps?.relationTo\n : undefined,\n value: internalQueryValue ?? '',\n }}\n />\n </div>\n </div>\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-remove`}\n icon=\"x\"\n iconStyle=\"with-border\"\n onClick={() =>\n removeCondition({\n andIndex,\n orIndex,\n })\n }\n round\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-add`}\n icon=\"plus\"\n iconStyle=\"with-border\"\n onClick={() =>\n addCondition({\n andIndex: andIndex + 1,\n fieldName: fields[0].value,\n orIndex,\n relation: 'and',\n })\n }\n round\n />\n </div>\n </div>\n </div>\n )\n}\n"],"names":["React","useEffect","useState","RenderCustomClientComponent","useDebounce","Button","ReactSelect","DateField","NumberField","RelationshipField","Select","Text","valueFields","Date","Number","Relationship","baseClass","Condition","props","addCondition","andIndex","fieldName","fields","initialValue","operator","orIndex","removeCondition","updateCondition","internalField","setInternalField","find","field","value","internalOperatorOption","setInternalOperatorOption","internalQueryValue","setInternalQueryValue","debouncedValue","undefined","includes","booleanSelect","type","ValueComponent","component","valueOptions","options","div","className","isClearable","onChange","f","disabled","operators","CustomComponent","admin","components","Filter","DefaultComponent","componentProps","relationTo","cellProps","buttonStyle","icon","iconStyle","onClick","round","relation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,OAAOA,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AA0ClD,SAASC,2BAA2B,QAAQ,yDAAwD;AACpG,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,SAASC,MAAM,QAAQ,oBAAmB;AAC1C,OAAOC,UAAU,kBAAiB;AAIlC,MAAMC,cAA+C;IACnDC,MAAMN;IACNO,QAAQN;IACRO,cAAcN;IACdC;IACAC;AACF;AAEA,MAAMK,YAAY;AAElB,OAAO,MAAMC,YA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AW,CAAC,EAAE/B,UAAU,SAAS,CAAC;;sCACrC,KAACX;4BACCwD,aAAY;4BACZd,WAAW,CAAC,EAAE/B,UAAU,gBAAgB,CAAC;4BACzC8C,MAAK;4BACLC,WAAU;4BACVC,SAAS,IACPtC,gBAAgB;oCACdN;oCACAK;gCACF;4BAEFwC,KAAK;;sCAEP,KAAC5D;4BACCwD,aAAY;4BACZd,WAAW,CAAC,EAAE/B,UAAU,aAAa,CAAC;4BACtC8C,MAAK;4BACLC,WAAU;4BACVC,SAAS,IACP7C,aAAa;oCACXC,UAAUA,WAAW;oCACrBC,WAAWC,MAAM,CAAC,EAAE,CAACU,KAAK;oCAC1BP;oCACAyC,UAAU;gCACZ;4BAEFD,KAAK;;;;;;;AAMjB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAQnD,OAAO,cAAc,CAAA;AAOrB,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAE5B;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4NpD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAQnD,OAAO,cAAc,CAAA;AAOrB,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAE5B;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4NpD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/elements/WhereBuilder/index.tsx"],"sourcesContent":["'use client'\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useEffect, useState } from 'react'\n\nimport type { WhereBuilderProps } from './types.js'\n\nimport { useListQuery } from '../../providers/ListQuery/index.js'\nimport { useSearchParams } from '../../providers/SearchParams/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/index.js'\nimport { useTableColumns } from '../TableColumns/index.js'\nimport { Condition } from './Condition/index.js'\nimport './index.scss'\nimport { reduceFieldMap } from './reduceFieldMap.js'\nimport { transformWhereQuery } from './transformWhereQuery.js'\nimport validateWhereQuery from './validateWhereQuery.js'\n\nconst baseClass = 'where-builder'\n\nexport { WhereBuilderProps }\n\n/**\n * The WhereBuilder component is used to render the filter controls for a collection's list view.\n * It is part of the {@link ListControls} component which is used to render the controls (search, filter, where).\n */\nexport const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {\n const { collectionPluralLabel } = props\n const { i18n, t } = useTranslation()\n const { columns } = useTableColumns()\n\n const [reducedFields, setReducedColumns] = useState(() => reduceFieldMap(columns, i18n))\n\n useEffect(() => {\n setReducedColumns(reduceFieldMap(columns, i18n))\n }, [columns, i18n])\n\n const { searchParams } = useSearchParams()\n const { handleWhereChange } = useListQuery()\n const [shouldUpdateQuery, setShouldUpdateQuery] = React.useState(false)\n\n // This handles initializing the where conditions from the search query (URL). That way, if you pass in\n // query params to the URL, the where conditions will be initialized from those and displayed in the UI.\n // Example: /admin/collections/posts?where[or][0][and][0][text][equals]=example%20post\n /*\n stored conditions look like this:\n [\n _or_ & _and_ queries have the same shape:\n {\n and: [{\n category: {\n equals: 'category-a'\n }\n }]\n },\n\n {\n and:[{\n category: {\n equals: 'category-b'\n },\n text: {\n not_equals: 'oranges'\n },\n }]\n }\n ]\n */\n\n const [conditions, setConditions] = React.useState(() => {\n const whereFromSearch = searchParams.where\n if (whereFromSearch) {\n if (validateWhereQuery(whereFromSearch)) {\n return whereFromSearch.or\n }\n\n // Transform the where query to be in the right format. This will transform something simple like [text][equals]=example%20post to the right format\n const transformedWhere = transformWhereQuery(whereFromSearch)\n\n if (validateWhereQuery(transformedWhere)) {\n return transformedWhere.or\n }\n\n console.warn(`Invalid where query in URL: ${JSON.stringify(whereFromSearch)}`)\n }\n\n return []\n })\n\n const addCondition = React.useCallback(\n ({ andIndex, fieldName, orIndex, relation }) => {\n const newConditions = [...conditions]\n if (relation === 'and') {\n newConditions[orIndex].and.splice(andIndex, 0, { [fieldName]: {} })\n } else {\n newConditions.push({\n and: [\n {\n [fieldName]: {},\n },\n ],\n })\n }\n setConditions(newConditions)\n },\n [conditions],\n )\n\n const updateCondition = React.useCallback(\n ({ andIndex, fieldName, operator, orIndex, value: valueArg }) => {\n const existingRowCondition = conditions[orIndex].and[andIndex]\n if (typeof existingRowCondition === 'object' && fieldName && operator) {\n const value = valueArg ?? (operator ? existingRowCondition[operator] : '')\n const newRowCondition = {\n [fieldName]: operator ? { [operator]: value } : {},\n }\n\n if (JSON.stringify(existingRowCondition) !== JSON.stringify(newRowCondition)) {\n conditions[orIndex].and[andIndex] = newRowCondition\n setConditions(conditions)\n if (![null, undefined].includes(value)) {\n // only update query when field/operator/value are filled out\n setShouldUpdateQuery(true)\n }\n }\n }\n },\n [conditions],\n )\n\n const removeCondition = React.useCallback(\n ({ andIndex, orIndex }) => {\n const newConditions = [...conditions]\n newConditions[orIndex].and.splice(andIndex, 1)\n if (newConditions[orIndex].and.length === 0) {\n newConditions.splice(orIndex, 1)\n }\n setConditions(newConditions)\n setShouldUpdateQuery(true)\n },\n [conditions],\n )\n\n React.useEffect(() => {\n if (shouldUpdateQuery) {\n handleWhereChange({ or: conditions })\n setShouldUpdateQuery(false)\n }\n }, [conditions, handleWhereChange, shouldUpdateQuery])\n\n return (\n <div className={baseClass}>\n {conditions.length > 0 && (\n <React.Fragment>\n <div className={`${baseClass}__label`}>\n {t('general:filterWhere', { label: getTranslation(collectionPluralLabel, i18n) })}\n </div>\n <ul className={`${baseClass}__or-filters`}>\n {conditions.map((or, orIndex) => {\n const compoundOrKey = `${orIndex}_${Array.isArray(or?.and) ? or.and.length : ''}`\n\n return (\n <li key={compoundOrKey}>\n {orIndex !== 0 && <div className={`${baseClass}__label`}>{t('general:or')}</div>}\n <ul className={`${baseClass}__and-filters`}>\n {Array.isArray(or?.and) &&\n or.and.map((_, andIndex) => {\n const initialFieldName = Object.keys(conditions[orIndex].and[andIndex])[0]\n const initialOperator =\n Object.keys(\n conditions[orIndex].and[andIndex]?.[initialFieldName] || {},\n )?.[0] || undefined\n const initialValue =\n conditions[orIndex].and[andIndex]?.[initialFieldName]?.[\n initialOperator\n ] || ''\n\n return (\n <li key={andIndex}>\n {andIndex !== 0 && (\n <div className={`${baseClass}__label`}>{t('general:and')}</div>\n )}\n <Condition\n addCondition={addCondition}\n andIndex={andIndex}\n fieldName={initialFieldName}\n fields={reducedFields}\n initialValue={initialValue}\n operator={initialOperator}\n orIndex={orIndex}\n removeCondition={removeCondition}\n updateCondition={updateCondition}\n />\n </li>\n )\n })}\n </ul>\n </li>\n )\n })}\n </ul>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-or`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n addCondition({\n andIndex: 0,\n fieldName: reducedFields[0].value,\n orIndex: conditions.length,\n relation: 'or',\n })\n }}\n >\n {t('general:or')}\n </Button>\n </React.Fragment>\n )}\n {conditions.length === 0 && (\n <div className={`${baseClass}__no-filters`}>\n <div className={`${baseClass}__label`}>{t('general:noFiltersSet')}</div>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-first-filter`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n if (reducedFields.length > 0) {\n addCondition({\n andIndex: 0,\n fieldName: reducedFields[0].value,\n orIndex: conditions.length,\n relation: 'or',\n })\n }\n }}\n >\n {t('general:addFilter')}\n </Button>\n </div>\n )}\n </div>\n )\n}\n"],"names":["getTranslation","React","useEffect","useState","useListQuery","useSearchParams","useTranslation","Button","useTableColumns","Condition","reduceFieldMap","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","collectionPluralLabel","i18n","t","columns","reducedFields","setReducedColumns","searchParams","handleWhereChange","shouldUpdateQuery","setShouldUpdateQuery","conditions","setConditions","whereFromSearch","where","or","transformedWhere","console","warn","JSON","stringify","addCondition","useCallback","andIndex","fieldName","orIndex","relation","newConditions","and","splice","push","updateCondition","operator","value","valueArg","existingRowCondition","newRowCondition","undefined","includes","removeCondition","length","div","className","Fragment","label","ul","map","compoundOrKey","Array","isArray","li","_","initialFieldName","Object","keys","initialOperator","initialValue","fields","buttonStyle","icon","iconPosition","iconStyle","onClick"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAIlD,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,MAAM,QAAQ,qBAAoB;AAC3C,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,OAAOC,wBAAwB,0BAAyB;AAExD,MAAMC,YAAY;AAIlB;;;CAGC,GACD,OAAO,MAAMC,eAA4C,CAACC;IACxD,MAAM,EAAEC,qBAAqB,EAAE,GA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KAACkB;wDAAIC,WAAW,CAAC,EAAE5C,UAAU,OAAO,CAAC;kEAAGK,EAAE;;kEAE5C,KAACT;wDACC2B,cAAcA;wDACdE,UAAUA;wDACVC,WAAW4B;wDACXK,QAAQpD;wDACRmD,cAAcA;wDACdxB,UAAUuB;wDACV9B,SAASA;wDACTc,iBAAiBA;wDACjBR,iBAAiBA;;;+CAbZR;wCAiBb;;;+BAjCGwB;wBAqCb;;kCAEF,KAACvD;wBACCkE,aAAY;wBACZhB,WAAW,CAAC,EAAE5C,UAAU,QAAQ,CAAC;wBACjC6D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACPzC,aAAa;gCACXE,UAAU;gCACVC,WAAWnB,aAAa,CAAC,EAAE,CAAC4B,KAAK;gCACjCR,SAASd,WAAW6B,MAAM;gCAC1Bd,UAAU;4BACZ;wBACF;kCAECvB,EAAE;;;;YAIRQ,WAAW6B,MAAM,KAAK,mBACrB,MAACC;gBAAIC,WAAW,CAAC,EAAE5C,UAAU,YAAY,CAAC;;kCACxC,KAAC2C;wBAAIC,WAAW,CAAC,EAAE5C,UAAU,OAAO,CAAC;kCAAGK,EAAE;;kCAC1C,KAACX;wBACCkE,aAAY;wBACZhB,WAAW,CAAC,EAAE5C,UAAU,kBAAkB,CAAC;wBAC3C6D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACP,IAAIzD,cAAcmC,MAAM,GAAG,GAAG;gCAC5BnB,aAAa;oCACXE,UAAU;oCACVC,WAAWnB,aAAa,CAAC,EAAE,CAAC4B,KAAK;oCACjCR,SAASd,WAAW6B,MAAM;oCAC1Bd,UAAU;gCACZ;4BACF;wBACF;kCAECvB,EAAE;;;;;;AAMf,EAAC"}
1
+ {"version":3,"sources":["../../../src/elements/WhereBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { Operator } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useEffect, useState } from 'react'\n\nimport type { WhereBuilderProps } from './types.js'\n\nimport { useListQuery } from '../../providers/ListQuery/index.js'\nimport { useSearchParams } from '../../providers/SearchParams/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/index.js'\nimport { useTableColumns } from '../TableColumns/index.js'\nimport { Condition } from './Condition/index.js'\nimport './index.scss'\nimport { reduceFieldMap } from './reduceFieldMap.js'\nimport { transformWhereQuery } from './transformWhereQuery.js'\nimport validateWhereQuery from './validateWhereQuery.js'\n\nconst baseClass = 'where-builder'\n\nexport { WhereBuilderProps }\n\n/**\n * The WhereBuilder component is used to render the filter controls for a collection's list view.\n * It is part of the {@link ListControls} component which is used to render the controls (search, filter, where).\n */\nexport const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {\n const { collectionPluralLabel } = props\n const { i18n, t } = useTranslation()\n const { columns } = useTableColumns()\n\n const [reducedFields, setReducedColumns] = useState(() => reduceFieldMap(columns, i18n))\n\n useEffect(() => {\n setReducedColumns(reduceFieldMap(columns, i18n))\n }, [columns, i18n])\n\n const { searchParams } = useSearchParams()\n const { handleWhereChange } = useListQuery()\n const [shouldUpdateQuery, setShouldUpdateQuery] = React.useState(false)\n\n // This handles initializing the where conditions from the search query (URL). That way, if you pass in\n // query params to the URL, the where conditions will be initialized from those and displayed in the UI.\n // Example: /admin/collections/posts?where[or][0][and][0][text][equals]=example%20post\n /*\n stored conditions look like this:\n [\n _or_ & _and_ queries have the same shape:\n {\n and: [{\n category: {\n equals: 'category-a'\n }\n }]\n },\n\n {\n and:[{\n category: {\n equals: 'category-b'\n },\n text: {\n not_equals: 'oranges'\n },\n }]\n }\n ]\n */\n\n const [conditions, setConditions] = React.useState(() => {\n const whereFromSearch = searchParams.where\n if (whereFromSearch) {\n if (validateWhereQuery(whereFromSearch)) {\n return whereFromSearch.or\n }\n\n // Transform the where query to be in the right format. This will transform something simple like [text][equals]=example%20post to the right format\n const transformedWhere = transformWhereQuery(whereFromSearch)\n\n if (validateWhereQuery(transformedWhere)) {\n return transformedWhere.or\n }\n\n console.warn(`Invalid where query in URL: ${JSON.stringify(whereFromSearch)}`)\n }\n\n return []\n })\n\n const addCondition = React.useCallback(\n ({ andIndex, fieldName, orIndex, relation }) => {\n const newConditions = [...conditions]\n if (relation === 'and') {\n newConditions[orIndex].and.splice(andIndex, 0, { [fieldName]: {} })\n } else {\n newConditions.push({\n and: [\n {\n [fieldName]: {},\n },\n ],\n })\n }\n setConditions(newConditions)\n },\n [conditions],\n )\n\n const updateCondition = React.useCallback(\n ({ andIndex, fieldName, operator, orIndex, value: valueArg }) => {\n const existingRowCondition = conditions[orIndex].and[andIndex]\n if (typeof existingRowCondition === 'object' && fieldName && operator) {\n const value = valueArg ?? (operator ? existingRowCondition[operator] : '')\n const newRowCondition = {\n [fieldName]: operator ? { [operator]: value } : {},\n }\n\n if (JSON.stringify(existingRowCondition) !== JSON.stringify(newRowCondition)) {\n conditions[orIndex].and[andIndex] = newRowCondition\n setConditions(conditions)\n if (![null, undefined].includes(value)) {\n // only update query when field/operator/value are filled out\n setShouldUpdateQuery(true)\n }\n }\n }\n },\n [conditions],\n )\n\n const removeCondition = React.useCallback(\n ({ andIndex, orIndex }) => {\n const newConditions = [...conditions]\n newConditions[orIndex].and.splice(andIndex, 1)\n if (newConditions[orIndex].and.length === 0) {\n newConditions.splice(orIndex, 1)\n }\n setConditions(newConditions)\n setShouldUpdateQuery(true)\n },\n [conditions],\n )\n\n React.useEffect(() => {\n if (shouldUpdateQuery) {\n handleWhereChange({ or: conditions })\n setShouldUpdateQuery(false)\n }\n }, [conditions, handleWhereChange, shouldUpdateQuery])\n\n return (\n <div className={baseClass}>\n {conditions.length > 0 && (\n <React.Fragment>\n <div className={`${baseClass}__label`}>\n {t('general:filterWhere', { label: getTranslation(collectionPluralLabel, i18n) })}\n </div>\n <ul className={`${baseClass}__or-filters`}>\n {conditions.map((or, orIndex) => {\n const compoundOrKey = `${orIndex}_${Array.isArray(or?.and) ? or.and.length : ''}`\n\n return (\n <li key={compoundOrKey}>\n {orIndex !== 0 && <div className={`${baseClass}__label`}>{t('general:or')}</div>}\n <ul className={`${baseClass}__and-filters`}>\n {Array.isArray(or?.and) &&\n or.and.map((_, andIndex) => {\n const initialFieldName = Object.keys(conditions[orIndex].and[andIndex])[0]\n const initialOperator =\n (Object.keys(\n conditions[orIndex].and[andIndex]?.[initialFieldName] || {},\n )?.[0] as Operator) || undefined\n const initialValue =\n conditions[orIndex].and[andIndex]?.[initialFieldName]?.[\n initialOperator\n ] || ''\n\n return (\n <li key={andIndex}>\n {andIndex !== 0 && (\n <div className={`${baseClass}__label`}>{t('general:and')}</div>\n )}\n <Condition\n addCondition={addCondition}\n andIndex={andIndex}\n fieldName={initialFieldName}\n fields={reducedFields}\n initialValue={initialValue}\n operator={initialOperator}\n orIndex={orIndex}\n removeCondition={removeCondition}\n updateCondition={updateCondition}\n />\n </li>\n )\n })}\n </ul>\n </li>\n )\n })}\n </ul>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-or`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n addCondition({\n andIndex: 0,\n fieldName: reducedFields[0].value,\n orIndex: conditions.length,\n relation: 'or',\n })\n }}\n >\n {t('general:or')}\n </Button>\n </React.Fragment>\n )}\n {conditions.length === 0 && (\n <div className={`${baseClass}__no-filters`}>\n <div className={`${baseClass}__label`}>{t('general:noFiltersSet')}</div>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-first-filter`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n if (reducedFields.length > 0) {\n addCondition({\n andIndex: 0,\n fieldName: reducedFields[0].value,\n orIndex: conditions.length,\n relation: 'or',\n })\n }\n }}\n >\n {t('general:addFilter')}\n </Button>\n </div>\n )}\n </div>\n )\n}\n"],"names":["getTranslation","React","useEffect","useState","useListQuery","useSearchParams","useTranslation","Button","useTableColumns","Condition","reduceFieldMap","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","collectionPluralLabel","i18n","t","columns","reducedFields","setReducedColumns","searchParams","handleWhereChange","shouldUpdateQuery","setShouldUpdateQuery","conditions","setConditions","whereFromSearch","where","or","transformedWhere","console","warn","JSON","stringify","addCondition","useCallback","andIndex","fieldName","orIndex","relation","newConditions","and","splice","push","updateCondition","operator","value","valueArg","existingRowCondition","newRowCondition","undefined","includes","removeCondition","length","div","className","Fragment","label","ul","map","compoundOrKey","Array","isArray","li","_","initialFieldName","Object","keys","initialOperator","initialValue","fields","buttonStyle","icon","iconPosition","iconStyle","onClick"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAIlD,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,MAAM,QAAQ,qBAAoB;AAC3C,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,OAAOC,wBAAwB,0BAAyB;AAExD,MAAMC,YAAY;AAIlB;;;CAGC,GACD,OAAO,MAAMC,eAA4C,CAACC;IACxD,MAAM,EAAEC,qBAAqB,EAAE,GAAGD;IAClC,MAAM,EAAEE,IAAI,EAAEC,CAAC,EAAE,GAAGZ;IAC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;kEAAGK,EAAE;;kEAE5C,KAACT;wDACC2B,cAAcA;wDACdE,UAAUA;wDACVC,WAAW4B;wDACXK,QAAQpD;wDACRmD,cAAcA;wDACdxB,UAAUuB;wDACV9B,SAASA;wDACTc,iBAAiBA;wDACjBR,iBAAiBA;;;+CAbZR;wCAiBb;;;+BAjCGwB;wBAqCb;;kCAEF,KAACvD;wBACCkE,aAAY;wBACZhB,WAAW,CAAC,EAAE5C,UAAU,QAAQ,CAAC;wBACjC6D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACPzC,aAAa;gCACXE,UAAU;gCACVC,WAAWnB,aAAa,CAAC,EAAE,CAAC4B,KAAK;gCACjCR,SAASd,WAAW6B,MAAM;gCAC1Bd,UAAU;4BACZ;wBACF;kCAECvB,EAAE;;;;YAIRQ,WAAW6B,MAAM,KAAK,mBACrB,MAACC;gBAAIC,WAAW,CAAC,EAAE5C,UAAU,YAAY,CAAC;;kCACxC,KAAC2C;wBAAIC,WAAW,CAAC,EAAE5C,UAAU,OAAO,CAAC;kCAAGK,EAAE;;kCAC1C,KAACX;wBACCkE,aAAY;wBACZhB,WAAW,CAAC,EAAE5C,UAAU,kBAAkB,CAAC;wBAC3C6D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACP,IAAIzD,cAAcmC,MAAM,GAAG,GAAG;gCAC5BnB,aAAa;oCACXE,UAAU;oCACVC,WAAWnB,aAAa,CAAC,EAAE,CAAC4B,KAAK;oCACjCR,SAASd,WAAW6B,MAAM;oCAC1Bd,UAAU;gCACZ;4BACF;wBACF;kCAECvB,EAAE;;;;;;AAMf,EAAC"}
@@ -76,7 +76,7 @@ export const _ArrayField = (props)=>{
76
76
  const { path: pathFromContext } = useFieldProps();
77
77
  const { errorPaths, formInitializing, formProcessing, path, rows = [], schemaPath, showError, valid, value } = useField({
78
78
  hasRows: true,
79
- path: pathFromContext || pathFromProps || name,
79
+ path: pathFromContext ?? pathFromProps ?? name,
80
80
  validate: memoizedValidate
81
81
  });
82
82
  const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
@@ -287,7 +287,7 @@ export const _ArrayField = (props)=>{
287
287
  type: "error",
288
288
  children: t('validation:requiresAtLeast', {
289
289
  count: minRows,
290
- label: getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) || t(minRows > 1 ? 'general:row' : 'general:rows')
290
+ label: getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) || t(minRows > 1 ? 'general:rows' : 'general:row')
291
291
  })
292
292
  })
293
293
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Array/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions } from 'payload/auth'\nimport type { ArrayField as ArrayFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { ArrayRow } from './ArrayRow.js'\nimport './index.scss'\n\nconst baseClass = 'array-field'\n\nexport type ArrayFieldProps = FormFieldBase & {\n CustomRowLabel?: React.ReactNode\n fieldMap: FieldMap\n forceRender?: boolean\n isSortable?: boolean\n labels?: ArrayFieldType['labels']\n maxRows?: ArrayFieldType['maxRows']\n minRows?: ArrayFieldType['minRows']\n name?: string\n permissions: FieldPermissions\n width?: string\n}\n\nexport const _ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n CustomRowLabel,\n className,\n descriptionProps,\n errorProps,\n fieldMap,\n forceRender = false,\n isSortable = true,\n label,\n labelProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n path: pathFromProps,\n permissions,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const submitted = useFormSubmitted()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n const { localization } = useConfig()\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n // Handle labeling for Arrays, Global Arrays, and Blocks\n const getLabels = (p: ArrayFieldProps): ArrayFieldType['labels'] => {\n if ('labels' in p && p?.labels) return p.labels\n if ('label' in p && p?.label) return { plural: undefined, singular: p?.label }\n return { plural: t('general:rows'), singular: t('general:row') }\n }\n\n const labels = getLabels(props)\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number) => {\n await addFieldRow({ path, rowIndex, schemaPath })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'REMOVE_ROW', path, rowIndex })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && errorPaths.length > 0\n\n const showRequired = disabled && rows.length === 0\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__header-content`}>\n <h3 className={`${baseClass}__title`}>\n <FieldLabel\n CustomLabel={CustomLabel}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__draggable-rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const rowErrorCount = errorPaths?.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}.`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <ArrayRow\n {...draggableSortableItemProps}\n CustomRowLabel={CustomRowLabel}\n addRow={addRow}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n fieldMap={fieldMap}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n })}\n {!valid && (\n <React.Fragment>\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:row' : 'general:rows'),\n })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-row`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => addRow(value || 0)}\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n )}\n </div>\n )\n}\n\nexport const ArrayField = withCondition(_ArrayField)\n"],"names":["getTranslation","React","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","ErrorPill","FieldDescription","FieldError","FieldLabel","useFieldProps","useForm","useFormSubmitted","NullifyLocaleField","useField","withCondition","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","ArrayRow","baseClass","_ArrayField","props","name","CustomDescription","CustomError","CustomLabel","CustomRowLabel","className","descriptionProps","errorProps","fieldMap","forceRender","isSortable","label","labelProps","localized","maxRows","minRows","minRowsProp","path","pathFromProps","permissions","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","submitted","code","locale","i18n","t","localization","editingDefaultLocale","fallback","defaultLocale","getLabels","p","labels","plural","undefined","singular","memoizedValidate","value","options","pathFromContext","errorPaths","formInitializing","formProcessing","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showRequired","showMinRows","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","Fragment","buttonStyle","icon","iconPosition","iconStyle","ArrayField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,qBAAqB,QAAQ,kEAAiE;AACvG,SAASC,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,8BAA6B;AACvE,SAASC,kBAAkB,QAA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B;gCACpC;;;;;;YAOX,CAAC0C,YAAY,CAACc,4BACb,KAAC9F;gBACCiI,aAAY;gBACZrG,WAAW,CAAC,EAAER,UAAU,SAAS,CAAC;gBAClC8G,MAAK;gBACLC,cAAa;gBACbC,WAAU;gBACVjB,SAAS,IAAMlC,OAAOZ,SAAS;0BAE9BZ,EAAE,mBAAmB;oBAAEvB,OAAOtC,eAAeoE,OAAOG,QAAQ,EAAEX;gBAAM;;;;AAK/E,EAAC;AAED,OAAO,MAAM6E,aAAazH,cAAcS,aAAY"}
1
+ {"version":3,"sources":["../../../src/fields/Array/index.tsx"],"sourcesContent":["'use client'\nimport type { FieldPermissions } from 'payload/auth'\nimport type { ArrayField as ArrayFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { ArrayRow } from './ArrayRow.js'\nimport './index.scss'\n\nconst baseClass = 'array-field'\n\nexport type ArrayFieldProps = FormFieldBase & {\n CustomRowLabel?: React.ReactNode\n fieldMap: FieldMap\n forceRender?: boolean\n isSortable?: boolean\n labels?: ArrayFieldType['labels']\n maxRows?: ArrayFieldType['maxRows']\n minRows?: ArrayFieldType['minRows']\n name?: string\n permissions: FieldPermissions\n width?: string\n}\n\nexport const _ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n CustomRowLabel,\n className,\n descriptionProps,\n errorProps,\n fieldMap,\n forceRender = false,\n isSortable = true,\n label,\n labelProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n path: pathFromProps,\n permissions,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const submitted = useFormSubmitted()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n const { localization } = useConfig()\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n // Handle labeling for Arrays, Global Arrays, and Blocks\n const getLabels = (p: ArrayFieldProps): ArrayFieldType['labels'] => {\n if ('labels' in p && p?.labels) return p.labels\n if ('label' in p && p?.label) return { plural: undefined, singular: p?.label }\n return { plural: t('general:rows'), singular: t('general:row') }\n }\n\n const labels = getLabels(props)\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number) => {\n await addFieldRow({ path, rowIndex, schemaPath })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'REMOVE_ROW', path, rowIndex })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && errorPaths.length > 0\n\n const showRequired = disabled && rows.length === 0\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__header-content`}>\n <h3 className={`${baseClass}__title`}>\n <FieldLabel\n CustomLabel={CustomLabel}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__draggable-rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const rowErrorCount = errorPaths?.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}.`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <ArrayRow\n {...draggableSortableItemProps}\n CustomRowLabel={CustomRowLabel}\n addRow={addRow}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n fieldMap={fieldMap}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n })}\n {!valid && (\n <React.Fragment>\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:rows' : 'general:row'),\n })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-row`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => addRow(value || 0)}\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n )}\n </div>\n )\n}\n\nexport const ArrayField = withCondition(_ArrayField)\n"],"names":["getTranslation","React","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","ErrorPill","FieldDescription","FieldError","FieldLabel","useFieldProps","useForm","useFormSubmitted","NullifyLocaleField","useField","withCondition","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","ArrayRow","baseClass","_ArrayField","props","name","CustomDescription","CustomError","CustomLabel","CustomRowLabel","className","descriptionProps","errorProps","fieldMap","forceRender","isSortable","label","labelProps","localized","maxRows","minRows","minRowsProp","path","pathFromProps","permissions","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","submitted","code","locale","i18n","t","localization","editingDefaultLocale","fallback","defaultLocale","getLabels","p","labels","plural","undefined","singular","memoizedValidate","value","options","pathFromContext","errorPaths","formInitializing","formProcessing","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showRequired","showMinRows","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","Fragment","buttonStyle","icon","iconPosition","iconStyle","ArrayField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,qBAAqB,QAAQ,kEAAiE;AACvG,SAASC,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,8BAA6B;AACvE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC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AAC0C,YAAY,CAACc,4BACb,KAAC9F;gBACCiI,aAAY;gBACZrG,WAAW,CAAC,EAAER,UAAU,SAAS,CAAC;gBAClC8G,MAAK;gBACLC,cAAa;gBACbC,WAAU;gBACVjB,SAAS,IAAMlC,OAAOZ,SAAS;0BAE9BZ,EAAE,mBAAmB;oBAAEvB,OAAOtC,eAAeoE,OAAOG,QAAQ,EAAEX;gBAAM;;;;AAK/E,EAAC;AAED,OAAO,MAAM6E,aAAazH,cAAcS,aAAY"}
@@ -72,7 +72,7 @@ const _BlocksField = (props)=>{
72
72
  const { path: pathFromContext } = useFieldProps();
73
73
  const { errorPaths, formInitializing, formProcessing, path, permissions, rows = [], schemaPath, showError, valid, value } = useField({
74
74
  hasRows: true,
75
- path: pathFromContext || pathFromProps || name,
75
+ path: pathFromContext ?? pathFromProps ?? name,
76
76
  validate: memoizedValidate
77
77
  });
78
78
  const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Blocks/index.tsx"],"sourcesContent":["'use client'\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { Fragment, useCallback } from 'react'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { DrawerToggler } from '../../elements/Drawer/index.js'\nimport { useDrawerSlug } from '../../elements/Drawer/useDrawerSlug.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { BlockRow } from './BlockRow.js'\nimport { BlocksDrawer } from './BlocksDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'blocks-field'\n\nimport type { FieldPermissions } from 'payload/auth'\nimport type { BlockField } from 'payload/types'\n\nimport type { ReducedBlock } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\n\nexport type BlocksFieldProps = FormFieldBase & {\n blocks?: ReducedBlock[]\n forceRender?: boolean\n isSortable?: boolean\n labels?: BlockField['labels']\n maxRows?: number\n minRows?: number\n name?: string\n permissions: FieldPermissions\n slug?: string\n width?: string\n}\n\nconst _BlocksField: React.FC<BlocksFieldProps> = (props) => {\n const { i18n, t } = useTranslation()\n\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n blocks,\n className,\n descriptionProps,\n errorProps,\n forceRender = false,\n isSortable = true,\n label,\n labelProps,\n labels: labelsFromProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const { code: locale } = useLocale()\n const { localization } = useConfig()\n const drawerSlug = useDrawerSlug('blocks-drawer')\n const submitted = useFormSubmitted()\n\n const labels = {\n plural: t('fields:blocks'),\n singular: t('fields:block'),\n ...labelsFromProps,\n }\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n permissions,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number, blockType: string) => {\n await addFieldRow({\n data: { blockType },\n path,\n rowIndex,\n schemaPath: `${schemaPath}.${blockType}`,\n })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({\n type: 'REMOVE_ROW',\n path,\n rowIndex,\n })\n\n setModified(true)\n },\n [path, dispatchFields, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && fieldErrorCount + (valid ? 0 : 1) > 0\n\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n const showRequired = disabled && rows.length === 0\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__heading-with-error`}>\n <h3>\n <FieldLabel\n CustomLabel={CustomLabel}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const { blockType } = row\n const blockToRender = blocks.find((block) => block.slug === blockType)\n\n if (blockToRender) {\n const rowErrorCount = errorPaths.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <BlockRow\n {...draggableSortableItemProps}\n addRow={addRow}\n block={blockToRender}\n blocks={blocks}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n }\n\n return null\n })}\n {!editingDefaultLocale && (\n <React.Fragment>\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:row' : 'general:rows'),\n })}\n </Banner>\n )}\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Fragment>\n <DrawerToggler className={`${baseClass}__drawer-toggler`} slug={drawerSlug}>\n <Button\n buttonStyle=\"icon-label\"\n el=\"span\"\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n </DrawerToggler>\n <BlocksDrawer\n addRow={addRow}\n addRowIndex={rows?.length || 0}\n blocks={blocks}\n drawerSlug={drawerSlug}\n labels={labels}\n />\n </Fragment>\n )}\n </div>\n )\n}\n\nexport const BlocksField = withCondition(_BlocksField)\n"],"names":["getTranslation","React","Fragment","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","DrawerToggler","useDrawerSlug","ErrorPill","useForm","useFormSubmitted","NullifyLocaleField","useField","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","BlockRow","BlocksDrawer","baseClass","FieldDescription","FieldError","FieldLabel","useFieldProps","withCondition","_BlocksField","props","i18n","t","name","CustomDescription","CustomError","CustomLabel","blocks","className","descriptionProps","errorProps","forceRender","isSortable","label","labelProps","labels","labelsFromProps","localized","maxRows","minRows","minRowsProp","path","pathFromProps","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","code","locale","localization","drawerSlug","submitted","plural","singular","editingDefaultLocale","fallback","defaultLocale","memoizedValidate","value","options","pathFromContext","errorPaths","formInitializing","formProcessing","permissions","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","blockType","data","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showMinRows","showRequired","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","blockToRender","find","block","slug","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","buttonStyle","el","icon","iconPosition","iconStyle","addRowIndex","BlocksField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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["../../../src/fields/Blocks/index.tsx"],"sourcesContent":["'use client'\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { Fragment, useCallback } from 'react'\n\nimport { Banner } from '../../elements/Banner/index.js'\nimport { Button } from '../../elements/Button/index.js'\nimport { DraggableSortableItem } from '../../elements/DraggableSortable/DraggableSortableItem/index.js'\nimport { DraggableSortable } from '../../elements/DraggableSortable/index.js'\nimport { DrawerToggler } from '../../elements/Drawer/index.js'\nimport { useDrawerSlug } from '../../elements/Drawer/useDrawerSlug.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useForm, useFormSubmitted } from '../../forms/Form/context.js'\nimport { NullifyLocaleField } from '../../forms/NullifyField/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { scrollToID } from '../../utilities/scrollToID.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { BlockRow } from './BlockRow.js'\nimport { BlocksDrawer } from './BlocksDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'blocks-field'\n\nimport type { FieldPermissions } from 'payload/auth'\nimport type { BlockField } from 'payload/types'\n\nimport type { ReducedBlock } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\n\nexport type BlocksFieldProps = FormFieldBase & {\n blocks?: ReducedBlock[]\n forceRender?: boolean\n isSortable?: boolean\n labels?: BlockField['labels']\n maxRows?: number\n minRows?: number\n name?: string\n permissions: FieldPermissions\n slug?: string\n width?: string\n}\n\nconst _BlocksField: React.FC<BlocksFieldProps> = (props) => {\n const { i18n, t } = useTranslation()\n\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n blocks,\n className,\n descriptionProps,\n errorProps,\n forceRender = false,\n isSortable = true,\n label,\n labelProps,\n labels: labelsFromProps,\n localized,\n maxRows,\n minRows: minRowsProp,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n validate,\n } = props\n\n const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()\n const minRows = minRowsProp ?? required ? 1 : 0\n\n const { setDocFieldPreferences } = useDocumentInfo()\n const { addFieldRow, dispatchFields, setModified } = useForm()\n const { code: locale } = useLocale()\n const { localization } = useConfig()\n const drawerSlug = useDrawerSlug('blocks-drawer')\n const submitted = useFormSubmitted()\n\n const labels = {\n plural: t('fields:blocks'),\n singular: t('fields:block'),\n ...labelsFromProps,\n }\n\n const editingDefaultLocale = (() => {\n if (localization && localization.fallback) {\n const defaultLocale = localization.defaultLocale || 'en'\n return locale === defaultLocale\n }\n\n return true\n })()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n // alternative locales can be null\n if (!editingDefaultLocale && value === null) {\n return true\n }\n if (typeof validate === 'function') {\n return validate(value, { ...options, maxRows, minRows, required })\n }\n },\n [maxRows, minRows, required, validate, editingDefaultLocale],\n )\n\n const { path: pathFromContext } = useFieldProps()\n\n const {\n errorPaths,\n formInitializing,\n formProcessing,\n path,\n permissions,\n rows = [],\n schemaPath,\n showError,\n valid,\n value,\n } = useField<number>({\n hasRows: true,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const addRow = useCallback(\n async (rowIndex: number, blockType: string) => {\n await addFieldRow({\n data: { blockType },\n path,\n rowIndex,\n schemaPath: `${schemaPath}.${blockType}`,\n })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [addFieldRow, path, setModified, schemaPath],\n )\n\n const duplicateRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({ type: 'DUPLICATE_ROW', path, rowIndex })\n setModified(true)\n\n setTimeout(() => {\n scrollToID(`${path}-row-${rowIndex + 1}`)\n }, 0)\n },\n [dispatchFields, path, setModified],\n )\n\n const removeRow = useCallback(\n (rowIndex: number) => {\n dispatchFields({\n type: 'REMOVE_ROW',\n path,\n rowIndex,\n })\n\n setModified(true)\n },\n [path, dispatchFields, setModified],\n )\n\n const moveRow = useCallback(\n (moveFromIndex: number, moveToIndex: number) => {\n dispatchFields({ type: 'MOVE_ROW', moveFromIndex, moveToIndex, path })\n setModified(true)\n },\n [dispatchFields, path, setModified],\n )\n\n const toggleCollapseAll = useCallback(\n (collapsed: boolean) => {\n dispatchFields({ type: 'SET_ALL_ROWS_COLLAPSED', collapsed, path, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const setCollapse = useCallback(\n (rowID: string, collapsed: boolean) => {\n dispatchFields({ type: 'SET_ROW_COLLAPSED', collapsed, path, rowID, setDocFieldPreferences })\n },\n [dispatchFields, path, setDocFieldPreferences],\n )\n\n const hasMaxRows = maxRows && rows.length >= maxRows\n\n const fieldErrorCount = errorPaths.length\n const fieldHasErrors = submitted && fieldErrorCount + (valid ? 0 : 1) > 0\n\n const showMinRows = rows.length < minRows || (required && rows.length === 0)\n const showRequired = disabled && rows.length === 0\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n fieldHasErrors ? `${baseClass}--has-error` : `${baseClass}--has-no-error`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path.replace(/\\./g, '__')}`}\n >\n {showError && <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />}\n <header className={`${baseClass}__header`}>\n <div className={`${baseClass}__header-wrap`}>\n <div className={`${baseClass}__heading-with-error`}>\n <h3>\n <FieldLabel\n CustomLabel={CustomLabel}\n as=\"span\"\n label={label}\n required={required}\n unstyled\n {...(labelProps || {})}\n />\n </h3>\n {fieldHasErrors && fieldErrorCount > 0 && (\n <ErrorPill count={fieldErrorCount} i18n={i18n} withMessage />\n )}\n </div>\n {rows.length > 0 && (\n <ul className={`${baseClass}__header-actions`}>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(true)}\n type=\"button\"\n >\n {t('fields:collapseAll')}\n </button>\n </li>\n <li>\n <button\n className={`${baseClass}__header-action`}\n onClick={() => toggleCollapseAll(false)}\n type=\"button\"\n >\n {t('fields:showAll')}\n </button>\n </li>\n </ul>\n )}\n </div>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </header>\n <NullifyLocaleField fieldValue={value} localized={localized} path={path} />\n {(rows.length > 0 || (!valid && (showRequired || showMinRows))) && (\n <DraggableSortable\n className={`${baseClass}__rows`}\n ids={rows.map((row) => row.id)}\n onDragEnd={({ moveFromIndex, moveToIndex }) => moveRow(moveFromIndex, moveToIndex)}\n >\n {rows.map((row, i) => {\n const { blockType } = row\n const blockToRender = blocks.find((block) => block.slug === blockType)\n\n if (blockToRender) {\n const rowErrorCount = errorPaths.filter((errorPath) =>\n errorPath.startsWith(`${path}.${i}`),\n ).length\n return (\n <DraggableSortableItem disabled={disabled || !isSortable} id={row.id} key={row.id}>\n {(draggableSortableItemProps) => (\n <BlockRow\n {...draggableSortableItemProps}\n addRow={addRow}\n block={blockToRender}\n blocks={blocks}\n duplicateRow={duplicateRow}\n errorCount={rowErrorCount}\n forceRender={forceRender}\n hasMaxRows={hasMaxRows}\n indexPath={indexPath}\n isSortable={isSortable}\n labels={labels}\n moveRow={moveRow}\n path={path}\n permissions={permissions}\n readOnly={disabled}\n removeRow={removeRow}\n row={row}\n rowCount={rows.length}\n rowIndex={i}\n schemaPath={schemaPath}\n setCollapse={setCollapse}\n />\n )}\n </DraggableSortableItem>\n )\n }\n\n return null\n })}\n {!editingDefaultLocale && (\n <React.Fragment>\n {showMinRows && (\n <Banner type=\"error\">\n {t('validation:requiresAtLeast', {\n count: minRows,\n label:\n getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||\n t(minRows > 1 ? 'general:row' : 'general:rows'),\n })}\n </Banner>\n )}\n {showRequired && (\n <Banner>\n {t('validation:fieldHasNo', { label: getTranslation(labels.plural, i18n) })}\n </Banner>\n )}\n </React.Fragment>\n )}\n </DraggableSortable>\n )}\n {!disabled && !hasMaxRows && (\n <Fragment>\n <DrawerToggler className={`${baseClass}__drawer-toggler`} slug={drawerSlug}>\n <Button\n buttonStyle=\"icon-label\"\n el=\"span\"\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n >\n {t('fields:addLabel', { label: getTranslation(labels.singular, i18n) })}\n </Button>\n </DrawerToggler>\n <BlocksDrawer\n addRow={addRow}\n addRowIndex={rows?.length || 0}\n blocks={blocks}\n drawerSlug={drawerSlug}\n labels={labels}\n />\n </Fragment>\n )}\n </div>\n )\n}\n\nexport const BlocksField = withCondition(_BlocksField)\n"],"names":["getTranslation","React","Fragment","useCallback","Banner","Button","DraggableSortableItem","DraggableSortable","DrawerToggler","useDrawerSlug","ErrorPill","useForm","useFormSubmitted","NullifyLocaleField","useField","useConfig","useDocumentInfo","useLocale","useTranslation","scrollToID","fieldBaseClass","BlockRow","BlocksDrawer","baseClass","FieldDescription","FieldError","FieldLabel","useFieldProps","withCondition","_BlocksField","props","i18n","t","name","CustomDescription","CustomError","CustomLabel","blocks","className","descriptionProps","errorProps","forceRender","isSortable","label","labelProps","labels","labelsFromProps","localized","maxRows","minRows","minRowsProp","path","pathFromProps","readOnly","readOnlyFromProps","required","validate","indexPath","readOnlyFromContext","setDocFieldPreferences","addFieldRow","dispatchFields","setModified","code","locale","localization","drawerSlug","submitted","plural","singular","editingDefaultLocale","fallback","defaultLocale","memoizedValidate","value","options","pathFromContext","errorPaths","formInitializing","formProcessing","permissions","rows","schemaPath","showError","valid","hasRows","disabled","addRow","rowIndex","blockType","data","setTimeout","duplicateRow","type","removeRow","moveRow","moveFromIndex","moveToIndex","toggleCollapseAll","collapsed","setCollapse","rowID","hasMaxRows","length","fieldErrorCount","fieldHasErrors","showMinRows","showRequired","div","filter","Boolean","join","id","replace","header","h3","as","unstyled","count","withMessage","ul","li","button","onClick","fieldValue","ids","map","row","onDragEnd","i","blockToRender","find","block","slug","rowErrorCount","errorPath","startsWith","draggableSortableItemProps","errorCount","rowCount","buttonStyle","el","icon","iconPosition","iconStyle","addRowIndex","BlocksField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,QAAQ,EAAEC,WAAW,QAAQ,QAAO;AAEpD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,qBAAqB,QAAQ,kEAAiE;AACvG,SAASC,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,aAAa,QAAQ,iCAAgC;AAC9D,SAASC,aAAa,QAAQ,yCAAwC;AACtE,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,OAAO,EAAEC,gBAAgB,QAAQ,8BAA6B;AACvE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SA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AU,IAAI,gBAAgB;gCACpC;;4BAGH0D,8BACC,KAACvG;0CACE4B,EAAE,yBAAyB;oCAAEW,OAAO3C,eAAe6C,OAAOuB,MAAM,EAAErC;gCAAM;;;;;;YAOpF,CAACuD,YAAY,CAACgB,4BACb,MAACpG;;kCACC,KAACM;wBAAc8B,WAAW,CAAC,EAAEf,UAAU,gBAAgB,CAAC;wBAAE8G,MAAMnE;kCAC9D,cAAA,KAAC7D;4BACCuI,aAAY;4BACZC,IAAG;4BACHC,MAAK;4BACLC,cAAa;4BACbC,WAAU;sCAEThH,EAAE,mBAAmB;gCAAEW,OAAO3C,eAAe6C,OAAOwB,QAAQ,EAAEtC;4BAAM;;;kCAGzE,KAACT;wBACCiE,QAAQA;wBACR0D,aAAahE,MAAMsB,UAAU;wBAC7BlE,QAAQA;wBACR6B,YAAYA;wBACZrB,QAAQA;;;;;;AAMpB;AAEA,OAAO,MAAMqG,cAActH,cAAcC,cAAa"}
@@ -31,7 +31,7 @@ const CheckboxField = (props)=>{
31
31
  const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
32
32
  const { formInitializing, formProcessing, path, setValue, showError, value } = useField({
33
33
  disableFormData,
34
- path: pathFromContext || pathFromProps || name,
34
+ path: pathFromContext ?? pathFromProps ?? name,
35
35
  validate: memoizedValidate
36
36
  });
37
37
  const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/Checkbox/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientValidate } from 'payload/types'\n\nimport React, { useCallback } from 'react'\n\nimport type { CheckboxInputProps } from './Input.js'\nimport type { CheckboxFieldProps } from './types.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm } from '../../forms/Form/context.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useEditDepth } from '../../providers/EditDepth/index.js'\nimport { generateFieldID } from '../../utilities/generateFieldID.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { CheckboxInput } from './Input.js'\nimport './index.scss'\n\nconst baseClass = 'checkbox'\n\nexport { CheckboxFieldProps, CheckboxInput, type CheckboxInputProps }\n\nconst CheckboxField: React.FC<CheckboxFieldProps> = (props) => {\n const {\n id,\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n checked: checkedFromProps,\n className,\n descriptionProps,\n disableFormData,\n errorProps,\n label,\n labelProps,\n onChange: onChangeFromProps,\n partialChecked,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const { uuid } = useForm()\n\n const editDepth = useEditDepth()\n\n const memoizedValidate: ClientValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField({\n disableFormData,\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const onToggle = useCallback(() => {\n if (!disabled) {\n setValue(!value)\n if (typeof onChangeFromProps === 'function') onChangeFromProps(!value)\n }\n }, [onChangeFromProps, disabled, setValue, value])\n\n const checked = checkedFromProps || Boolean(value)\n\n const fieldID = id || generateFieldID(path, editDepth, uuid)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n showError && 'error',\n className,\n value && `${baseClass}--checked`,\n disabled && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n <CheckboxInput\n AfterInput={AfterInput}\n BeforeInput={BeforeInput}\n CustomLabel={CustomLabel}\n checked={checked}\n id={fieldID}\n inputRef={null}\n label={label}\n labelProps={labelProps}\n name={path}\n onToggle={onToggle}\n partialChecked={partialChecked}\n readOnly={disabled}\n required={required}\n />\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n )\n}\n\nexport const Checkbox = withCondition(CheckboxField)\n"],"names":["React","useCallback","FieldDescription","FieldError","useFieldProps","useForm","useField","withCondition","useEditDepth","generateFieldID","fieldBaseClass","CheckboxInput","baseClass","CheckboxField","props","id","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","checked","checkedFromProps","className","descriptionProps","disableFormData","errorProps","label","labelProps","onChange","onChangeFromProps","partialChecked","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","width","uuid","editDepth","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","onToggle","Boolean","fieldID","div","filter","join","inputRef","undefined","Checkbox"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,OAAOA,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,OAAO,QAAQ,8BAA6B;AACrD,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,aAAa,QAAQ,aAAY;AAG1C,MAAMC,YAAY;AAElB,SAA6BD,aAAa,GAA2B;AAErE,MAAME,gBAA8C,CAACC;IACnD,MAAM,EACJC,EAAE,EACFC,IAAI,E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ChCwC,YAAY,CAAC,EAAExC,UAAU,WAAW,CAAC;SACtC,CACE6C,MAAM,CAACH,SACPI,IAAI,CAAC;QACRpB,OAAO;YACL,GAAGA,KAAK;YACRE;QACF;;0BAEA,KAACrC;gBAAWiB,aAAaA;gBAAaa,MAAMA;gBAAO,GAAIN,cAAc,CAAC,CAAC;;0BACvE,KAAChB;gBACCM,YAAYA;gBACZC,aAAaA;gBACbG,aAAaA;gBACbC,SAASA;gBACTP,IAAIwC;gBACJI,UAAU;gBACV/B,OAAOA;gBACPC,YAAYA;gBACZb,MAAMiB;gBACNoB,UAAUA;gBACVrB,gBAAgBA;gBAChBG,UAAUiB;gBACVf,UAAUA;;YAEXlB,sBAAsByC,YACrBzC,kCAEA,KAACjB;gBAAkB,GAAIuB,oBAAoB,CAAC,CAAC;;;;AAIrD;AAEA,OAAO,MAAMoC,WAAWtD,cAAcM,eAAc"}
1
+ {"version":3,"sources":["../../../src/fields/Checkbox/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientValidate } from 'payload/types'\n\nimport React, { useCallback } from 'react'\n\nimport type { CheckboxInputProps } from './Input.js'\nimport type { CheckboxFieldProps } from './types.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useForm } from '../../forms/Form/context.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useEditDepth } from '../../providers/EditDepth/index.js'\nimport { generateFieldID } from '../../utilities/generateFieldID.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { CheckboxInput } from './Input.js'\nimport './index.scss'\n\nconst baseClass = 'checkbox'\n\nexport { CheckboxFieldProps, CheckboxInput, type CheckboxInputProps }\n\nconst CheckboxField: React.FC<CheckboxFieldProps> = (props) => {\n const {\n id,\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n checked: checkedFromProps,\n className,\n descriptionProps,\n disableFormData,\n errorProps,\n label,\n labelProps,\n onChange: onChangeFromProps,\n partialChecked,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const { uuid } = useForm()\n\n const editDepth = useEditDepth()\n\n const memoizedValidate: ClientValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, required })\n }\n },\n [validate, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField({\n disableFormData,\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const onToggle = useCallback(() => {\n if (!disabled) {\n setValue(!value)\n if (typeof onChangeFromProps === 'function') onChangeFromProps(!value)\n }\n }, [onChangeFromProps, disabled, setValue, value])\n\n const checked = checkedFromProps || Boolean(value)\n\n const fieldID = id || generateFieldID(path, editDepth, uuid)\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n showError && 'error',\n className,\n value && `${baseClass}--checked`,\n disabled && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n <CheckboxInput\n AfterInput={AfterInput}\n BeforeInput={BeforeInput}\n CustomLabel={CustomLabel}\n checked={checked}\n id={fieldID}\n inputRef={null}\n label={label}\n labelProps={labelProps}\n name={path}\n onToggle={onToggle}\n partialChecked={partialChecked}\n readOnly={disabled}\n required={required}\n />\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n )\n}\n\nexport const Checkbox = withCondition(CheckboxField)\n"],"names":["React","useCallback","FieldDescription","FieldError","useFieldProps","useForm","useField","withCondition","useEditDepth","generateFieldID","fieldBaseClass","CheckboxInput","baseClass","CheckboxField","props","id","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","checked","checkedFromProps","className","descriptionProps","disableFormData","errorProps","label","labelProps","onChange","onChangeFromProps","partialChecked","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","width","uuid","editDepth","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","onToggle","Boolean","fieldID","div","filter","join","inputRef","undefined","Checkbox"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,OAAOA,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,OAAO,QAAQ,8BAA6B;AACrD,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,aAAa,QAAQ,aAAY;AAG1C,MAAMC,YAAY;AAElB,SAA6BD,aAAa,GAA2B;AAErE,MAAME,gBAA8C,CAACC;IACnD,MAAM,EACJC,EAAE,EACFC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAASC,gBAAgB,EACzBC,SAAS,EACTC,gBAAgB,EAChBC,eAAe,EACfC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,UAAUC,iBAAiB,EAC3BC,cAAc,EACdC,MAAMC,aAAa,EACnBC,UAAUC,iBAAiB,EAC3BC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACN,GAAG1B;IAEJ,MAAM,EAAE2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A;gBACPC,YAAYA;gBACZb,MAAMiB;gBACNoB,UAAUA;gBACVrB,gBAAgBA;gBAChBG,UAAUiB;gBACVf,UAAUA;;YAEXlB,sBAAsByC,YACrBzC,kCAEA,KAACjB;gBAAkB,GAAIuB,oBAAoB,CAAC,CAAC;;;;AAIrD;AAEA,OAAO,MAAMoC,WAAWtD,cAAcM,eAAc"}
@@ -29,7 +29,7 @@ const CodeField = (props)=>{
29
29
  ]);
30
30
  const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
31
31
  const { formInitializing, formProcessing, path, setValue, showError, value } = useField({
32
- path: pathFromContext || pathFromProps || name,
32
+ path: pathFromContext ?? pathFromProps ?? name,
33
33
  validate: memoizedValidate
34
34
  });
35
35
  const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;