@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.
- package/dist/elements/DocumentControls/index.d.ts.map +1 -1
- package/dist/elements/DocumentControls/index.js +28 -21
- package/dist/elements/DocumentControls/index.js.map +1 -1
- package/dist/elements/DocumentDrawer/DrawerContent.js +1 -1
- package/dist/elements/DocumentDrawer/DrawerContent.js.map +1 -1
- package/dist/elements/DuplicateDocument/index.d.ts.map +1 -1
- package/dist/elements/DuplicateDocument/index.js +2 -2
- package/dist/elements/DuplicateDocument/index.js.map +1 -1
- package/dist/elements/ListDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/elements/ListDrawer/DrawerContent.js +1 -1
- package/dist/elements/ListDrawer/DrawerContent.js.map +1 -1
- package/dist/elements/ReactSelect/index.d.ts +1 -1
- package/dist/elements/ReactSelect/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/index.js.map +1 -1
- package/dist/elements/ReactSelect/types.d.ts +4 -4
- package/dist/elements/ReactSelect/types.d.ts.map +1 -1
- package/dist/elements/ReactSelect/types.js.map +1 -1
- package/dist/elements/SortComplex/index.d.ts.map +1 -1
- package/dist/elements/SortComplex/index.js.map +1 -1
- package/dist/elements/TableColumns/index.d.ts +0 -2
- package/dist/elements/TableColumns/index.d.ts.map +1 -1
- package/dist/elements/TableColumns/index.js +83 -85
- package/dist/elements/TableColumns/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.d.ts.map +1 -1
- package/dist/elements/Thumbnail/index.js +2 -2
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/Upload/index.d.ts.map +1 -1
- package/dist/elements/Upload/index.js +4 -9
- package/dist/elements/Upload/index.js.map +1 -1
- package/dist/elements/Upload/index.scss +0 -11
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js +3 -3
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/index.d.ts +2 -1
- package/dist/elements/WhereBuilder/Condition/index.d.ts.map +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.map +1 -1
- package/dist/fields/Array/index.js +2 -2
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/index.js +1 -1
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Checkbox/index.js +1 -1
- package/dist/fields/Checkbox/index.js.map +1 -1
- package/dist/fields/Code/index.js +1 -1
- package/dist/fields/Code/index.js.map +1 -1
- package/dist/fields/Collapsible/index.js +1 -1
- package/dist/fields/Collapsible/index.js.map +1 -1
- package/dist/fields/DateTime/index.d.ts +1 -1
- package/dist/fields/DateTime/index.d.ts.map +1 -1
- package/dist/fields/DateTime/index.js +1 -1
- package/dist/fields/DateTime/index.js.map +1 -1
- package/dist/fields/Email/index.d.ts.map +1 -1
- package/dist/fields/Email/index.js +1 -1
- package/dist/fields/Email/index.js.map +1 -1
- package/dist/fields/JSON/index.d.ts +1 -1
- package/dist/fields/JSON/index.d.ts.map +1 -1
- package/dist/fields/JSON/index.js +1 -1
- package/dist/fields/JSON/index.js.map +1 -1
- package/dist/fields/Number/index.js +1 -1
- package/dist/fields/Number/index.js.map +1 -1
- package/dist/fields/Point/index.js +1 -1
- package/dist/fields/Point/index.js.map +1 -1
- package/dist/fields/RadioGroup/index.js +1 -1
- package/dist/fields/RadioGroup/index.js.map +1 -1
- package/dist/fields/Relationship/index.d.ts.map +1 -1
- package/dist/fields/Relationship/index.js +18 -10
- package/dist/fields/Relationship/index.js.map +1 -1
- package/dist/fields/Relationship/types.d.ts +1 -2
- package/dist/fields/Relationship/types.d.ts.map +1 -1
- package/dist/fields/Relationship/types.js.map +1 -1
- package/dist/fields/Select/Input.d.ts +3 -1
- package/dist/fields/Select/Input.d.ts.map +1 -1
- package/dist/fields/Select/Input.js.map +1 -1
- package/dist/fields/Select/index.d.ts +1 -1
- package/dist/fields/Select/index.d.ts.map +1 -1
- package/dist/fields/Select/index.js +4 -6
- package/dist/fields/Select/index.js.map +1 -1
- package/dist/fields/Tabs/index.js +1 -1
- package/dist/fields/Tabs/index.js.map +1 -1
- package/dist/fields/Text/Input.d.ts.map +1 -1
- package/dist/fields/Text/Input.js.map +1 -1
- package/dist/fields/Text/index.js +1 -1
- package/dist/fields/Text/index.js.map +1 -1
- package/dist/fields/Text/types.d.ts +9 -4
- package/dist/fields/Text/types.d.ts.map +1 -1
- package/dist/fields/Text/types.js.map +1 -1
- package/dist/fields/Textarea/index.js +1 -1
- package/dist/fields/Textarea/index.js.map +1 -1
- package/dist/fields/Upload/index.js +1 -1
- package/dist/fields/Upload/index.js.map +1 -1
- package/dist/forms/FieldError/index.js +1 -1
- package/dist/forms/FieldError/index.js.map +1 -1
- package/dist/forms/FieldPropsProvider/index.js +4 -4
- package/dist/forms/FieldPropsProvider/index.js.map +1 -1
- package/dist/forms/Form/index.js +1 -1
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/types.d.ts +2 -3
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/withCondition/index.js +1 -1
- package/dist/forms/withCondition/index.js.map +1 -1
- package/dist/graphics/Account/index.d.ts +0 -1
- package/dist/graphics/Account/index.d.ts.map +1 -1
- package/dist/graphics/Account/index.js +5 -1
- package/dist/graphics/Account/index.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.js +2 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.js.map +1 -1
- package/dist/providers/FormQueryParams/index.d.ts.map +1 -1
- package/dist/providers/FormQueryParams/index.js +8 -6
- package/dist/providers/FormQueryParams/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/elements/TableColumns/columnReducer.d.ts +0 -24
- package/dist/elements/TableColumns/columnReducer.d.ts.map +0 -1
- package/dist/elements/TableColumns/columnReducer.js +0 -59
- package/dist/elements/TableColumns/columnReducer.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Code/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { CodeField as CodeFieldType } from 'payload/types'\n\nimport React, { useCallback } from 'react'\n\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { CodeEditor } from '../../elements/CodeEditor/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 { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nexport type CodeFieldProps = FormFieldBase & {\n editorOptions?: CodeFieldType['admin']['editorOptions']\n language?: CodeFieldType['admin']['language']\n name?: string\n path?: string\n width: string\n}\n\nconst prismToMonacoLanguageMap = {\n js: 'javascript',\n ts: 'typescript',\n}\n\nconst baseClass = 'code-field'\n\nconst CodeField: React.FC<CodeFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n editorOptions = {},\n errorProps,\n label,\n labelProps,\n language = 'javascript',\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const memoizedValidate = 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 path: pathFromContext
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Code/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { CodeField as CodeFieldType } from 'payload/types'\n\nimport React, { useCallback } from 'react'\n\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { CodeEditor } from '../../elements/CodeEditor/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 { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nexport type CodeFieldProps = FormFieldBase & {\n editorOptions?: CodeFieldType['admin']['editorOptions']\n language?: CodeFieldType['admin']['language']\n name?: string\n path?: string\n width: string\n}\n\nconst prismToMonacoLanguageMap = {\n js: 'javascript',\n ts: 'typescript',\n}\n\nconst baseClass = 'code-field'\n\nconst CodeField: React.FC<CodeFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n editorOptions = {},\n errorProps,\n label,\n labelProps,\n language = 'javascript',\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const memoizedValidate = 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 path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n {BeforeInput}\n <CodeEditor\n defaultLanguage={prismToMonacoLanguageMap[language] || language}\n onChange={disabled ? () => null : (val) => setValue(val)}\n options={editorOptions}\n readOnly={disabled}\n value={(value as string) || ''}\n />\n {AfterInput}\n </div>\n {CustomDescription ? CustomDescription : <FieldDescription {...(descriptionProps || {})} />}\n </div>\n )\n}\n\nexport const Code = withCondition(CodeField)\n"],"names":["React","useCallback","CodeEditor","FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","fieldBaseClass","prismToMonacoLanguageMap","js","ts","baseClass","CodeField","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","descriptionProps","editorOptions","errorProps","label","labelProps","language","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","width","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","defaultLanguage","onChange","val","Code"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD;;AAGA,OAAOA,SAASC,WAAW,QAAQ,QAAO;AAI1C,SAASC,UAAU,QAAQ,qCAAoC;AAC/D,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,cAAc,QAAQ,qBAAoB;AAWnD,MAAMC,2BAA2B;IAC/BC,IAAI;IACJC,IAAI;AACN;AAEA,MAAMC,YAAY;AAElB,MAAMC,YAAsC,CAACC;IAC3C,MAAM,EACJC,IAAI,EACJC,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AW,IAAM,OAAO,CAACO,MAAQT,SAASS;wBACpDd,SAASf;wBACTO,UAAUe;wBACVR,OAAO,AAACA,SAAoB;;oBAE7BrB;;;YAEFE,oBAAoBA,kCAAoB,KAAChB;gBAAkB,GAAIoB,oBAAoB,CAAC,CAAC;;;;AAG5F;AAEA,OAAO,MAAM+B,OAAO9C,cAAcM,WAAU"}
|
|
@@ -20,7 +20,7 @@ const CollapsibleField = (props)=>{
|
|
|
20
20
|
const { indexPath, path: pathFromContext, readOnly: readOnlyFromContext, schemaPath, siblingPermissions } = useFieldProps();
|
|
21
21
|
const formInitializing = useFormInitializing();
|
|
22
22
|
const formProcessing = useFormProcessing();
|
|
23
|
-
const path = pathFromContext
|
|
23
|
+
const path = pathFromContext ?? pathFromProps;
|
|
24
24
|
const { i18n } = useTranslation();
|
|
25
25
|
const { getPreference, setPreference } = usePreferences();
|
|
26
26
|
const { preferencesKey } = useDocumentInfo();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { DocumentPreferences } from 'payload/types'\n\nimport React, { Fragment, useCallback, useEffect, useState } from 'react'\n\nimport { Collapsible as CollapsibleElement } from '../../elements/Collapsible/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { RowLabel } from '../../forms/RowLabel/index.js'\nimport { WatchChildErrors } from '../../forms/WatchChildErrors/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'collapsible-field'\n\nimport type { FieldPermissions } from 'payload/auth'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { useFormInitializing, useFormProcessing } from '../../forms/Form/context.js'\n\nexport type CollapsibleFieldProps = FormFieldBase & {\n fieldMap: FieldMap\n initCollapsed?: boolean\n permissions: FieldPermissions\n width?: string\n}\n\nconst CollapsibleField: React.FC<CollapsibleFieldProps> = (props) => {\n const {\n CustomDescription,\n CustomLabel,\n className,\n descriptionProps,\n fieldMap,\n initCollapsed = false,\n label,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n } = props\n\n const {\n indexPath,\n path: pathFromContext,\n readOnly: readOnlyFromContext,\n schemaPath,\n siblingPermissions,\n } = useFieldProps()\n\n const formInitializing = useFormInitializing()\n const formProcessing = useFormProcessing()\n\n const path = pathFromContext || pathFromProps\n\n const { i18n } = useTranslation()\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const [collapsedOnMount, setCollapsedOnMount] = useState<boolean>()\n const fieldPreferencesKey = `collapsible-${indexPath.replace(/\\./g, '__')}`\n const [errorCount, setErrorCount] = useState(0)\n const fieldHasErrors = errorCount > 0\n\n const onToggle = useCallback(\n async (newCollapsedState: boolean) => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n collapsed: newCollapsedState,\n },\n },\n }\n : {\n fields: {\n ...(existingPreferences?.fields || {}),\n [fieldPreferencesKey]: {\n ...existingPreferences?.fields?.[fieldPreferencesKey],\n collapsed: newCollapsedState,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n if (preferencesKey) {\n const preferences = await getPreference(preferencesKey)\n const specificPreference = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n\n if (specificPreference !== undefined) {\n setCollapsedOnMount(Boolean(specificPreference))\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n }\n\n void fetchInitialState()\n }, [getPreference, preferencesKey, fieldPreferencesKey, initCollapsed, path])\n\n if (typeof collapsedOnMount !== 'boolean') return null\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <Fragment>\n <WatchChildErrors fieldMap={fieldMap} path={path} setErrorCount={setErrorCount} />\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-${fieldPreferencesKey}${path ? `-${path.replace(/\\./g, '__')}` : ''}`}\n >\n <CollapsibleElement\n className={`${baseClass}__collapsible`}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__row-label-wrap`}>\n <RowLabel RowLabelComponent={CustomLabel} i18n={i18n} path={path} rowLabel={label} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fieldMap={fieldMap}\n forceRender\n indexPath={indexPath}\n margins=\"small\"\n path={path}\n permissions={siblingPermissions}\n readOnly={disabled}\n schemaPath={schemaPath}\n />\n </CollapsibleElement>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </div>\n </Fragment>\n )\n}\n\nexport const Collapsible = withCondition(CollapsibleField)\n"],"names":["React","Fragment","useCallback","useEffect","useState","Collapsible","CollapsibleElement","ErrorPill","useFieldProps","RenderFields","RowLabel","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","baseClass","FieldDescription","useFormInitializing","useFormProcessing","CollapsibleField","props","CustomDescription","CustomLabel","className","descriptionProps","fieldMap","initCollapsed","label","path","pathFromProps","readOnly","readOnlyFromProps","indexPath","pathFromContext","readOnlyFromContext","schemaPath","siblingPermissions","formInitializing","formProcessing","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","onToggle","newCollapsedState","existingPreferences","fields","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","disabled","div","filter","join","id","collapsibleStyle","header","RowLabelComponent","rowLabel","count","withMessage","forceRender","margins","permissions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,OAAOA,SAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEzE,SAASC,eAAeC,kBAAkB,QAAQ,sCAAqC;AACvF,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,qBAAoB;AAGnD,MAAMC,YAAY;AAOlB,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,mBAAmB,EAAEC,iBAAiB,QAAQ,8BAA6B;AASpF,MAAMC,mBAAoD,CAACC;IACzD,MAAM,EACJC,iBAAiB,EACjBC,WAAW,EAC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CAAkB,KAAC5C;oCAAUgE,OAAOtB;oCAAYR,MAAMA;oCAAM+B,WAAW;;;;wBAG5E5C,eAAeiB;wBACfO,UAAUA;kCAEV,cAAA,KAAC3C;4BACCkB,UAAUA;4BACV8C,WAAW;4BACXvC,WAAWA;4BACXwC,SAAQ;4BACR5C,MAAMA;4BACN6C,aAAarC;4BACbN,UAAU8B;4BACVzB,YAAYA;;;kCAGhB,KAACnB;wBAAiBK,mBAAmBA;wBAAoB,GAAIG,oBAAoB,CAAC,CAAC;;;;;;AAI3F;AAEA,OAAO,MAAMrB,cAAcO,cAAcS,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Collapsible/index.tsx"],"sourcesContent":["'use client'\nimport type { DocumentPreferences } from 'payload/types'\n\nimport React, { Fragment, useCallback, useEffect, useState } from 'react'\n\nimport { Collapsible as CollapsibleElement } from '../../elements/Collapsible/index.js'\nimport { ErrorPill } from '../../elements/ErrorPill/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { RowLabel } from '../../forms/RowLabel/index.js'\nimport { WatchChildErrors } from '../../forms/WatchChildErrors/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'collapsible-field'\n\nimport type { FieldPermissions } from 'payload/auth'\n\nimport type { FieldMap } from '../../providers/ComponentMap/buildComponentMap/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { useFormInitializing, useFormProcessing } from '../../forms/Form/context.js'\n\nexport type CollapsibleFieldProps = FormFieldBase & {\n fieldMap: FieldMap\n initCollapsed?: boolean\n permissions: FieldPermissions\n width?: string\n}\n\nconst CollapsibleField: React.FC<CollapsibleFieldProps> = (props) => {\n const {\n CustomDescription,\n CustomLabel,\n className,\n descriptionProps,\n fieldMap,\n initCollapsed = false,\n label,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n } = props\n\n const {\n indexPath,\n path: pathFromContext,\n readOnly: readOnlyFromContext,\n schemaPath,\n siblingPermissions,\n } = useFieldProps()\n\n const formInitializing = useFormInitializing()\n const formProcessing = useFormProcessing()\n\n const path = pathFromContext ?? pathFromProps\n\n const { i18n } = useTranslation()\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const [collapsedOnMount, setCollapsedOnMount] = useState<boolean>()\n const fieldPreferencesKey = `collapsible-${indexPath.replace(/\\./g, '__')}`\n const [errorCount, setErrorCount] = useState(0)\n const fieldHasErrors = errorCount > 0\n\n const onToggle = useCallback(\n async (newCollapsedState: boolean) => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n collapsed: newCollapsedState,\n },\n },\n }\n : {\n fields: {\n ...(existingPreferences?.fields || {}),\n [fieldPreferencesKey]: {\n ...existingPreferences?.fields?.[fieldPreferencesKey],\n collapsed: newCollapsedState,\n },\n },\n }),\n })\n }\n },\n [preferencesKey, fieldPreferencesKey, getPreference, setPreference, path],\n )\n\n useEffect(() => {\n const fetchInitialState = async () => {\n if (preferencesKey) {\n const preferences = await getPreference(preferencesKey)\n const specificPreference = path\n ? preferences?.fields?.[path]?.collapsed\n : preferences?.fields?.[fieldPreferencesKey]?.collapsed\n\n if (specificPreference !== undefined) {\n setCollapsedOnMount(Boolean(specificPreference))\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n } else {\n setCollapsedOnMount(typeof initCollapsed === 'boolean' ? initCollapsed : false)\n }\n }\n\n void fetchInitialState()\n }, [getPreference, preferencesKey, fieldPreferencesKey, initCollapsed, path])\n\n if (typeof collapsedOnMount !== 'boolean') return null\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <Fragment>\n <WatchChildErrors fieldMap={fieldMap} path={path} setErrorCount={setErrorCount} />\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-${fieldPreferencesKey}${path ? `-${path.replace(/\\./g, '__')}` : ''}`}\n >\n <CollapsibleElement\n className={`${baseClass}__collapsible`}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__row-label-wrap`}>\n <RowLabel RowLabelComponent={CustomLabel} i18n={i18n} path={path} rowLabel={label} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n }\n initCollapsed={collapsedOnMount}\n onToggle={onToggle}\n >\n <RenderFields\n fieldMap={fieldMap}\n forceRender\n indexPath={indexPath}\n margins=\"small\"\n path={path}\n permissions={siblingPermissions}\n readOnly={disabled}\n schemaPath={schemaPath}\n />\n </CollapsibleElement>\n <FieldDescription CustomDescription={CustomDescription} {...(descriptionProps || {})} />\n </div>\n </Fragment>\n )\n}\n\nexport const Collapsible = withCondition(CollapsibleField)\n"],"names":["React","Fragment","useCallback","useEffect","useState","Collapsible","CollapsibleElement","ErrorPill","useFieldProps","RenderFields","RowLabel","WatchChildErrors","withCondition","useDocumentInfo","usePreferences","useTranslation","fieldBaseClass","baseClass","FieldDescription","useFormInitializing","useFormProcessing","CollapsibleField","props","CustomDescription","CustomLabel","className","descriptionProps","fieldMap","initCollapsed","label","path","pathFromProps","readOnly","readOnlyFromProps","indexPath","pathFromContext","readOnlyFromContext","schemaPath","siblingPermissions","formInitializing","formProcessing","i18n","getPreference","setPreference","preferencesKey","collapsedOnMount","setCollapsedOnMount","fieldPreferencesKey","replace","errorCount","setErrorCount","fieldHasErrors","onToggle","newCollapsedState","existingPreferences","fields","collapsed","fetchInitialState","preferences","specificPreference","undefined","Boolean","disabled","div","filter","join","id","collapsibleStyle","header","RowLabelComponent","rowLabel","count","withMessage","forceRender","margins","permissions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,OAAOA,SAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEzE,SAASC,eAAeC,kBAAkB,QAAQ,sCAAqC;AACvF,SAASC,SAAS,QAAQ,oCAAmC;AAC7D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,qBAAoB;AAGnD,MAAMC,YAAY;AAOlB,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,mBAAmB,EAAEC,iBAAiB,QAAQ,8BAA6B;AASpF,MAAMC,mBAAoD,CAACC;IACzD,MAAM,EACJC,iBAAiB,EACjBC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,QAAQ,EACRC,gBAAgB,KAAK,EACrBC,KAAK,EACLC,MAAMC,aAAa,EACnBC,UAAUC,iBAAiB,EAC5B,GAAGX;IAEJ,MAAM,EACJY,SAAS,EACTJ,MAAMK,eAAe,EACrBH,UAAUI,mBAAmB,EAC7BC,UAAU,EACV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;4BACbN,UAAU8B;4BACVzB,YAAYA;;;kCAGhB,KAACnB;wBAAiBK,mBAAmBA;wBAAoB,GAAIG,oBAAoB,CAAC,CAAC;;;;;;AAI3F;AAEA,OAAO,MAAMrB,cAAcO,cAAcS,kBAAiB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { DateField } from 'payload/types';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import './index.scss';
|
|
3
|
-
import type { DateField } from 'payload/types';
|
|
4
4
|
import type { FormFieldBase } from '../shared/index.js';
|
|
5
5
|
export type DateFieldProps = FormFieldBase & {
|
|
6
6
|
date?: DateField['admin']['date'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/DateTime/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/DateTime/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9D,OAAO,KAAsB,MAAM,OAAO,CAAA;AAO1C,OAAO,cAAc,CAAA;AAIrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAOvD,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC3C,IAAI,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA;IACjC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,GAAG,MAAM,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AA0FD,eAAO,MAAM,QAAQ,0BAA+B,CAAA"}
|
|
@@ -28,7 +28,7 @@ const DateTimeField = (props)=>{
|
|
|
28
28
|
]);
|
|
29
29
|
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
30
30
|
const { formInitializing, formProcessing, path, setValue, showError, value } = useField({
|
|
31
|
-
path: pathFromContext
|
|
31
|
+
path: pathFromContext ?? pathFromProps ?? name,
|
|
32
32
|
validate: memoizedValidate
|
|
33
33
|
});
|
|
34
34
|
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/DateTime/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { ClientValidate } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { DatePickerField } from '../../elements/DatePicker/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'date-time-field'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/DateTime/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { ClientValidate, DateField } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { DatePickerField } from '../../elements/DatePicker/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'date-time-field'\n\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\n\nexport type DateFieldProps = FormFieldBase & {\n date?: DateField['admin']['date']\n name?: string\n path?: string\n placeholder?: DateField['admin']['placeholder'] | string\n width?: string\n}\n\nconst DateTimeField: React.FC<DateFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n date: datePickerProps,\n descriptionProps,\n errorProps,\n label,\n labelProps,\n path: pathFromProps,\n placeholder,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const { i18n } = useTranslation()\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<Date>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && `${baseClass}--has-error`,\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`} id={`field-${path.replace(/\\./g, '__')}`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n {BeforeInput}\n <DatePickerField\n {...datePickerProps}\n onChange={(incomingDate) => {\n if (!disabled) setValue(incomingDate?.toISOString() || null)\n }}\n placeholder={getTranslation(placeholder, i18n)}\n readOnly={disabled}\n value={value}\n />\n {AfterInput}\n </div>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n )\n}\n\nexport const DateTime = withCondition(DateTimeField)\n"],"names":["getTranslation","React","useCallback","DatePickerField","FieldLabel","useField","useTranslation","fieldBaseClass","baseClass","FieldDescription","FieldError","useFieldProps","withCondition","DateTimeField","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","date","datePickerProps","descriptionProps","errorProps","label","labelProps","path","pathFromProps","placeholder","readOnly","readOnlyFromProps","required","style","validate","width","i18n","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","id","replace","onChange","incomingDate","toISOString","undefined","DateTime"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,qBAAoB;AAGnD,MAAMC,YAAY;AAIlB,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,aAAa,QAAQ,qCAAoC;AAUlE,MAAMC,gBAA0C,CAACC;IAC/C,MAAM,EACJC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,MAAMC,eAAe,EACrBC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,MAAMC,aAAa,EACnBC,WAAW,EACXC,UAAUC,iBAAiB,EAC3BC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACN,GAAGtB;IAEJ,MAAM,EAAEuB,IAAI,EAAE,GAAG/B;IAEjB,MAAMgC,mBAAmCpC,YACvC,CAACqC,OAAOC;QACN,IAAI,OAAOL,aAAa,YAAY;YAClC,OAAOA,SAAS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1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Email/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Email/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,UAAU,IAAI,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjF,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAUvD,OAAO,cAAc,CAAA;AAErB,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAA;IACpD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAqFD,eAAO,MAAM,KAAK,2BAA4B,CAAA"}
|
|
@@ -26,7 +26,7 @@ const EmailField = (props)=>{
|
|
|
26
26
|
]);
|
|
27
27
|
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
28
28
|
const { formInitializing, formProcessing, path, setValue, showError, value } = useField({
|
|
29
|
-
path: pathFromContext
|
|
29
|
+
path: pathFromContext ?? pathFromProps ?? name,
|
|
30
30
|
validate: memoizedValidate
|
|
31
31
|
});
|
|
32
32
|
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Email/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientValidate
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Email/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientValidate, EmailField as EmailFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\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 { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nexport type EmailFieldProps = FormFieldBase & {\n autoComplete?: string\n name?: string\n path?: string\n placeholder?: EmailFieldType['admin']['placeholder']\n width?: string\n}\n\nconst EmailField: React.FC<EmailFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n autoComplete,\n className,\n descriptionProps,\n errorProps,\n label,\n labelProps,\n path: pathFromProps,\n placeholder,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const { i18n } = useTranslation()\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 path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n return (\n <div\n className={[fieldBaseClass, 'email', className, showError && 'error', disabled && 'read-only']\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n {BeforeInput}\n <input\n autoComplete={autoComplete}\n disabled={disabled}\n id={`field-${path.replace(/\\./g, '__')}`}\n name={path}\n onChange={setValue}\n placeholder={getTranslation(placeholder, i18n)}\n type=\"email\"\n value={(value as string) || ''}\n />\n {AfterInput}\n </div>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n )\n}\n\nexport const Email = withCondition(EmailField)\n"],"names":["getTranslation","React","useCallback","FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","useTranslation","fieldBaseClass","EmailField","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","autoComplete","className","descriptionProps","errorProps","label","labelProps","path","pathFromProps","placeholder","readOnly","readOnlyFromProps","required","style","validate","width","i18n","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","div","filter","Boolean","join","input","id","replace","onChange","type","undefined","Email"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAI1C,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,qBAAoB;AAWnD,MAAMC,aAAwC,CAACC;IAC7C,MAAM,EACJC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,MAAMC,aAAa,EACnBC,WAAW,EACXC,UAAUC,iBA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YAEFE,sBAAsBsC,YACrBtC,kCAEA,KAACb;gBAAkB,GAAIkB,oBAAoB,CAAC,CAAC;;;;AAIrD;AAEA,OAAO,MAAMkC,QAAQ/C,cAAcG,YAAW"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { JSONField as JSONFieldType } from 'payload/types';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import './index.scss';
|
|
3
|
-
import type { JSONField as JSONFieldType } from 'payload/types';
|
|
4
4
|
import type { FormFieldBase } from '../shared/index.js';
|
|
5
5
|
export type JSONFieldProps = FormFieldBase & {
|
|
6
6
|
editorOptions?: JSONFieldType['admin']['editorOptions'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/JSON/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/JSON/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,IAAI,aAAa,EAAE,MAAM,eAAe,CAAA;AAE/E,OAAO,KAA2C,MAAM,OAAO,CAAA;AAO/D,OAAO,cAAc,CAAA;AAIrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAMvD,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC3C,aAAa,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAyID,eAAO,MAAM,SAAS,0BAAoC,CAAA"}
|
|
@@ -28,7 +28,7 @@ const JSONFieldComponent = (props)=>{
|
|
|
28
28
|
]);
|
|
29
29
|
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
30
30
|
const { formInitializing, formProcessing, initialValue, path, setValue, showError, value } = useField({
|
|
31
|
-
path: pathFromContext
|
|
31
|
+
path: pathFromContext ?? pathFromProps ?? name,
|
|
32
32
|
validate: memoizedValidate
|
|
33
33
|
});
|
|
34
34
|
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/JSON/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientValidate } from 'payload/types'\n\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'json-field'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/JSON/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientValidate, JSONField as JSONFieldType } from 'payload/types'\n\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { CodeEditor } from '../../elements/CodeEditor/index.js'\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'json-field'\n\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\n\nexport type JSONFieldProps = FormFieldBase & {\n editorOptions?: JSONFieldType['admin']['editorOptions']\n jsonSchema?: Record<string, unknown>\n name?: string\n path?: string\n width?: string\n}\n\nconst JSONFieldComponent: React.FC<JSONFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n editorOptions,\n errorProps,\n jsonSchema,\n label,\n labelProps,\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n width,\n } = props\n\n const [stringValue, setStringValue] = useState<string>()\n const [jsonError, setJsonError] = useState<string>()\n const [hasLoadedValue, setHasLoadedValue] = useState(false)\n\n const memoizedValidate: ClientValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function')\n return validate(value, { ...options, jsonError, required })\n },\n [validate, required, jsonError],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, initialValue, path, setValue, showError, value } =\n useField<string>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const handleMount = useCallback(\n (editor, monaco) => {\n if (!jsonSchema) return\n\n const existingSchemas = monaco.languages.json.jsonDefaults.diagnosticsOptions.schemas || []\n const modelUri = monaco.Uri.parse(jsonSchema.uri)\n\n const model = monaco.editor.createModel(JSON.stringify(value, null, 2), 'json', modelUri)\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n enableSchemaRequest: true,\n schemas: [...existingSchemas, jsonSchema],\n validate: true,\n })\n\n editor.setModel(model)\n },\n [jsonSchema, value],\n )\n\n const handleChange = useCallback(\n (val) => {\n if (disabled) return\n setStringValue(val)\n\n try {\n setValue(val ? JSON.parse(val) : null)\n setJsonError(undefined)\n } catch (e) {\n setValue(val ? val : null)\n setJsonError(e)\n }\n },\n [disabled, setValue, setStringValue],\n )\n\n useEffect(() => {\n if (hasLoadedValue || value === undefined) return\n\n setStringValue(\n value || initialValue ? JSON.stringify(value ? value : initialValue, null, 2) : '',\n )\n\n setHasLoadedValue(true)\n }, [initialValue, value, hasLoadedValue])\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n disabled && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n {BeforeInput}\n <CodeEditor\n defaultLanguage=\"json\"\n onChange={handleChange}\n onMount={handleMount}\n options={editorOptions}\n readOnly={disabled}\n value={stringValue}\n />\n {AfterInput}\n </div>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n )\n}\n\nexport const JSONField = withCondition(JSONFieldComponent)\n"],"names":["React","useCallback","useEffect","useState","CodeEditor","FieldLabel","useField","withCondition","fieldBaseClass","baseClass","FieldDescription","FieldError","useFieldProps","JSONFieldComponent","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","descriptionProps","editorOptions","errorProps","jsonSchema","label","labelProps","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","width","stringValue","setStringValue","jsonError","setJsonError","hasLoadedValue","setHasLoadedValue","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","initialValue","setValue","showError","disabled","handleMount","editor","monaco","existingSchemas","languages","json","jsonDefaults","diagnosticsOptions","schemas","modelUri","Uri","parse","uri","model","createModel","JSON","stringify","setDiagnosticsOptions","enableSchemaRequest","setModel","handleChange","val","undefined","e","div","filter","Boolean","join","defaultLanguage","onChange","onMount","JSONField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAGA,OAAOA,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;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Ac,CAAC,CAAC;;0BAEvB,KAAChB;gBAAWQ,aAAaA;gBAAaS,MAAMA;gBAAO,GAAIJ,cAAc,CAAC,CAAC;;0BACvE,MAACqD;gBAAIxD,WAAW,CAAC,EAAEb,eAAe,MAAM,CAAC;;kCACvC,KAACG;wBAAWQ,aAAaA;wBAAaS,MAAMA;wBAAO,GAAIJ,cAAc,CAAC,CAAC;;oBACtEP;kCACD,KAACb;wBACC6E,iBAAgB;wBAChBC,UAAUT;wBACVU,SAAS9B;wBACTT,SAASrB;wBACTO,UAAUsB;wBACVT,OAAOP;;oBAERpB;;;YAEFE,sBAAsByD,YACrBzD,kCAEA,KAACR;gBAAkB,GAAIY,oBAAoB,CAAC,CAAC;;;;AAIrD;AAEA,OAAO,MAAM8D,YAAY7E,cAAcM,oBAAmB"}
|
|
@@ -32,7 +32,7 @@ const NumberFieldComponent = (props)=>{
|
|
|
32
32
|
]);
|
|
33
33
|
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
34
34
|
const { formInitializing, formProcessing, path, setValue, showError, value } = useField({
|
|
35
|
-
path: pathFromContext
|
|
35
|
+
path: pathFromContext ?? pathFromProps ?? name,
|
|
36
36
|
validate: memoizedValidate
|
|
37
37
|
});
|
|
38
38
|
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Number/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { NumberField as NumberFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { isNumber } from 'payload/utilities'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { Option } from '../../elements/ReactSelect/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { ReactSelect } from '../../elements/ReactSelect/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 { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nexport type NumberFieldProps = FormFieldBase & {\n hasMany?: boolean\n max?: number\n maxRows?: number\n min?: number\n name?: string\n onChange?: (e: number) => void\n path?: string\n placeholder?: NumberFieldType['admin']['placeholder']\n step?: number\n width?: string\n}\n\nconst NumberFieldComponent: React.FC<NumberFieldProps> = (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 label,\n labelProps,\n max = Infinity,\n maxRows = Infinity,\n min = -Infinity,\n onChange: onChangeFromProps,\n path: pathFromProps,\n placeholder,\n readOnly: readOnlyFromProps,\n required,\n step = 1,\n style,\n validate,\n width,\n } = props\n\n const { i18n, t } = useTranslation()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, max, min, required })\n }\n },\n [validate, min, max, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField<\n number | number[]\n >({\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const handleChange = useCallback(\n (e) => {\n const val = parseFloat(e.target.value)\n let newVal = val\n\n if (Number.isNaN(val)) {\n newVal = undefined\n }\n\n if (typeof onChangeFromProps === 'function') {\n onChangeFromProps(newVal)\n }\n\n setValue(newVal)\n },\n [onChangeFromProps, setValue],\n )\n\n const [valueToRender, setValueToRender] = useState<\n { id: string; label: string; value: { value: number } }[]\n >([]) // Only for hasMany\n\n const handleHasManyChange = useCallback(\n (selectedOption) => {\n if (!disabled) {\n let newValue\n if (!selectedOption) {\n newValue = []\n } else if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => Number(option.value?.value || option.value))\n } else {\n newValue = [Number(selectedOption.value?.value || selectedOption.value)]\n }\n\n setValue(newValue)\n }\n },\n [disabled, setValue],\n )\n\n // useEffect update valueToRender:\n useEffect(() => {\n if (hasMany && Array.isArray(value)) {\n setValueToRender(\n value.map((val, index) => {\n return {\n id: `${val}${index}`, // append index to avoid duplicate keys but allow duplicate numbers\n label: `${val}`,\n value: {\n toString: () => `${val}${index}`,\n value: (val as unknown as Record<string, number>)?.value || val,\n }, // You're probably wondering, why the hell is this done that way? Well, React-select automatically uses \"label-value\" as a key, so we will get that react duplicate key warning if we just pass in the value as multiple values can be the same. So we need to append the index to the toString() of the value to avoid that warning, as it uses that as the key.\n }\n }),\n )\n }\n }, [value, hasMany])\n\n return (\n <div\n className={[\n fieldBaseClass,\n 'number',\n className,\n showError && 'error',\n disabled && 'read-only',\n hasMany && 'has-many',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n {hasMany ? (\n <ReactSelect\n className={`field-${path.replace(/\\./g, '__')}`}\n disabled={disabled}\n filterOption={(_, rawInput) => {\n // eslint-disable-next-line no-restricted-globals\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n return isNumber(rawInput) && !isOverHasMany\n }}\n isClearable\n isCreatable\n isMulti\n isSortable\n noOptionsMessage={() => {\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n if (isOverHasMany) {\n return t('validation:limitReached', { max: maxRows, value: value.length + 1 })\n }\n return null\n }}\n // numberOnly\n onChange={handleHasManyChange}\n options={[]}\n placeholder={t('general:enterAValue')}\n showError={showError}\n value={valueToRender as Option[]}\n />\n ) : (\n <div>\n {BeforeInput}\n <input\n disabled={disabled}\n id={`field-${path.replace(/\\./g, '__')}`}\n max={max}\n min={min}\n name={path}\n onChange={handleChange}\n onWheel={(e) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n e.target.blur()\n }}\n placeholder={getTranslation(placeholder, i18n)}\n step={step}\n type=\"number\"\n value={typeof value === 'number' ? value : ''}\n />\n {AfterInput}\n </div>\n )}\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nexport const NumberField = withCondition(NumberFieldComponent)\n"],"names":["getTranslation","isNumber","React","useCallback","useEffect","useState","ReactSelect","FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","useTranslation","fieldBaseClass","NumberFieldComponent","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","descriptionProps","errorProps","hasMany","label","labelProps","max","Infinity","maxRows","min","onChange","onChangeFromProps","path","pathFromProps","placeholder","readOnly","readOnlyFromProps","required","step","style","validate","width","i18n","t","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","handleChange","e","val","parseFloat","target","newVal","Number","isNaN","undefined","valueToRender","setValueToRender","handleHasManyChange","selectedOption","newValue","Array","isArray","map","option","index","id","toString","div","filter","Boolean","join","replace","filterOption","_","rawInput","isOverHasMany","length","isClearable","isCreatable","isMulti","isSortable","noOptionsMessage","input","onWheel","blur","type","NumberField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD;;AAGA,SAASA,cAAc,QAAQ,2BAA0B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I,CAAC,MAAM,EAAEzC,KAAK+C,OAAO,CAAC,OAAO,MAAM,CAAC;gCACxCrD,KAAKA;gCACLG,KAAKA;gCACLf,MAAMkB;gCACNF,UAAUwB;gCACVqC,SAAS,CAACpC;oCACR,6DAA6D;oCAC7D,mBAAmB;oCACnBA,EAAEG,MAAM,CAACkC,IAAI;gCACf;gCACA1D,aAAarC,eAAeqC,aAAaQ;gCACzCJ,MAAMA;gCACNuD,MAAK;gCACLhD,OAAO,OAAOA,UAAU,WAAWA,QAAQ;;4BAE5C9B;;;oBAGJE,sBAAsB6C,YACrB7C,kCAEA,KAACb;wBAAkB,GAAIiB,oBAAoB,CAAC,CAAC;;;;;;AAKvD;AAEA,OAAO,MAAMyE,cAAcrF,cAAcG,sBAAqB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Number/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { NumberField as NumberFieldType } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { isNumber } from 'payload/utilities'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { Option } from '../../elements/ReactSelect/types.js'\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { ReactSelect } from '../../elements/ReactSelect/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 { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nexport type NumberFieldProps = FormFieldBase & {\n hasMany?: boolean\n max?: number\n maxRows?: number\n min?: number\n name?: string\n onChange?: (e: number) => void\n path?: string\n placeholder?: NumberFieldType['admin']['placeholder']\n step?: number\n width?: string\n}\n\nconst NumberFieldComponent: React.FC<NumberFieldProps> = (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 label,\n labelProps,\n max = Infinity,\n maxRows = Infinity,\n min = -Infinity,\n onChange: onChangeFromProps,\n path: pathFromProps,\n placeholder,\n readOnly: readOnlyFromProps,\n required,\n step = 1,\n style,\n validate,\n width,\n } = props\n\n const { i18n, t } = useTranslation()\n\n const memoizedValidate = useCallback(\n (value, options) => {\n if (typeof validate === 'function') {\n return validate(value, { ...options, max, min, required })\n }\n },\n [validate, min, max, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const { formInitializing, formProcessing, path, setValue, showError, value } = useField<\n number | number[]\n >({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const handleChange = useCallback(\n (e) => {\n const val = parseFloat(e.target.value)\n let newVal = val\n\n if (Number.isNaN(val)) {\n newVal = undefined\n }\n\n if (typeof onChangeFromProps === 'function') {\n onChangeFromProps(newVal)\n }\n\n setValue(newVal)\n },\n [onChangeFromProps, setValue],\n )\n\n const [valueToRender, setValueToRender] = useState<\n { id: string; label: string; value: { value: number } }[]\n >([]) // Only for hasMany\n\n const handleHasManyChange = useCallback(\n (selectedOption) => {\n if (!disabled) {\n let newValue\n if (!selectedOption) {\n newValue = []\n } else if (Array.isArray(selectedOption)) {\n newValue = selectedOption.map((option) => Number(option.value?.value || option.value))\n } else {\n newValue = [Number(selectedOption.value?.value || selectedOption.value)]\n }\n\n setValue(newValue)\n }\n },\n [disabled, setValue],\n )\n\n // useEffect update valueToRender:\n useEffect(() => {\n if (hasMany && Array.isArray(value)) {\n setValueToRender(\n value.map((val, index) => {\n return {\n id: `${val}${index}`, // append index to avoid duplicate keys but allow duplicate numbers\n label: `${val}`,\n value: {\n toString: () => `${val}${index}`,\n value: (val as unknown as Record<string, number>)?.value || val,\n }, // You're probably wondering, why the hell is this done that way? Well, React-select automatically uses \"label-value\" as a key, so we will get that react duplicate key warning if we just pass in the value as multiple values can be the same. So we need to append the index to the toString() of the value to avoid that warning, as it uses that as the key.\n }\n }),\n )\n }\n }, [value, hasMany])\n\n return (\n <div\n className={[\n fieldBaseClass,\n 'number',\n className,\n showError && 'error',\n disabled && 'read-only',\n hasMany && 'has-many',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n {hasMany ? (\n <ReactSelect\n className={`field-${path.replace(/\\./g, '__')}`}\n disabled={disabled}\n filterOption={(_, rawInput) => {\n // eslint-disable-next-line no-restricted-globals\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n return isNumber(rawInput) && !isOverHasMany\n }}\n isClearable\n isCreatable\n isMulti\n isSortable\n noOptionsMessage={() => {\n const isOverHasMany = Array.isArray(value) && value.length >= maxRows\n if (isOverHasMany) {\n return t('validation:limitReached', { max: maxRows, value: value.length + 1 })\n }\n return null\n }}\n // numberOnly\n onChange={handleHasManyChange}\n options={[]}\n placeholder={t('general:enterAValue')}\n showError={showError}\n value={valueToRender as Option[]}\n />\n ) : (\n <div>\n {BeforeInput}\n <input\n disabled={disabled}\n id={`field-${path.replace(/\\./g, '__')}`}\n max={max}\n min={min}\n name={path}\n onChange={handleChange}\n onWheel={(e) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n e.target.blur()\n }}\n placeholder={getTranslation(placeholder, i18n)}\n step={step}\n type=\"number\"\n value={typeof value === 'number' ? value : ''}\n />\n {AfterInput}\n </div>\n )}\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nexport const NumberField = withCondition(NumberFieldComponent)\n"],"names":["getTranslation","isNumber","React","useCallback","useEffect","useState","ReactSelect","FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","useTranslation","fieldBaseClass","NumberFieldComponent","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","descriptionProps","errorProps","hasMany","label","labelProps","max","Infinity","maxRows","min","onChange","onChangeFromProps","path","pathFromProps","placeholder","readOnly","readOnlyFromProps","required","step","style","validate","width","i18n","t","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","disabled","handleChange","e","val","parseFloat","target","newVal","Number","isNaN","undefined","valueToRender","setValueToRender","handleHasManyChange","selectedOption","newValue","Array","isArray","map","option","index","id","toString","div","filter","Boolean","join","replace","filterOption","_","rawInput","isOverHasMany","length","isClearable","isCreatable","isMulti","isSortable","noOptionsMessage","input","onWheel","blur","type","NumberField"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,QAAQ,QAAQ,oBAAmB;AAC5C,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAK/D,SAASC,WAAW,QAAQ,sCAAqC;AACjE,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,cAAc,QA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CAEA,KAACb;wBAAkB,GAAIiB,oBAAoB,CAAC,CAAC;;;;;;AAKvD;AAEA,OAAO,MAAMyE,cAAcrF,cAAcG,sBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Point/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { ClientValidate } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'point'\n\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'\n\nexport type PointFieldProps = FormFieldBase & {\n name?: string\n path?: string\n placeholder?: string\n step?: number\n width?: string\n}\n\nconst PointField: React.FC<PointFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n errorProps,\n label,\n labelProps,\n path: pathFromProps,\n placeholder,\n readOnly: readOnlyFromProps,\n required,\n step,\n style,\n validate,\n width,\n } = props\n\n const { i18n, t } = useTranslation()\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 const readOnly = readOnlyFromProps || readOnlyFromContext\n\n const {\n path,\n setValue,\n showError,\n value = [null, null],\n } = useField<[number, number]>({\n path: pathFromContext
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Point/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n'use client'\nimport type { ClientValidate } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback } from 'react'\n\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport './index.scss'\n\nconst baseClass = 'point'\n\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'\n\nexport type PointFieldProps = FormFieldBase & {\n name?: string\n path?: string\n placeholder?: string\n step?: number\n width?: string\n}\n\nconst PointField: React.FC<PointFieldProps> = (props) => {\n const {\n name,\n AfterInput,\n BeforeInput,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n errorProps,\n label,\n labelProps,\n path: pathFromProps,\n placeholder,\n readOnly: readOnlyFromProps,\n required,\n step,\n style,\n validate,\n width,\n } = props\n\n const { i18n, t } = useTranslation()\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 const readOnly = readOnlyFromProps || readOnlyFromContext\n\n const {\n path,\n setValue,\n showError,\n value = [null, null],\n } = useField<[number, number]>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const handleChange = useCallback(\n (e, index: 0 | 1) => {\n let val = parseFloat(e.target.value)\n if (Number.isNaN(val)) {\n val = e.target.value\n }\n const coordinates = [...value]\n coordinates[index] = val\n setValue(coordinates)\n },\n [setValue, value],\n )\n\n const getCoordinateFieldLabel = (type: 'latitude' | 'longitude') => {\n const suffix = type === 'longitude' ? t('fields:longitude') : t('fields:latitude')\n const fieldLabel = label ? getTranslation(label, i18n) : ''\n\n return {\n ...labelProps,\n label: `${fieldLabel}${fieldLabel ? ' - ' : ''}${suffix}`,\n }\n }\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n readOnly && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n <ul className={`${baseClass}__wrap`}>\n <li>\n {CustomLabel !== undefined ? (\n CustomLabel\n ) : (\n <FieldLabel {...getCoordinateFieldLabel('longitude')} />\n )}\n <div className=\"input-wrapper\">\n {BeforeInput}\n <input\n disabled={readOnly}\n id={`field-longitude-${path.replace(/\\./g, '__')}`}\n name={`${path}.longitude`}\n onChange={(e) => handleChange(e, 0)}\n placeholder={getTranslation(placeholder, i18n)}\n step={step}\n type=\"number\"\n value={value && typeof value[0] === 'number' ? value[0] : ''}\n />\n {AfterInput}\n </div>\n </li>\n <li>\n {CustomLabel !== undefined ? (\n CustomLabel\n ) : (\n <FieldLabel {...getCoordinateFieldLabel('latitude')} />\n )}\n <div className=\"input-wrapper\">\n {BeforeInput}\n <input\n disabled={readOnly}\n id={`field-latitude-${path.replace(/\\./g, '__')}`}\n name={`${path}.latitude`}\n onChange={(e) => handleChange(e, 1)}\n placeholder={getTranslation(placeholder, i18n)}\n step={step}\n type=\"number\"\n value={value && typeof value[1] === 'number' ? value[1] : ''}\n />\n {AfterInput}\n </div>\n </li>\n </ul>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n )\n}\n\nexport const Point = withCondition(PointField)\n"],"names":["getTranslation","React","useCallback","useField","withCondition","useTranslation","fieldBaseClass","baseClass","FieldDescription","FieldError","FieldLabel","useFieldProps","PointField","props","name","AfterInput","BeforeInput","CustomDescription","CustomError","CustomLabel","className","descriptionProps","errorProps","label","labelProps","path","pathFromProps","placeholder","readOnly","readOnlyFromProps","required","step","style","validate","width","i18n","t","memoizedValidate","value","options","pathFromContext","readOnlyFromContext","setValue","showError","handleChange","e","index","val","parseFloat","target","Number","isNaN","coordinates","getCoordinateFieldLabel","type","suffix","fieldLabel","div","filter","Boolean","join","ul","li","undefined","input","disabled","id","replace","onChange","Point"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,qBAAoB;AAGnD,MAAMC,YAAY;AAIlB,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AAUvE,MAAMC,aAAwC,CAACC;IAC7C,MAAM,EACJC,IAAI,EACJC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,MAAMC,aAAa,EACnBC,WAAW,EACXC,UAAUC,iBAAiB,EAC3BC,QAAQ,EACRC,IAAI,EACJC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACN,GAAGrB;IAEJ,MAAM,EAAEsB,IAAI,EAAEC,CAAC,EAAE,GAAG/B;IAEpB,MAAMgC,mBAAmCnC,YACvC,CAACoC,OAAOC;QACN,IAAI,OAAON,aAAa,YAAY;YAClC,OAAOA,SAASK,O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,4BAEA,KAACT;gCAAY,GAAG2C,wBAAwB,YAAY;;0CAEtD,MAACI;gCAAIrC,WAAU;;oCACZJ;kDACD,KAACgD;wCACCC,UAAUrC;wCACVsC,IAAI,CAAC,gBAAgB,EAAEzC,KAAK0C,OAAO,CAAC,OAAO,MAAM,CAAC;wCAClDrD,MAAM,CAAC,EAAEW,KAAK,UAAU,CAAC;wCACzB2C,UAAU,CAACvB,IAAMD,aAAaC,GAAG;wCACjClB,aAAa3B,eAAe2B,aAAaQ;wCACzCJ,MAAMA;wCACNuB,MAAK;wCACLhB,OAAOA,SAAS,OAAOA,KAAK,CAAC,EAAE,KAAK,WAAWA,KAAK,CAAC,EAAE,GAAG;;oCAE3DvB;;;;;kCAGL,MAAC+C;;4BACE3C,gBAAgB4C,YACf5C,4BAEA,KAACT;gCAAY,GAAG2C,wBAAwB,WAAW;;0CAErD,MAACI;gCAAIrC,WAAU;;oCACZJ;kDACD,KAACgD;wCACCC,UAAUrC;wCACVsC,IAAI,CAAC,eAAe,EAAEzC,KAAK0C,OAAO,CAAC,OAAO,MAAM,CAAC;wCACjDrD,MAAM,CAAC,EAAEW,KAAK,SAAS,CAAC;wCACxB2C,UAAU,CAACvB,IAAMD,aAAaC,GAAG;wCACjClB,aAAa3B,eAAe2B,aAAaQ;wCACzCJ,MAAMA;wCACNuB,MAAK;wCACLhB,OAAOA,SAAS,OAAOA,KAAK,CAAC,EAAE,KAAK,WAAWA,KAAK,CAAC,EAAE,GAAG;;oCAE3DvB;;;;;;;YAINE,sBAAsB8C,YACrB9C,kCAEA,KAACT;gBAAkB,GAAIa,oBAAoB,CAAC,CAAC;;;;AAIrD;AAEA,OAAO,MAAMgD,QAAQjE,cAAcQ,YAAW"}
|
|
@@ -28,7 +28,7 @@ const RadioGroupField = (props)=>{
|
|
|
28
28
|
]);
|
|
29
29
|
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
30
30
|
const { formInitializing, formProcessing, path, setValue, showError, value: valueFromContext } = useField({
|
|
31
|
-
path: pathFromContext
|
|
31
|
+
path: pathFromContext ?? pathFromProps ?? name,
|
|
32
32
|
validate: memoizedValidate
|
|
33
33
|
});
|
|
34
34
|
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/RadioGroup/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n/* eslint-disable react-hooks/exhaustive-deps */\n'use client'\nimport type { Option } from 'payload/types'\n\nimport { optionIsObject } from 'payload/types'\nimport React, { useCallback } from 'react'\n\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useForm } from '../../forms/Form/context.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { Radio } from './Radio/index.js'\nimport './index.scss'\n\nconst baseClass = 'radio-group'\n\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\n\nexport type RadioFieldProps = FormFieldBase & {\n layout?: 'horizontal' | 'vertical'\n name?: string\n onChange?: OnChange\n options?: Option[]\n path?: string\n value?: string\n width?: string\n}\n\nexport type OnChange<T = string> = (value: T) => void\n\nconst RadioGroupField: React.FC<RadioFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n errorProps,\n label,\n labelProps,\n layout = 'horizontal',\n onChange: onChangeFromProps,\n options = [],\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n value: valueFromProps,\n width,\n } = props\n\n const { uuid } = useForm()\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function')\n return validate(value, { ...validationOptions, options, required })\n },\n [validate, options, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const {\n formInitializing,\n formProcessing,\n path,\n setValue,\n showError,\n value: valueFromContext,\n } = useField<string>({\n path: pathFromContext
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/RadioGroup/index.tsx"],"sourcesContent":["/* eslint-disable react/destructuring-assignment */\n/* eslint-disable react-hooks/exhaustive-deps */\n'use client'\nimport type { Option } from 'payload/types'\n\nimport { optionIsObject } from 'payload/types'\nimport React, { useCallback } from 'react'\n\nimport { FieldLabel } from '../../forms/FieldLabel/index.js'\nimport { useForm } from '../../forms/Form/context.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { Radio } from './Radio/index.js'\nimport './index.scss'\n\nconst baseClass = 'radio-group'\n\nimport type { FormFieldBase } from '../shared/index.js'\n\nimport { FieldDescription } from '../../forms/FieldDescription/index.js'\nimport { FieldError } from '../../forms/FieldError/index.js'\nimport { useFieldProps } from '../../forms/FieldPropsProvider/index.js'\n\nexport type RadioFieldProps = FormFieldBase & {\n layout?: 'horizontal' | 'vertical'\n name?: string\n onChange?: OnChange\n options?: Option[]\n path?: string\n value?: string\n width?: string\n}\n\nexport type OnChange<T = string> = (value: T) => void\n\nconst RadioGroupField: React.FC<RadioFieldProps> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n errorProps,\n label,\n labelProps,\n layout = 'horizontal',\n onChange: onChangeFromProps,\n options = [],\n path: pathFromProps,\n readOnly: readOnlyFromProps,\n required,\n style,\n validate,\n value: valueFromProps,\n width,\n } = props\n\n const { uuid } = useForm()\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function')\n return validate(value, { ...validationOptions, options, required })\n },\n [validate, options, required],\n )\n\n const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const {\n formInitializing,\n formProcessing,\n path,\n setValue,\n showError,\n value: valueFromContext,\n } = useField<string>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const value = valueFromContext || valueFromProps\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n `${baseClass}--layout-${layout}`,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')}\n style={{\n ...style,\n width,\n }}\n >\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n\n <ul className={`${baseClass}--group`} id={`field-${path.replace(/\\./g, '__')}`}>\n {options.map((option) => {\n let optionValue = ''\n\n if (optionIsObject(option)) {\n optionValue = option.value\n } else {\n optionValue = option\n }\n\n const isSelected = String(optionValue) === String(value)\n\n const id = `field-${path}-${optionValue}${uuid ? `-${uuid}` : ''}`\n\n return (\n <li key={`${path} - ${optionValue}`}>\n <Radio\n id={id}\n isSelected={isSelected}\n onChange={() => {\n if (typeof onChangeFromProps === 'function') {\n onChangeFromProps(optionValue)\n }\n\n if (!disabled) {\n setValue(optionValue)\n }\n }}\n option={optionIsObject(option) ? option : { label: option, value: option }}\n path={path}\n readOnly={disabled}\n uuid={uuid}\n />\n </li>\n )\n })}\n </ul>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nexport const RadioGroup = withCondition(RadioGroupField)\n"],"names":["optionIsObject","React","useCallback","FieldLabel","useForm","useField","withCondition","fieldBaseClass","Radio","baseClass","FieldDescription","FieldError","useFieldProps","RadioGroupField","props","name","CustomDescription","CustomError","CustomLabel","className","descriptionProps","errorProps","label","labelProps","layout","onChange","onChangeFromProps","options","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","value","valueFromProps","width","uuid","memoizedValidate","validationOptions","pathFromContext","readOnlyFromContext","formInitializing","formProcessing","setValue","showError","valueFromContext","disabled","div","filter","Boolean","join","ul","id","replace","map","option","optionValue","isSelected","String","li","undefined","RadioGroup"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iDAAiD,GACjD,8CAA8C,GAC9C;;AAGA,SAASA,cAAc,QAAQ,gBAAe;AAC9C,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAE1C,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,OAAO,QAAQ,8BAA6B;AACrD,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,KAAK,QAAQ,mBAAkB;AAGxC,MAAMC,YAAY;AAIlB,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AAcvE,MAAMC,kBAA6C,CAACC;IAClD,MAAM,EACJC,IAAI,EACJC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,SAAS,YAAY,EACrBC,UAAUC,iBAAiB,EAC3BC,UAAU,EAAE,EACZC,MAAMC,aAAa,EACnBC,UAAUC,iBAAiB,EAC3BC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,OAAOC,cAAc,EACrBC,KAAK,EACN,GAAGvB;IAEJ,MAAM,EAAEwB,IAAI,EAAE,GAAGlC;IAEjB,MAAMmC,mBAAmBrC,YACvB,CAACiC,OAAOK;QACN,IAAI,OAAON,aAAa,YACtB,OAAOA,SAASC,OAAO;YAAE,GAAGK,iBAAiB;YAA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,CAAC,MAAM,EAAE1B,KAAK,CAAC,EAAE8B,YAAY,EAAEpB,OAAO,CAAC,CAAC,EAAEA,KAAK,CAAC,GAAG,GAAG,CAAC;4BAElE,qBACE,KAACuB;0CACC,cAAA,KAACrD;oCACC8C,IAAIA;oCACJK,YAAYA;oCACZlC,UAAU;wCACR,IAAI,OAAOC,sBAAsB,YAAY;4CAC3CA,kBAAkBgC;wCACpB;wCAEA,IAAI,CAACV,UAAU;4CACbH,SAASa;wCACX;oCACF;oCACAD,QAAQzD,eAAeyD,UAAUA,SAAS;wCAAEnC,OAAOmC;wCAAQtB,OAAOsB;oCAAO;oCACzE7B,MAAMA;oCACNE,UAAUkB;oCACVV,MAAMA;;+BAhBD,CAAC,EAAEV,KAAK,GAAG,EAAE8B,YAAY,CAAC;wBAoBvC;;oBAED1C,sBAAsB8C,YACrB9C,kCAEA,KAACN;wBAAkB,GAAIU,oBAAoB,CAAC,CAAC;;;;;;AAKvD;AAEA,OAAO,MAAM2C,aAAazD,cAAcO,iBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Relationship/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA+D,MAAM,OAAO,CAAA;AAGnF,OAAO,KAAK,EAAsB,sBAAsB,EAAS,MAAM,YAAY,CAAA;AAkBnF,OAAO,cAAc,CAAA;AASrB,OAAO,EAAE,sBAAsB,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Relationship/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA+D,MAAM,OAAO,CAAA;AAGnF,OAAO,KAAK,EAAsB,sBAAsB,EAAS,MAAM,YAAY,CAAA;AAkBnF,OAAO,cAAc,CAAA;AASrB,OAAO,EAAE,sBAAsB,EAAE,CAAA;AA6jBjC,eAAO,MAAM,YAAY,kCAAmC,CAAA"}
|
|
@@ -54,7 +54,7 @@ const RelationshipField = (props)=>{
|
|
|
54
54
|
]);
|
|
55
55
|
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
56
56
|
const { filterOptions, formInitializing, formProcessing, initialValue, path, setValue, showError, value } = useField({
|
|
57
|
-
path: pathFromContext
|
|
57
|
+
path: pathFromContext ?? pathFromProps ?? name,
|
|
58
58
|
validate: memoizedValidate
|
|
59
59
|
});
|
|
60
60
|
const readOnly = readOnlyFromProps || readOnlyFromContext || formInitializing;
|
|
@@ -126,11 +126,15 @@ const RelationshipField = (props)=>{
|
|
|
126
126
|
if (relationFilterOption && typeof relationFilterOption !== 'boolean') {
|
|
127
127
|
query.where.and.push(relationFilterOption);
|
|
128
128
|
}
|
|
129
|
-
const response = await fetch(`${serverURL}${api}/${relation}
|
|
129
|
+
const response = await fetch(`${serverURL}${api}/${relation}`, {
|
|
130
|
+
body: qs.stringify(query),
|
|
130
131
|
credentials: 'include',
|
|
131
132
|
headers: {
|
|
132
|
-
'Accept-Language': i18n.language
|
|
133
|
-
|
|
133
|
+
'Accept-Language': i18n.language,
|
|
134
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
135
|
+
'X-HTTP-Method-Override': 'GET'
|
|
136
|
+
},
|
|
137
|
+
method: 'POST'
|
|
134
138
|
});
|
|
135
139
|
if (response.ok) {
|
|
136
140
|
const data = await response.json();
|
|
@@ -237,11 +241,15 @@ const RelationshipField = (props)=>{
|
|
|
237
241
|
}
|
|
238
242
|
};
|
|
239
243
|
if (!errorLoading) {
|
|
240
|
-
const response = await fetch(`${serverURL}${api}/${relation}
|
|
244
|
+
const response = await fetch(`${serverURL}${api}/${relation}`, {
|
|
245
|
+
body: qs.stringify(query),
|
|
241
246
|
credentials: 'include',
|
|
242
247
|
headers: {
|
|
243
|
-
'Accept-Language': i18n.language
|
|
244
|
-
|
|
248
|
+
'Accept-Language': i18n.language,
|
|
249
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
250
|
+
'X-HTTP-Method-Override': 'GET'
|
|
251
|
+
},
|
|
252
|
+
method: 'POST'
|
|
245
253
|
});
|
|
246
254
|
const collection = collections.find((coll)=>coll.slug === relation);
|
|
247
255
|
let docs = [];
|
|
@@ -422,7 +430,7 @@ const RelationshipField = (props)=>{
|
|
|
422
430
|
onChange: !readOnly ? (selected)=>{
|
|
423
431
|
if (selected === null) {
|
|
424
432
|
setValue(hasMany ? [] : null);
|
|
425
|
-
} else if (hasMany) {
|
|
433
|
+
} else if (hasMany && Array.isArray(selected)) {
|
|
426
434
|
setValue(selected ? selected.map((option)=>{
|
|
427
435
|
if (hasMultipleRelations) {
|
|
428
436
|
return {
|
|
@@ -432,12 +440,12 @@ const RelationshipField = (props)=>{
|
|
|
432
440
|
}
|
|
433
441
|
return option.value;
|
|
434
442
|
}) : null);
|
|
435
|
-
} else if (hasMultipleRelations) {
|
|
443
|
+
} else if (hasMultipleRelations && !Array.isArray(selected)) {
|
|
436
444
|
setValue({
|
|
437
445
|
relationTo: selected.relationTo,
|
|
438
446
|
value: selected.value
|
|
439
447
|
});
|
|
440
|
-
} else {
|
|
448
|
+
} else if (!Array.isArray(selected)) {
|
|
441
449
|
setValue(selected.value);
|
|
442
450
|
}
|
|
443
451
|
} : undefined,
|