@payloadcms/ui 3.0.0-beta.55 → 3.0.0-beta.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/DatePicker/DatePicker.d.ts +2 -2
- package/dist/elements/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/elements/DatePicker/DatePicker.js +2 -2
- package/dist/elements/DatePicker/DatePicker.js.map +1 -1
- package/dist/elements/DeleteDocument/index.scss +1 -0
- package/dist/elements/DeleteMany/index.scss +1 -0
- package/dist/elements/FieldSelect/index.d.ts +7 -2
- package/dist/elements/FieldSelect/index.d.ts.map +1 -1
- package/dist/elements/FieldSelect/index.js +1 -1
- package/dist/elements/FieldSelect/index.js.map +1 -1
- package/dist/elements/HydrateClientUser/index.d.ts +2 -2
- package/dist/elements/HydrateClientUser/index.d.ts.map +1 -1
- package/dist/elements/HydrateClientUser/index.js.map +1 -1
- package/dist/elements/ListControls/index.d.ts.map +1 -1
- package/dist/elements/ListControls/index.js +2 -1
- package/dist/elements/ListControls/index.js.map +1 -1
- package/dist/elements/SaveDraftButton/index.d.ts +1 -0
- package/dist/elements/SaveDraftButton/index.d.ts.map +1 -1
- package/dist/elements/SaveDraftButton/index.js +1 -1
- package/dist/elements/SaveDraftButton/index.js.map +1 -1
- package/dist/elements/Upload/index.d.ts.map +1 -1
- package/dist/elements/Upload/index.js +1 -0
- package/dist/elements/Upload/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/index.js +1 -1
- package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
- package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/index.js +8 -7
- package/dist/elements/WhereBuilder/index.js.map +1 -1
- package/dist/elements/WhereBuilder/reduceFieldMap.d.ts +2 -2
- package/dist/elements/WhereBuilder/reduceFieldMap.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/reduceFieldMap.js +34 -16
- package/dist/elements/WhereBuilder/reduceFieldMap.js.map +1 -1
- package/dist/elements/WhereBuilder/types.d.ts +2 -0
- package/dist/elements/WhereBuilder/types.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/types.js.map +1 -1
- package/dist/exports/client/DatePicker-BN5AOAME.js +14 -0
- package/dist/exports/client/DatePicker-BN5AOAME.js.map +8 -0
- package/dist/exports/client/chunk-3X2D2TP2.js +30 -0
- package/dist/exports/client/chunk-3X2D2TP2.js.map +8 -0
- package/dist/exports/client/index.d.ts +6 -3
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +6 -6
- package/dist/exports/client/index.js.map +4 -4
- package/dist/forms/Form/index.js +2 -2
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.d.ts +2 -2
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.js.map +1 -1
- package/dist/forms/buildStateFromSchema/index.d.ts +4 -3
- package/dist/forms/buildStateFromSchema/index.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/index.js +1 -0
- package/dist/forms/buildStateFromSchema/index.js.map +1 -1
- package/dist/forms/buildStateFromSchema/iterateFields.d.ts +2 -2
- package/dist/forms/buildStateFromSchema/iterateFields.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/iterateFields.js.map +1 -1
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js +2 -1
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/collections.js +4 -4
- package/dist/providers/ComponentMap/buildComponentMap/collections.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.js +2 -5
- package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts +1 -2
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js +7 -11
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts +4 -4
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js.map +1 -1
- package/package.json +5 -5
- package/dist/exports/client/DatePicker-CBQPW5J5.js +0 -30
- package/dist/exports/client/DatePicker-CBQPW5J5.js.map +0 -8
- package/dist/exports/client/chunk-DODCWLCH.js +0 -14
- package/dist/exports/client/chunk-DODCWLCH.js.map +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/elements/WhereBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { Operator } from 'payload'\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"],"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;AAChD,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C1Bd,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'\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 { useLocale } from '../../providers/Locale/index.js'\nimport { useSearchParams } from '../../providers/SearchParams/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/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, fieldMap } = props\n const { i18n, t } = useTranslation()\n const { code: currentLocale } = useLocale()\n\n const [reducedFields, setReducedColumns] = useState(() => reduceFieldMap(fieldMap, i18n))\n\n useEffect(() => {\n setReducedColumns(reduceFieldMap(fieldMap, i18n, undefined, undefined, currentLocale))\n }, [fieldMap, i18n, currentLocale])\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 // 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","useLocale","useSearchParams","useTranslation","Button","Condition","reduceFieldMap","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","collectionPluralLabel","fieldMap","i18n","t","code","currentLocale","reducedFields","setReducedColumns","undefined","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","includes","removeCondition","length","div","className","Fragment","label","ul","map","compoundOrKey","Array","isArray","li","_","initialFieldName","Object","keys","initialOperator","initialValue","fields","buttonStyle","icon","iconPosition","iconStyle","onClick"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAIlD,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,MAAM,QAAQ,qBAAoB;AAC3C,SAASC,SAAS,QAAQ,uBAAsB;AAChD,OAAO,eAAc;AACrB,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,EAAEC,QAAQ,EAAE,GAAGF;IAC5C,MAAM,EAAEG,IAAI,EAAEC,CAAC,EA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mBACZ,KAACiB;wDAAIC,WAAW,CAAC,EAAE9C,UAAU,OAAO,CAAC;kEAAGM,EAAE;;kEAE5C,KAACV;wDACC8B,cAAcA;wDACdE,UAAUA;wDACVC,WAAW2B;wDACXK,QAAQpD;wDACRmD,cAAcA;wDACdvB,UAAUsB;wDACV7B,SAASA;wDACTa,iBAAiBA;wDACjBP,iBAAiBA;;;+CAbZR;wCAiBb;;;+BAjCGuB;wBAqCb;;kCAEF,KAACxD;wBACCmE,aAAY;wBACZhB,WAAW,CAAC,EAAE9C,UAAU,QAAQ,CAAC;wBACjC+D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACPxC,aAAa;gCACXE,UAAU;gCACVC,WAAWpB,aAAa,CAAC,EAAE,CAAC6B,KAAK;gCACjCR,SAASd,WAAW4B,MAAM;gCAC1Bb,UAAU;4BACZ;wBACF;kCAECzB,EAAE;;;;YAIRU,WAAW4B,MAAM,KAAK,mBACrB,MAACC;gBAAIC,WAAW,CAAC,EAAE9C,UAAU,YAAY,CAAC;;kCACxC,KAAC6C;wBAAIC,WAAW,CAAC,EAAE9C,UAAU,OAAO,CAAC;kCAAGM,EAAE;;kCAC1C,KAACX;wBACCmE,aAAY;wBACZhB,WAAW,CAAC,EAAE9C,UAAU,kBAAkB,CAAC;wBAC3C+D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACP,IAAIzD,cAAcmC,MAAM,GAAG,GAAG;gCAC5BlB,aAAa;oCACXE,UAAU;oCACVC,WAAWpB,aAAa,CAAC,EAAE,CAAC6B,KAAK;oCACjCR,SAASd,WAAW4B,MAAM;oCAC1Bb,UAAU;gCACZ;4BACF;wBACF;kCAECzB,EAAE;;;;;;AAMf,EAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const reduceFieldMap: (fieldMap:
|
|
1
|
+
import type { FieldMap } from '../../utilities/buildComponentMap.js';
|
|
2
|
+
export declare const reduceFieldMap: (fieldMap: FieldMap, i18n: any, labelPrefix?: string, pathPrefix?: string, locale?: string) => any[];
|
|
3
3
|
//# sourceMappingURL=reduceFieldMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduceFieldMap.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"reduceFieldMap.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAMpE,eAAO,MAAM,cAAc,aACf,QAAQ,2BAEJ,MAAM,eACP,MAAM,WACV,MAAM,UAyEhB,CAAA"}
|
|
@@ -1,38 +1,56 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { createNestedClientFieldPath } from '../../forms/Form/createNestedFieldPath.js';
|
|
3
|
+
import { combineLabel } from '../FieldSelect/index.js';
|
|
2
4
|
import fieldTypes from './field-types.js';
|
|
3
|
-
export const reduceFieldMap = (fieldMap, i18n
|
|
5
|
+
export const reduceFieldMap = (fieldMap, i18n, labelPrefix, pathPrefix, locale)=>{
|
|
6
|
+
return fieldMap.reduce((reduced, field)=>{
|
|
7
|
+
if (field.disableListFilter) return reduced;
|
|
8
|
+
if (field.type === 'tabs' && 'tabs' in field.fieldComponentProps) {
|
|
9
|
+
const tabs = field.fieldComponentProps.tabs;
|
|
10
|
+
tabs.forEach((tab)=>{
|
|
11
|
+
if (tab.name && typeof tab.label === 'string' && tab.fieldMap) {
|
|
12
|
+
reduced.push(...reduceFieldMap(tab.fieldMap, i18n, tab.label, tab.name));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return reduced;
|
|
16
|
+
}
|
|
17
|
+
if (field.type === 'group' && 'fieldMap' in field.fieldComponentProps) {
|
|
18
|
+
reduced.push(...reduceFieldMap(field.fieldComponentProps.fieldMap, i18n, field.fieldComponentProps.label, field.name));
|
|
19
|
+
return reduced;
|
|
20
|
+
}
|
|
4
21
|
if (typeof fieldTypes[field.type] === 'object') {
|
|
5
22
|
const operatorKeys = new Set();
|
|
6
23
|
const operators = fieldTypes[field.type].operators.reduce((acc, operator)=>{
|
|
7
24
|
if (!operatorKeys.has(operator.value)) {
|
|
8
25
|
operatorKeys.add(operator.value);
|
|
9
|
-
|
|
10
|
-
...
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
label: i18n.t(`operators:${operator.label}`)
|
|
14
|
-
}
|
|
15
|
-
];
|
|
26
|
+
acc.push({
|
|
27
|
+
...operator,
|
|
28
|
+
label: i18n.t(`operators:${operator.label}`)
|
|
29
|
+
});
|
|
16
30
|
}
|
|
17
31
|
return acc;
|
|
18
32
|
}, []);
|
|
33
|
+
const localizedLabel = locale && typeof field.fieldComponentProps.label === 'object' ? field.fieldComponentProps.label[locale] : field.fieldComponentProps.label;
|
|
34
|
+
const formattedLabel = labelPrefix ? combineLabel({
|
|
35
|
+
field,
|
|
36
|
+
prefix: labelPrefix
|
|
37
|
+
}) : localizedLabel;
|
|
38
|
+
const formattedValue = pathPrefix ? createNestedClientFieldPath(pathPrefix, field) : field.name;
|
|
19
39
|
const formattedField = {
|
|
20
|
-
label:
|
|
21
|
-
value:
|
|
40
|
+
label: formattedLabel,
|
|
41
|
+
value: formattedValue,
|
|
22
42
|
...fieldTypes[field.type],
|
|
23
43
|
operators,
|
|
24
44
|
props: {
|
|
25
45
|
...field,
|
|
26
|
-
...field?.
|
|
46
|
+
...field?.cellComponentProps || {}
|
|
27
47
|
}
|
|
28
48
|
};
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
...reduced,
|
|
32
|
-
formattedField
|
|
33
|
-
];
|
|
49
|
+
reduced.push(formattedField);
|
|
50
|
+
return reduced;
|
|
34
51
|
}
|
|
35
52
|
return reduced;
|
|
36
53
|
}, []);
|
|
54
|
+
};
|
|
37
55
|
|
|
38
56
|
//# sourceMappingURL=reduceFieldMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"sourcesContent":["'use client'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"sourcesContent":["'use client'\nimport type { FieldMap } from '../../utilities/buildComponentMap.js'\n\nimport { createNestedClientFieldPath } from '../../forms/Form/createNestedFieldPath.js'\nimport { combineLabel } from '../FieldSelect/index.js'\nimport fieldTypes from './field-types.js'\n\nexport const reduceFieldMap = (\n fieldMap: FieldMap,\n i18n,\n labelPrefix?: string,\n pathPrefix?: string,\n locale?: string,\n) => {\n return fieldMap.reduce((reduced, field) => {\n if (field.disableListFilter) return reduced\n\n if (field.type === 'tabs' && 'tabs' in field.fieldComponentProps) {\n const tabs = field.fieldComponentProps.tabs\n tabs.forEach((tab) => {\n if (tab.name && typeof tab.label === 'string' && tab.fieldMap) {\n reduced.push(...reduceFieldMap(tab.fieldMap, i18n, tab.label, tab.name))\n }\n })\n return reduced\n }\n\n if (field.type === 'group' && 'fieldMap' in field.fieldComponentProps) {\n reduced.push(\n ...reduceFieldMap(\n field.fieldComponentProps.fieldMap,\n i18n,\n field.fieldComponentProps.label as string,\n field.name,\n ),\n )\n return reduced\n }\n\n if (typeof fieldTypes[field.type] === 'object') {\n const operatorKeys = new Set()\n const operators = fieldTypes[field.type].operators.reduce((acc, operator) => {\n if (!operatorKeys.has(operator.value)) {\n operatorKeys.add(operator.value)\n acc.push({\n ...operator,\n label: i18n.t(`operators:${operator.label}`),\n })\n }\n return acc\n }, [])\n\n const localizedLabel =\n locale && typeof field.fieldComponentProps.label === 'object'\n ? field.fieldComponentProps.label[locale]\n : field.fieldComponentProps.label\n\n const formattedLabel = labelPrefix\n ? combineLabel({\n field,\n prefix: labelPrefix,\n })\n : localizedLabel\n\n const formattedValue = pathPrefix\n ? createNestedClientFieldPath(pathPrefix, field)\n : field.name\n\n const formattedField = {\n label: formattedLabel,\n value: formattedValue,\n ...fieldTypes[field.type],\n operators,\n props: {\n ...field,\n ...(field?.cellComponentProps || {}),\n },\n }\n\n reduced.push(formattedField)\n return reduced\n }\n\n return reduced\n }, [])\n}\n"],"names":["createNestedClientFieldPath","combineLabel","fieldTypes","reduceFieldMap","fieldMap","i18n","labelPrefix","pathPrefix","locale","reduce","reduced","field","disableListFilter","type","fieldComponentProps","tabs","forEach","tab","name","label","push","operatorKeys","Set","operators","acc","operator","has","value","add","t","localizedLabel","formattedLabel","prefix","formattedValue","formattedField","props","cellComponentProps"],"mappings":"AAAA;AAGA,SAASA,2BAA2B,QAAQ,4CAA2C;AACvF,SAASC,YAAY,QAAQ,0BAAyB;AACtD,OAAOC,gBAAgB,mBAAkB;AAEzC,OAAO,MAAMC,iBAAiB,CAC5BC,UACAC,MACAC,aACAC,YACAC;IAEA,OAAOJ,SAASK,MAAM,CAAC,CAACC,SAASC;QAC/B,IAAIA,MAAMC,iBAAiB,EAAE,OAAOF;QAEpC,IAAIC,MAAME,IAAI,KAAK,UAAU,UAAUF,MAAMG,mBAAmB,EAAE;YAChE,MAAMC,OAAOJ,MAAMG,mBAAmB,CAACC,IAAI;YAC3CA,KAAKC,OAAO,CAAC,CAACC;gBACZ,IAAIA,IAAIC,IAAI,IAAI,OAAOD,IAAIE,KAAK,KAAK,YAAYF,IAAIb,QAAQ,EAAE;oBAC7DM,QAAQU,IAAI,IAAIjB,eAAec,IAAIb,QAAQ,EAAEC,MAAMY,IAAIE,KAAK,EAAEF,IAAIC,IAAI;gBACxE;YACF;YACA,OAAOR;QACT;QAEA,IAAIC,MAAME,IAAI,KAAK,WAAW,cAAcF,MAAMG,mBAAmB,EAAE;YACrEJ,QAAQU,IAAI,IACPjB,eACDQ,MAAMG,mBAAmB,CAACV,QAAQ,EAClCC,MACAM,MAAMG,mBAAmB,CAACK,KAAK,EAC/BR,MAAMO,IAAI;YAGd,OAAOR;QACT;QAEA,IAAI,OAAOR,UAAU,CAACS,MAAME,IAAI,CAAC,KAAK,UAAU;YAC9C,MAAMQ,eAAe,IAAIC;YACzB,MAAMC,YAAYrB,UAAU,CAACS,MAAME,IAAI,CAAC,CAACU,SAAS,CAACd,MAAM,CAAC,CAACe,KAAKC;gBAC9D,IAAI,CAACJ,aAAaK,GAAG,CAACD,SAASE,KAAK,GAAG;oBACrCN,aAAaO,GAAG,CAACH,SAASE,KAAK;oBAC/BH,IAAIJ,IAAI,CAAC;wBACP,GAAGK,QAAQ;wBACXN,OAAOd,KAAKwB,CAAC,CAAC,CAAC,UAAU,EAAEJ,SAASN,KAAK,CAAC,CAAC;oBAC7C;gBACF;gBACA,OAAOK;YACT,GAAG,EAAE;YAEL,MAAMM,iBACJtB,UAAU,OAAOG,MAAMG,mBAAmB,CAACK,KAAK,KAAK,WACjDR,MAAMG,mBAAmB,CAACK,KAAK,CAACX,OAAO,GACvCG,MAAMG,mBAAmB,CAACK,KAAK;YAErC,MAAMY,iBAAiBzB,cACnBL,aAAa;gBACXU;gBACAqB,QAAQ1B;YACV,KACAwB;YAEJ,MAAMG,iBAAiB1B,aACnBP,4BAA4BO,YAAYI,SACxCA,MAAMO,IAAI;YAEd,MAAMgB,iBAAiB;gBACrBf,OAAOY;gBACPJ,OAAOM;gBACP,GAAG/B,UAAU,CAACS,MAAME,IAAI,CAAC;gBACzBU;gBACAY,OAAO;oBACL,GAAGxB,KAAK;oBACR,GAAIA,OAAOyB,sBAAsB,CAAC,CAAC;gBACrC;YACF;YAEA1B,QAAQU,IAAI,CAACc;YACb,OAAOxB;QACT;QAEA,OAAOA;IACT,GAAG,EAAE;AACP,EAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Field, Operator, SanitizedCollectionConfig, Where } from 'payload';
|
|
2
|
+
import type { FieldMap } from '../../utilities/buildComponentMap.js';
|
|
2
3
|
export type WhereBuilderProps = {
|
|
3
4
|
collectionPluralLabel: SanitizedCollectionConfig['labels']['plural'];
|
|
4
5
|
collectionSlug: SanitizedCollectionConfig['slug'];
|
|
6
|
+
fieldMap?: FieldMap;
|
|
5
7
|
};
|
|
6
8
|
export type FieldCondition = {
|
|
7
9
|
component?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEhF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,qBAAqB,EAAE,yBAAyB,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAA;IACpE,cAAc,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEhF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAEpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,qBAAqB,EAAE,yBAAyB,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAA;IACpE,cAAc,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACjD,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE;QACT,KAAK,EAAE,MAAM,CAAA;QACb,KAAK,EAAE,QAAQ,CAAA;KAChB,EAAE,CAAA;IACH,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAA;AAEnC,MAAM,MAAM,GAAG,GAAG;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,IAAI,EAAE,KAAK,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,QAAQ,CAAA;CACf,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,GAAG,GAAG,MAAM,GAAG,MAAM,CAAA;AAE1C,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,KAAK,EAAE,CAAA;CACZ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/elements/WhereBuilder/types.ts"],"sourcesContent":["import type { Field, Operator, SanitizedCollectionConfig, Where } from 'payload'\n\nexport type WhereBuilderProps = {\n collectionPluralLabel: SanitizedCollectionConfig['labels']['plural']\n collectionSlug: SanitizedCollectionConfig['slug']\n}\n\nexport type FieldCondition = {\n component?: string\n label: string\n operators: {\n label: string\n value: Operator\n }[]\n props: Field\n value: string\n}\n\nexport type Relation = 'and' | 'or'\n\nexport type ADD = {\n andIndex?: number\n field: string\n orIndex?: number\n relation?: Relation\n type: 'add'\n}\n\nexport type REMOVE = {\n andIndex: number\n orIndex: number\n type: 'remove'\n}\n\nexport type UPDATE = {\n andIndex: number\n field?: string\n operator?: string\n orIndex: number\n type: 'update'\n value?: unknown\n}\n\nexport type Action = ADD | REMOVE | UPDATE\n\nexport type State = {\n or: Where[]\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/elements/WhereBuilder/types.ts"],"sourcesContent":["import type { Field, Operator, SanitizedCollectionConfig, Where } from 'payload'\n\nimport type { FieldMap } from '../../utilities/buildComponentMap.js'\n\nexport type WhereBuilderProps = {\n collectionPluralLabel: SanitizedCollectionConfig['labels']['plural']\n collectionSlug: SanitizedCollectionConfig['slug']\n fieldMap?: FieldMap\n}\n\nexport type FieldCondition = {\n component?: string\n label: string\n operators: {\n label: string\n value: Operator\n }[]\n props: Field\n value: string\n}\n\nexport type Relation = 'and' | 'or'\n\nexport type ADD = {\n andIndex?: number\n field: string\n orIndex?: number\n relation?: Relation\n type: 'add'\n}\n\nexport type REMOVE = {\n andIndex: number\n orIndex: number\n type: 'remove'\n}\n\nexport type UPDATE = {\n andIndex: number\n field?: string\n operator?: string\n orIndex: number\n type: 'update'\n value?: unknown\n}\n\nexport type Action = ADD | REMOVE | UPDATE\n\nexport type State = {\n or: Where[]\n}\n"],"names":[],"mappings":"AAgDA,WAEC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// Workaround for react-datepicker and other cjs dependencies potentially inserting require("react") statements
|
|
3
|
+
import * as requireReact from 'react';
|
|
4
|
+
import * as requireReactDom from 'react-dom';
|
|
5
|
+
|
|
6
|
+
function require(m) {
|
|
7
|
+
if (m === 'react') return requireReact;
|
|
8
|
+
if (m === 'react-dom') return requireReactDom;
|
|
9
|
+
throw new Error(`Unknown module ${m}`);
|
|
10
|
+
}
|
|
11
|
+
// Workaround end
|
|
12
|
+
|
|
13
|
+
import{j as a}from"./chunk-3X2D2TP2.js";import"./chunk-5LKBKI4T.js";export{a as default};
|
|
14
|
+
//# sourceMappingURL=DatePicker-BN5AOAME.js.map
|