@payloadcms/plugin-form-builder 3.0.0-canary.92e4997 → 3.0.0-canary.c13f9ba
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/collections/FormSubmissions/hooks/createCharge.d.ts +3 -0
- package/dist/collections/FormSubmissions/hooks/createCharge.d.ts.map +1 -0
- package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts +3 -0
- package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts.map +1 -0
- package/dist/collections/FormSubmissions/index.d.ts +4 -0
- package/dist/collections/FormSubmissions/index.d.ts.map +1 -0
- package/dist/collections/FormSubmissions/index.js +62 -60
- package/dist/collections/FormSubmissions/index.js.map +1 -1
- package/dist/collections/Forms/DynamicFieldSelector.d.ts +4 -0
- package/dist/collections/Forms/DynamicFieldSelector.d.ts.map +1 -0
- package/dist/collections/Forms/DynamicFieldSelector.js +2 -1
- package/dist/collections/Forms/DynamicFieldSelector.js.map +1 -1
- package/dist/collections/Forms/DynamicPriceSelector.d.ts +4 -0
- package/dist/collections/Forms/DynamicPriceSelector.d.ts.map +1 -0
- package/dist/collections/Forms/DynamicPriceSelector.js +17 -6
- package/dist/collections/Forms/DynamicPriceSelector.js.map +1 -1
- package/dist/collections/Forms/fields.d.ts +6 -0
- package/dist/collections/Forms/fields.d.ts.map +1 -0
- package/dist/collections/Forms/index.d.ts +4 -0
- package/dist/collections/Forms/index.d.ts.map +1 -0
- package/dist/collections/Forms/index.js +146 -144
- package/dist/collections/Forms/index.js.map +1 -1
- package/dist/exports/types.d.ts +2 -0
- package/dist/exports/types.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +0 -14
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +182 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -1
- package/dist/utilities/getPaymentTotal.d.ts +5 -0
- package/dist/utilities/getPaymentTotal.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/heading.d.ts +3 -0
- package/dist/utilities/lexical/converters/heading.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/linebreak.d.ts +3 -0
- package/dist/utilities/lexical/converters/linebreak.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/link.d.ts +3 -0
- package/dist/utilities/lexical/converters/link.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/list.d.ts +4 -0
- package/dist/utilities/lexical/converters/list.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/paragraph.d.ts +3 -0
- package/dist/utilities/lexical/converters/paragraph.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/quote.d.ts +3 -0
- package/dist/utilities/lexical/converters/quote.d.ts.map +1 -0
- package/dist/utilities/lexical/converters/text.d.ts +3 -0
- package/dist/utilities/lexical/converters/text.d.ts.map +1 -0
- package/dist/utilities/lexical/defaultConverters.d.ts +3 -0
- package/dist/utilities/lexical/defaultConverters.d.ts.map +1 -0
- package/dist/utilities/lexical/nodeFormat.d.ts +39 -0
- package/dist/utilities/lexical/nodeFormat.d.ts.map +1 -0
- package/dist/utilities/lexical/serializeLexical.d.ts +9 -0
- package/dist/utilities/lexical/serializeLexical.d.ts.map +1 -0
- package/dist/utilities/lexical/types.d.ts +14 -0
- package/dist/utilities/lexical/types.d.ts.map +1 -0
- package/dist/utilities/replaceDoubleCurlys.d.ts +8 -0
- package/dist/utilities/replaceDoubleCurlys.d.ts.map +1 -0
- package/dist/utilities/slate/serializeSlate.d.ts +12 -0
- package/dist/utilities/slate/serializeSlate.d.ts.map +1 -0
- package/package.json +13 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCharge.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAEhE,eAAO,MAAM,YAAY,qBACL,GAAG,cACT,uBAAuB,KAClC,QAAQ,GAAG,CAeb,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendEmail.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,uBAAuB,EAAkB,MAAM,mBAAmB,CAAA;AAMvF,eAAO,MAAM,SAAS,qBACF,GAAG,cACT,uBAAuB,KAClC,QAAQ,GAAG,CA6Fb,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/FormSubmissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,eAAe,CAAA;AAE5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAM7D,eAAO,MAAM,4BAA4B,eAC3B,uBAAuB,KAClC,gBA6JF,CAAA"}
|
|
@@ -3,6 +3,65 @@ import { sendEmail } from './hooks/sendEmail.js';
|
|
|
3
3
|
// all settings can be overridden by the config
|
|
4
4
|
export const generateSubmissionCollection = (formConfig)=>{
|
|
5
5
|
const formSlug = formConfig?.formOverrides?.slug || 'forms';
|
|
6
|
+
const defaultFields = [
|
|
7
|
+
{
|
|
8
|
+
name: 'form',
|
|
9
|
+
type: 'relationship',
|
|
10
|
+
admin: {
|
|
11
|
+
readOnly: true
|
|
12
|
+
},
|
|
13
|
+
relationTo: formSlug,
|
|
14
|
+
required: true,
|
|
15
|
+
validate: async (value, { req: { payload }, req })=>{
|
|
16
|
+
/* Don't run in the client side */ if (!payload) return true;
|
|
17
|
+
if (payload) {
|
|
18
|
+
let _existingForm;
|
|
19
|
+
try {
|
|
20
|
+
_existingForm = await payload.findByID({
|
|
21
|
+
id: value,
|
|
22
|
+
collection: formSlug,
|
|
23
|
+
req
|
|
24
|
+
});
|
|
25
|
+
return true;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return 'Cannot create this submission because this form does not exist.';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'submissionData',
|
|
34
|
+
type: 'array',
|
|
35
|
+
admin: {
|
|
36
|
+
readOnly: true
|
|
37
|
+
},
|
|
38
|
+
fields: [
|
|
39
|
+
{
|
|
40
|
+
name: 'field',
|
|
41
|
+
type: 'text',
|
|
42
|
+
required: true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'value',
|
|
46
|
+
type: 'text',
|
|
47
|
+
required: true,
|
|
48
|
+
validate: (value)=>{
|
|
49
|
+
// TODO:
|
|
50
|
+
// create a validation function that dynamically
|
|
51
|
+
// relies on the field type and its options as configured.
|
|
52
|
+
// How to access sibling data from this field?
|
|
53
|
+
// Need the `name` of the field in order to validate it.
|
|
54
|
+
// Might not be possible to use this validation function.
|
|
55
|
+
// Instead, might need to do all validation in a `beforeValidate` collection hook.
|
|
56
|
+
if (typeof value !== 'undefined') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return 'This field is required.';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
];
|
|
6
65
|
const newConfig = {
|
|
7
66
|
...formConfig?.formSubmissionOverrides || {},
|
|
8
67
|
slug: formConfig?.formSubmissionOverrides?.slug || 'form-submissions',
|
|
@@ -16,66 +75,9 @@ export const generateSubmissionCollection = (formConfig)=>{
|
|
|
16
75
|
...formConfig?.formSubmissionOverrides?.admin || {},
|
|
17
76
|
enableRichTextRelationship: false
|
|
18
77
|
},
|
|
19
|
-
fields:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type: 'relationship',
|
|
23
|
-
admin: {
|
|
24
|
-
readOnly: true
|
|
25
|
-
},
|
|
26
|
-
relationTo: formSlug,
|
|
27
|
-
required: true,
|
|
28
|
-
validate: async (value, { req: { payload }, req })=>{
|
|
29
|
-
/* Don't run in the client side */ if (!payload) return true;
|
|
30
|
-
if (payload) {
|
|
31
|
-
let _existingForm;
|
|
32
|
-
try {
|
|
33
|
-
_existingForm = await payload.findByID({
|
|
34
|
-
id: value,
|
|
35
|
-
collection: formSlug,
|
|
36
|
-
req
|
|
37
|
-
});
|
|
38
|
-
return true;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return 'Cannot create this submission because this form does not exist.';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'submissionData',
|
|
47
|
-
type: 'array',
|
|
48
|
-
admin: {
|
|
49
|
-
readOnly: true
|
|
50
|
-
},
|
|
51
|
-
fields: [
|
|
52
|
-
{
|
|
53
|
-
name: 'field',
|
|
54
|
-
type: 'text',
|
|
55
|
-
required: true
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'value',
|
|
59
|
-
type: 'text',
|
|
60
|
-
required: true,
|
|
61
|
-
validate: (value)=>{
|
|
62
|
-
// TODO:
|
|
63
|
-
// create a validation function that dynamically
|
|
64
|
-
// relies on the field type and its options as configured.
|
|
65
|
-
// How to access sibling data from this field?
|
|
66
|
-
// Need the `name` of the field in order to validate it.
|
|
67
|
-
// Might not be possible to use this validation function.
|
|
68
|
-
// Instead, might need to do all validation in a `beforeValidate` collection hook.
|
|
69
|
-
if (typeof value !== 'undefined') {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
return 'This field is required.';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
},
|
|
77
|
-
...formConfig?.formSubmissionOverrides?.fields || []
|
|
78
|
-
],
|
|
78
|
+
fields: formConfig?.formSubmissionOverrides?.fields && typeof formConfig?.formSubmissionOverrides?.fields === 'function' ? formConfig?.formSubmissionOverrides?.fields({
|
|
79
|
+
defaultFields
|
|
80
|
+
}) : defaultFields,
|
|
79
81
|
hooks: {
|
|
80
82
|
...formConfig?.formSubmissionOverrides?.hooks || {},
|
|
81
83
|
beforeChange: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/FormSubmissions/index.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { FormBuilderPluginConfig } from '../../types.js'\n\nimport { createCharge } from './hooks/createCharge.js'\nimport { sendEmail } from './hooks/sendEmail.js'\n\n// all settings can be overridden by the config\nexport const generateSubmissionCollection = (\n formConfig: FormBuilderPluginConfig,\n): CollectionConfig => {\n const formSlug = formConfig?.formOverrides?.slug || 'forms'\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/FormSubmissions/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload/types'\n\nimport type { FormBuilderPluginConfig } from '../../types.js'\n\nimport { createCharge } from './hooks/createCharge.js'\nimport { sendEmail } from './hooks/sendEmail.js'\n\n// all settings can be overridden by the config\nexport const generateSubmissionCollection = (\n formConfig: FormBuilderPluginConfig,\n): CollectionConfig => {\n const formSlug = formConfig?.formOverrides?.slug || 'forms'\n\n const defaultFields: Field[] = [\n {\n name: 'form',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: formSlug,\n required: true,\n validate: async (value, { req: { payload }, req }) => {\n /* Don't run in the client side */\n if (!payload) return true\n\n if (payload) {\n let _existingForm\n\n try {\n _existingForm = await payload.findByID({\n id: value,\n collection: formSlug,\n req,\n })\n\n return true\n } catch (error) {\n return 'Cannot create this submission because this form does not exist.'\n }\n }\n },\n },\n {\n name: 'submissionData',\n type: 'array',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n required: true,\n validate: (value: unknown) => {\n // TODO:\n // create a validation function that dynamically\n // relies on the field type and its options as configured.\n\n // How to access sibling data from this field?\n // Need the `name` of the field in order to validate it.\n\n // Might not be possible to use this validation function.\n // Instead, might need to do all validation in a `beforeValidate` collection hook.\n\n if (typeof value !== 'undefined') {\n return true\n }\n\n return 'This field is required.'\n },\n },\n ],\n },\n ]\n\n const newConfig: CollectionConfig = {\n ...(formConfig?.formSubmissionOverrides || {}),\n slug: formConfig?.formSubmissionOverrides?.slug || 'form-submissions',\n access: {\n create: () => true,\n read: ({ req: { user } }) => !!user, // logged-in users,\n update: () => false,\n ...(formConfig?.formSubmissionOverrides?.access || {}),\n },\n admin: {\n ...(formConfig?.formSubmissionOverrides?.admin || {}),\n enableRichTextRelationship: false,\n },\n fields:\n formConfig?.formSubmissionOverrides?.fields &&\n typeof formConfig?.formSubmissionOverrides?.fields === 'function'\n ? formConfig?.formSubmissionOverrides?.fields({ defaultFields })\n : defaultFields,\n hooks: {\n ...(formConfig?.formSubmissionOverrides?.hooks || {}),\n beforeChange: [\n (data) => createCharge(data, formConfig),\n (data) => sendEmail(data, formConfig),\n ...(formConfig?.formSubmissionOverrides?.hooks?.beforeChange || []),\n ],\n },\n }\n\n const paymentFieldConfig = formConfig?.fields?.payment\n\n if (paymentFieldConfig) {\n newConfig.fields.push({\n name: 'payment',\n type: 'group',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n label: 'Field',\n },\n {\n name: 'status',\n type: 'text',\n label: 'Status',\n },\n {\n name: 'amount',\n type: 'number',\n admin: {\n description: 'Amount in cents',\n },\n },\n {\n name: 'paymentProcessor',\n type: 'text',\n },\n {\n name: 'creditCard',\n type: 'group',\n fields: [\n {\n name: 'token',\n type: 'text',\n label: 'token',\n },\n {\n name: 'brand',\n type: 'text',\n label: 'Brand',\n },\n {\n name: 'number',\n type: 'text',\n label: 'Number',\n },\n ],\n label: 'Credit Card',\n },\n ],\n })\n }\n\n return newConfig\n}\n"],"names":["createCharge","sendEmail","generateSubmissionCollection","formConfig","formSlug","formOverrides","slug","defaultFields","name","type","admin","readOnly","relationTo","required","validate","value","req","payload","_existingForm","findByID","id","collection","error","fields","newConfig","formSubmissionOverrides","access","create","read","user","update","enableRichTextRelationship","hooks","beforeChange","data","paymentFieldConfig","payment","push","label","description"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicFieldSelector.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAIhE,OAAO,KAA8B,MAAM,OAAO,CAAA;AAIlD,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA8BzD,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { Select } from '@payloadcms/ui/fields/Select';
|
|
3
4
|
import { useForm } from '@payloadcms/ui/forms/Form';
|
|
4
5
|
import React, { useEffect, useState } from 'react';
|
|
@@ -26,7 +27,7 @@ export const DynamicFieldSelector = (props)=>{
|
|
|
26
27
|
]);
|
|
27
28
|
// TODO: label from config is Record<string, string> | false | string
|
|
28
29
|
// but the FormFieldBase type has only label?: string, changing FormFieldBase breaks other ui components
|
|
29
|
-
return /*#__PURE__*/
|
|
30
|
+
return /*#__PURE__*/ _jsx(Select, {
|
|
30
31
|
...props,
|
|
31
32
|
options: options
|
|
32
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"sourcesContent":["'use client'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"sourcesContent":["'use client'\n\nimport type { TextFieldProps } from '@payloadcms/ui/fields/Text'\n\nimport { Select } from '@payloadcms/ui/fields/Select'\nimport { useForm } from '@payloadcms/ui/forms/Form'\nimport React, { useEffect, useState } from 'react'\n\nimport type { SelectFieldOption } from '../../types.js'\n\nexport const DynamicFieldSelector: React.FC<TextFieldProps> = (props) => {\n const { fields, getDataByPath } = useForm()\n\n const [options, setOptions] = useState<SelectFieldOption[]>([])\n\n useEffect(() => {\n const fields: any[] = getDataByPath('fields')\n\n if (fields) {\n const allNonPaymentFields = fields\n .map((block): SelectFieldOption | null => {\n const { name, blockType, label } = block\n\n if (blockType !== 'payment') {\n return {\n label,\n value: name,\n }\n }\n\n return null\n })\n .filter(Boolean)\n setOptions(allNonPaymentFields)\n }\n }, [fields, getDataByPath])\n\n // TODO: label from config is Record<string, string> | false | string\n // but the FormFieldBase type has only label?: string, changing FormFieldBase breaks other ui components\n return <Select {...props} options={options} />\n}\n"],"names":["Select","useForm","React","useEffect","useState","DynamicFieldSelector","props","fields","getDataByPath","options","setOptions","allNonPaymentFields","map","block","name","blockType","label","value","filter","Boolean"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,SAASA,MAAM,QAAQ,+BAA8B;AACrD,SAASC,OAAO,QAAQ,4BAA2B;AACnD,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAIlD,OAAO,MAAMC,uBAAiD,CAACC;IAC7D,MAAM,EAAEC,MAAM,EAAEC,aAAa,EAAE,GAAGP;IAElC,MAAM,CAACQ,SAASC,WAAW,GAAGN,SAA8B,EAAE;IAE9DD,UAAU;QACR,MAAMI,SAAgBC,cAAc;QAEpC,IAAID,QAAQ;YACV,MAAMI,sBAAsBJ,OACzBK,GAAG,CAAC,CAACC;gBACJ,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGH;gBAEnC,IAAIE,cAAc,WAAW;oBAC3B,OAAO;wBACLC;wBACAC,OAAOH;oBACT;gBACF;gBAEA,OAAO;YACT,GACCI,MAAM,CAACC;YACVT,WAAWC;QACb;IACF,GAAG;QAACJ;QAAQC;KAAc;IAE1B,qEAAqE;IACrE,yGAAyG;IACzG,qBAAO,KAACR;QAAQ,GAAGM,KAAK;QAAEG,SAASA;;AACrC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicPriceSelector.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAMhE,OAAO,KAA8B,MAAM,OAAO,CAAA;AAOlD,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA2DzD,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { Text } from '@payloadcms/ui/fields/Text';
|
|
3
4
|
import { useWatchForm } from '@payloadcms/ui/forms/Form';
|
|
4
5
|
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
|
@@ -33,7 +34,9 @@ export const DynamicPriceSelector = (props)=>{
|
|
|
33
34
|
]);
|
|
34
35
|
// TODO: make this a number field, block by Payload
|
|
35
36
|
if (valueType === 'static') {
|
|
36
|
-
return /*#__PURE__*/
|
|
37
|
+
return /*#__PURE__*/ _jsx(Text, {
|
|
38
|
+
...props
|
|
39
|
+
});
|
|
37
40
|
}
|
|
38
41
|
const localeCode = typeof locale === 'object' && 'code' in locale ? locale.code : locale;
|
|
39
42
|
const localLabels = typeof label === 'object' ? label : {
|
|
@@ -41,11 +44,19 @@ export const DynamicPriceSelector = (props)=>{
|
|
|
41
44
|
};
|
|
42
45
|
const labelValue = localLabels[localeCode] || localLabels['en'] || '';
|
|
43
46
|
if (valueType === 'valueOfField' && !isNumberField) {
|
|
44
|
-
return /*#__PURE__*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
48
|
+
children: [
|
|
49
|
+
/*#__PURE__*/ _jsx("div", {
|
|
50
|
+
children: String(labelValue)
|
|
51
|
+
}),
|
|
52
|
+
/*#__PURE__*/ _jsx("div", {
|
|
53
|
+
style: {
|
|
54
|
+
color: '#9A9A9A'
|
|
55
|
+
},
|
|
56
|
+
children: "The selected field must be a number field."
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
49
60
|
}
|
|
50
61
|
return null;
|
|
51
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"sourcesContent":["'use client'\n\nimport type { TextFieldProps } from '@payloadcms/ui/fields/Text'\nimport type { Data } from 'payload/types'\n\nimport { Text } from '@payloadcms/ui/fields/Text'\nimport { useWatchForm } from '@payloadcms/ui/forms/Form'\nimport { useLocale } from '@payloadcms/ui/providers/Locale'\nimport React, { useEffect, useState } from 'react'\n\ntype FieldWithID = {\n id: string\n name: string\n}\n\nexport const DynamicPriceSelector: React.FC<TextFieldProps> = (props) => {\n const { label, path } = props\n\n const { fields, getData, getDataByPath } = useWatchForm()\n\n const locale = useLocale()\n\n const [isNumberField, setIsNumberField] = useState<boolean>()\n const [valueType, setValueType] = useState<'static' | 'valueOfField'>()\n\n // only number fields can use 'valueOfField`\n useEffect(() => {\n if (path) {\n const parentPath = path.split('.').slice(0, -1).join('.')\n const paymentFieldData: any = getDataByPath(parentPath)\n\n if (paymentFieldData) {\n const { fieldToUse, valueType } = paymentFieldData\n\n setValueType(valueType)\n\n const { fields: allFields }: Data = getData()\n const field = allFields.find((field: FieldWithID) => field.name === fieldToUse)\n\n if (field) {\n const { blockType } = field\n setIsNumberField(blockType === 'number')\n }\n }\n }\n }, [fields, path, getDataByPath, getData])\n\n // TODO: make this a number field, block by Payload\n if (valueType === 'static') {\n return <Text {...props} />\n }\n\n const localeCode = typeof locale === 'object' && 'code' in locale ? locale.code : locale\n\n const localLabels = typeof label === 'object' ? label : { [localeCode]: label }\n const labelValue = localLabels[localeCode] || localLabels['en'] || ''\n\n if (valueType === 'valueOfField' && !isNumberField) {\n return (\n <div>\n <div>{labelValue}</div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n The selected field must be a number field.\n </div>\n </div>\n )\n }\n\n return null\n}\n"],"names":["Text","useWatchForm","useLocale","React","useEffect","useState","DynamicPriceSelector","props","label","path","fields","getData","getDataByPath","locale","isNumberField","setIsNumberField","valueType","setValueType","parentPath","split","slice","join","paymentFieldData","fieldToUse","allFields","field","find","name","blockType","localeCode","code","localLabels","labelValue","div","style","color"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"sourcesContent":["'use client'\n\nimport type { TextFieldProps } from '@payloadcms/ui/fields/Text'\nimport type { Data } from 'payload/types'\n\nimport { Text } from '@payloadcms/ui/fields/Text'\nimport { useWatchForm } from '@payloadcms/ui/forms/Form'\nimport { useLocale } from '@payloadcms/ui/providers/Locale'\nimport React, { useEffect, useState } from 'react'\n\ntype FieldWithID = {\n id: string\n name: string\n}\n\nexport const DynamicPriceSelector: React.FC<TextFieldProps> = (props) => {\n const { label, path } = props\n\n const { fields, getData, getDataByPath } = useWatchForm()\n\n const locale = useLocale()\n\n const [isNumberField, setIsNumberField] = useState<boolean>()\n const [valueType, setValueType] = useState<'static' | 'valueOfField'>()\n\n // only number fields can use 'valueOfField`\n useEffect(() => {\n if (path) {\n const parentPath = path.split('.').slice(0, -1).join('.')\n const paymentFieldData: any = getDataByPath(parentPath)\n\n if (paymentFieldData) {\n const { fieldToUse, valueType } = paymentFieldData\n\n setValueType(valueType)\n\n const { fields: allFields }: Data = getData()\n const field = allFields.find((field: FieldWithID) => field.name === fieldToUse)\n\n if (field) {\n const { blockType } = field\n setIsNumberField(blockType === 'number')\n }\n }\n }\n }, [fields, path, getDataByPath, getData])\n\n // TODO: make this a number field, block by Payload\n if (valueType === 'static') {\n return <Text {...props} />\n }\n\n const localeCode = typeof locale === 'object' && 'code' in locale ? locale.code : locale\n\n const localLabels = typeof label === 'object' ? label : { [localeCode]: label }\n\n const labelValue = localLabels[localeCode] || localLabels['en'] || ''\n\n if (valueType === 'valueOfField' && !isNumberField) {\n return (\n <div>\n <div>{String(labelValue)}</div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n The selected field must be a number field.\n </div>\n </div>\n )\n }\n\n return null\n}\n"],"names":["Text","useWatchForm","useLocale","React","useEffect","useState","DynamicPriceSelector","props","label","path","fields","getData","getDataByPath","locale","isNumberField","setIsNumberField","valueType","setValueType","parentPath","split","slice","join","paymentFieldData","fieldToUse","allFields","field","find","name","blockType","localeCode","code","localLabels","labelValue","div","String","style","color"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAKA,SAASA,IAAI,QAAQ,6BAA4B;AACjD,SAASC,YAAY,QAAQ,4BAA2B;AACxD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAOlD,OAAO,MAAMC,uBAAiD,CAACC;IAC7D,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAE,GAAGF;IAExB,MAAM,EAAEG,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAE,GAAGX;IAE3C,MAAMY,SAASX;IAEf,MAAM,CAACY,eAAeC,iBAAiB,GAAGV;IAC1C,MAAM,CAACW,WAAWC,aAAa,GAAGZ;IAElC,4CAA4C;IAC5CD,UAAU;QACR,IAAIK,MAAM;YACR,MAAMS,aAAaT,KAAKU,KAAK,CAAC,KAAKC,KAAK,CAAC,GAAG,CAAC,GAAGC,IAAI,CAAC;YACrD,MAAMC,mBAAwBV,cAAcM;YAE5C,IAAII,kBAAkB;gBACpB,MAAM,EAAEC,UAAU,EAAEP,SAAS,EAAE,GAAGM;gBAElCL,aAAaD;gBAEb,MAAM,EAAEN,QAAQc,SAAS,EAAE,GAASb;gBACpC,MAAMc,QAAQD,UAAUE,IAAI,CAAC,CAACD,QAAuBA,MAAME,IAAI,KAAKJ;gBAEpE,IAAIE,OAAO;oBACT,MAAM,EAAEG,SAAS,EAAE,GAAGH;oBACtBV,iBAAiBa,cAAc;gBACjC;YACF;QACF;IACF,GAAG;QAAClB;QAAQD;QAAMG;QAAeD;KAAQ;IAEzC,mDAAmD;IACnD,IAAIK,cAAc,UAAU;QAC1B,qBAAO,KAAChB;YAAM,GAAGO,KAAK;;IACxB;IAEA,MAAMsB,aAAa,OAAOhB,WAAW,YAAY,UAAUA,SAASA,OAAOiB,IAAI,GAAGjB;IAElF,MAAMkB,cAAc,OAAOvB,UAAU,WAAWA,QAAQ;QAAE,CAACqB,WAAW,EAAErB;IAAM;IAE9E,MAAMwB,aAAaD,WAAW,CAACF,WAAW,IAAIE,WAAW,CAAC,KAAK,IAAI;IAEnE,IAAIf,cAAc,kBAAkB,CAACF,eAAe;QAClD,qBACE,MAACmB;;8BACC,KAACA;8BAAKC,OAAOF;;8BACb,KAACC;oBACCE,OAAO;wBACLC,OAAO;oBACT;8BACD;;;;IAKP;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAA;AA6jBrE,eAAO,MAAM,MAAM;2CAYc,WAAW,GAAG,OAAO,KAAK,KAAK;CAC/D,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,gBAAgB,EAAS,MAAM,eAAe,CAAA;AAInE,OAAO,KAAK,EAAe,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAK1E,eAAO,MAAM,sBAAsB,eAAgB,uBAAuB,KAAG,gBAqO5E,CAAA"}
|