@payloadcms/ui 3.0.0-canary.1331796 → 3.0.0-canary.2189a9e
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react/destructuring-assignment */ 'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React, { useCallback
|
|
3
|
+
import React, { useCallback } from 'react';
|
|
4
4
|
import { useFieldProps } from '../../forms/FieldPropsProvider/index.js';
|
|
5
5
|
import { useField } from '../../forms/useField/index.js';
|
|
6
6
|
import { withCondition } from '../../forms/withCondition/index.js';
|
|
@@ -16,7 +16,9 @@ const formatOptions = (options)=>options.map((option)=>{
|
|
|
16
16
|
});
|
|
17
17
|
const SelectField = (props)=>{
|
|
18
18
|
const { name, AfterInput, BeforeInput, CustomDescription, CustomError, CustomLabel, className, descriptionProps, errorProps, hasMany = false, isClearable = true, isSortable = true, label, labelProps, onChange: onChangeFromProps, options: optionsFromProps = [], path: pathFromProps, readOnly: readOnlyFromProps, required, style, validate, width } = props;
|
|
19
|
-
const
|
|
19
|
+
const options = React.useMemo(()=>formatOptions(optionsFromProps), [
|
|
20
|
+
optionsFromProps
|
|
21
|
+
]);
|
|
20
22
|
const memoizedValidate = useCallback((value, validationOptions)=>{
|
|
21
23
|
if (typeof validate === 'function') return validate(value, {
|
|
22
24
|
...validationOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Select/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { ClientValidate, Option, OptionObject } from 'payload'\n\nimport React, { useCallback, useState } from 'react'\n\nimport type { ReactSelectAdapterProps } from '../../elements/ReactSelect/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\nimport type { SelectInputProps } from './Input.js'\n\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { SelectInput } from './Input.js'\n\nexport type SelectFieldProps = FormFieldBase & {\n hasMany?: boolean\n isClearable?: boolean\n isSortable?: boolean\n name?: string\n onChange?: (e: string | string[]) => void\n options?: Option[]\n path?: string\n value?: string\n width?: string\n}\n\nconst formatOptions = (options: Option[]): OptionObject[] =>\n options.map((option) => {\n if (typeof option === 'object' && (option.value || option.value === '')) {\n return option\n }\n\n return {\n label: option,\n value: option,\n } as OptionObject\n })\n\nconst SelectField: React.FC<SelectFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n errorProps,\n hasMany = false,\n isClearable = true,\n isSortable = true,\n label,\n labelProps,\n onChange: onChangeFromProps,\n options: optionsFromProps = [],\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Select/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { ClientValidate, Option, OptionObject } from 'payload'\n\nimport React, { useCallback, useState } from 'react'\n\nimport type { ReactSelectAdapterProps } from '../../elements/ReactSelect/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\nimport type { SelectInputProps } from './Input.js'\n\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { SelectInput } from './Input.js'\n\nexport type SelectFieldProps = FormFieldBase & {\n hasMany?: boolean\n isClearable?: boolean\n isSortable?: boolean\n name?: string\n onChange?: (e: string | string[]) => void\n options?: Option[]\n path?: string\n value?: string\n width?: string\n}\n\nconst formatOptions = (options: Option[]): OptionObject[] =>\n options.map((option) => {\n if (typeof option === 'object' && (option.value || option.value === '')) {\n return option\n }\n\n return {\n label: option,\n value: option,\n } as OptionObject\n })\n\nconst SelectField: React.FC<SelectFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n errorProps,\n hasMany = false,\n isClearable = true,\n isSortable = true,\n label,\n labelProps,\n onChange: onChangeFromProps,\n options: optionsFromProps = [],\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const options = React.useMemo(() => formatOptions(optionsFromProps), [optionsFromProps])\n\n const memoizedValidate: ClientValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function')\n return validate(value, { ...validationOptions, hasMany, options, required })\n },\n [validate, required, hasMany, options],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const onChange: ReactSelectAdapterProps['onChange'] = useCallback(\n (selectedOption: OptionObject | OptionObject[]) => {\n if (!disabled) {\n let newValue: string | string[] = null\n if (selectedOption && hasMany) {\n if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => option.value)\n } else {\n newValue = []\n }\n } else if (selectedOption && !Array.isArray(selectedOption)) {\n newValue = selectedOption.value\n }\n\n if (typeof onChangeFromProps === 'function') {\n onChangeFromProps(newValue)\n }\n\n setValue(newValue)\n }\n },\n [disabled, hasMany, setValue, onChangeFromProps],\n )\n\n return (\n <SelectInput\n AfterInput={AfterInput}\n BeforeInput={BeforeInput}\n CustomDescription={CustomDescription}\n CustomError={CustomError}\n CustomLabel={CustomLabel}\n className={className}\n descriptionProps={descriptionProps}\n errorProps={errorProps}\n hasMany={hasMany}\n isClearable={isClearable}\n isSortable={isSortable}\n label={label}\n labelProps={labelProps}\n name={name}\n onChange={onChange}\n options={options}\n path={path}\n readOnly={disabled}\n required={required}\n showError={showError}\n style={style}\n value={value as string | string[]}\n width={width}\n />\n )\n}\n\nexport const Select = withCondition(SelectField)\n\nexport { SelectInput, type SelectInputProps }\n"],"names":["React","useCallback","useFieldProps","useField","withCondition","SelectInput","formatOptions","options","map","option","value","label","SelectField","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","descriptionProps","errorProps","hasMany","isClearable","isSortable","labelProps","onChange","onChangeFromProps","optionsFromProps","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","width","useMemo","memoizedValidate","validationOptions","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","selectedOption","newValue","Array","isArray","Select"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD;;AAGA,OAAOA,SAASC,WAAW,QAAkB,QAAO;AAMpD,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,WAAW,QAAQ,aAAY;AAcxC,MAAMC,gBAAgB,CAACC,UACrBA,QAAQC,GAAG,CAAC,CAACC;QACX,IAAI,OAAOA,WAAW,YAAaA,CAAAA,OAAOC,KAAK,IAAID,OAAOC,KAAK,KAAK,EAAC,GAAI;YACvE,OAAOD;QACT;QAEA,OAAO;YACLE,OAAOF;YACPC,OAAOD;QACT;IACF;AAEF,MAAMG,cAA0C,CAACC;IAC/C,MAAM,EACJC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,UAAU,EACVC,UAAU,KAAK,EACfC,cAAc,IAAI,EAClBC,aAAa,IAAI,EACjBd,KAAK,EACLe,UAAU,EACVC,UAAUC,iBAAiB,EAC3BrB,SAASsB,mBAAmB,EAAE,EAC9BC,MAAMC,aAAa,EACnBC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bC,WAAWA;QACXC,kBAAkBA;QAClBC,YAAYA;QACZC,SAASA;QACTC,aAAaA;QACbC,YAAYA;QACZd,OAAOA;QACPe,YAAYA;QACZZ,MAAMA;QACNa,UAAUA;QACVpB,SAASA;QACTuB,MAAMA;QACNE,UAAUe;QACVb,UAAUA;QACVY,WAAWA;QACXX,OAAOA;QACPzB,OAAOA;QACP2B,OAAOA;;AAGb;AAEA,OAAO,MAAMe,SAAShD,cAAcQ,aAAY;AAEhD,SAASP,WAAW,GAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/ui",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.2189a9e",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"sonner": "^1.5.0",
|
|
105
105
|
"use-context-selector": "2.0.0",
|
|
106
106
|
"uuid": "10.0.0",
|
|
107
|
-
"@payloadcms/translations": "3.0.0-canary.
|
|
107
|
+
"@payloadcms/translations": "3.0.0-canary.2189a9e"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@babel/cli": "^7.24.5",
|
|
@@ -130,13 +130,13 @@
|
|
|
130
130
|
"swc-loader": "^0.2.6",
|
|
131
131
|
"turbopack": "^0.0.1",
|
|
132
132
|
"@payloadcms/eslint-config": "1.1.1",
|
|
133
|
-
"payload": "3.0.0-canary.
|
|
133
|
+
"payload": "3.0.0-canary.2189a9e"
|
|
134
134
|
},
|
|
135
135
|
"peerDependencies": {
|
|
136
136
|
"next": "^15.0.0-rc.0",
|
|
137
137
|
"react": "^19.0.0 || ^19.0.0-rc-f994737d14-20240522",
|
|
138
138
|
"react-dom": "^19.0.0 || ^19.0.0-rc-f994737d14-20240522",
|
|
139
|
-
"payload": "3.0.0-canary.
|
|
139
|
+
"payload": "3.0.0-canary.2189a9e"
|
|
140
140
|
},
|
|
141
141
|
"engines": {
|
|
142
142
|
"node": "^18.20.2 || >=20.9.0"
|