form-craft-package 1.3.3 → 1.4.0
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/package.json +1 -1
- package/src/components/common/color-field.tsx +42 -0
- package/src/components/form/layout-renderer/3-element/2-field-element.tsx +6 -1
- package/src/components/form/layout-renderer/3-element/3-read-only.tsx +4 -4
- package/src/components/form/layout-renderer/3-element/9-form-data-render.tsx +26 -18
- package/src/enums.ts +1 -1
- package/src/types/index.ts +2 -0
- package/src/types/layout-elements/index.ts +9 -6
- package/src/types/relationship/index.ts +18 -3
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Form, FormInstance } from 'antd'
|
|
2
|
+
import { useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
export default function CustomColorField({ formRef, name, isPreview, disabled }: ICustomColorField) {
|
|
5
|
+
const colorInputRef = useRef<HTMLInputElement>(null)
|
|
6
|
+
const [fieldValue, setFieldValue] = useState('')
|
|
7
|
+
|
|
8
|
+
const color = Form.useWatch(name, formRef)
|
|
9
|
+
|
|
10
|
+
if (!isPreview && !formRef)
|
|
11
|
+
<div className="text-warning italic leading-4">Form instance is missing for color field!</div>
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
className={`flex items-center gap-2 border bg-white rounded-lg w-full p-1 ${
|
|
16
|
+
isPreview || disabled ? 'cursor-not-allowed' : 'cursor-pointer'
|
|
17
|
+
}`}
|
|
18
|
+
onClick={() => colorInputRef.current?.click()}
|
|
19
|
+
>
|
|
20
|
+
<input
|
|
21
|
+
type="color"
|
|
22
|
+
ref={colorInputRef}
|
|
23
|
+
value={fieldValue ?? color}
|
|
24
|
+
onChange={(e) => setFieldValue(e.target.value)}
|
|
25
|
+
className={`opacity-0 absolute w-[24px] h-[24px] ${
|
|
26
|
+
isPreview || disabled ? 'cursor-not-allowed' : 'cursor-pointer'
|
|
27
|
+
}`}
|
|
28
|
+
onBlur={() => formRef?.setFieldValue(name, fieldValue)}
|
|
29
|
+
disabled={isPreview}
|
|
30
|
+
/>
|
|
31
|
+
<div className="w-[24px] h-[24px] rounded cursor-pointer border" style={{ backgroundColor: color }}></div>
|
|
32
|
+
<span className="uppercase pr-1">{color}</span>
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ICustomColorField {
|
|
38
|
+
isPreview?: boolean
|
|
39
|
+
formRef?: FormInstance
|
|
40
|
+
name?: string | (string | number)[]
|
|
41
|
+
disabled?: boolean
|
|
42
|
+
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
Switch,
|
|
19
19
|
FormInstance,
|
|
20
20
|
} from 'antd'
|
|
21
|
+
import CustomColorField from '../../../common/color-field'
|
|
21
22
|
|
|
22
23
|
export const LayoutRenderer_FieldElement = ({
|
|
23
24
|
fields,
|
|
@@ -49,7 +50,11 @@ export const LayoutRenderer_FieldElement = ({
|
|
|
49
50
|
return value
|
|
50
51
|
}}
|
|
51
52
|
>
|
|
52
|
-
{
|
|
53
|
+
{field.type === ElementTypeEnum.ColorPicker ? (
|
|
54
|
+
<CustomColorField formRef={formRef} name={field.name} disabled={field.disabled} />
|
|
55
|
+
) : (
|
|
56
|
+
getField(field)
|
|
57
|
+
)}
|
|
53
58
|
</Form.Item>
|
|
54
59
|
{field.disabled && field.type !== ElementTypeEnum.Checkbox && <DisabledFieldIndicator />}
|
|
55
60
|
</Fragment>
|
|
@@ -6,10 +6,10 @@ import { useMemo } from 'react'
|
|
|
6
6
|
import { DataRenderTypeEnum } from '../../../../enums'
|
|
7
7
|
import { IFormItemPath } from '.'
|
|
8
8
|
|
|
9
|
-
export default function LayoutRenderer_ReadOnly({ formRef,
|
|
9
|
+
export default function LayoutRenderer_ReadOnly({ formRef, elementProps }: ILayoutRenderer_ReadOnly) {
|
|
10
10
|
const fieldValue = elementProps.isHardCoded
|
|
11
11
|
? elementProps.value
|
|
12
|
-
: Form.useWatch(
|
|
12
|
+
: Form.useWatch(elementProps.value, { form: formRef, preserve: true })
|
|
13
13
|
const { baseServerUrl, companyKey } = useFormPreservedItemValues(formRef)
|
|
14
14
|
|
|
15
15
|
const formValues = Form.useWatch([], { form: formRef, preserve: true })
|
|
@@ -21,7 +21,7 @@ export default function LayoutRenderer_ReadOnly({ formRef, fullPath, elementProp
|
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<div className="flex items-center gap-2">
|
|
24
|
-
<span>{elementProps.label}: </span>
|
|
24
|
+
{elementProps.label && <span>{elementProps.label}: </span>}
|
|
25
25
|
<span className="font-bold">
|
|
26
26
|
{renderData(
|
|
27
27
|
elementProps.renderConfig?.type === DataRenderTypeEnum.Image
|
|
@@ -29,7 +29,7 @@ export default function LayoutRenderer_ReadOnly({ formRef, fullPath, elementProp
|
|
|
29
29
|
: elementProps.renderConfig?.type === DataRenderTypeEnum.Conditional
|
|
30
30
|
? formValues
|
|
31
31
|
: fieldValue,
|
|
32
|
-
elementProps.renderConfig,
|
|
32
|
+
elementProps.renderConfig ?? { type: DataRenderTypeEnum.Default },
|
|
33
33
|
) ?? 'N/A'}
|
|
34
34
|
</span>
|
|
35
35
|
</div>
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Form, FormInstance } from 'antd'
|
|
2
2
|
import { IFormItemPath } from '.'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
IFormData,
|
|
5
|
+
IFormDataListConfig,
|
|
6
|
+
IFormLayoutRow,
|
|
7
|
+
IFormRelationshipConfig,
|
|
8
|
+
IRelationshipForm,
|
|
9
|
+
} from '../../../../types'
|
|
4
10
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
5
11
|
import client from '../../../../functions/axios-handler'
|
|
6
12
|
import { useFormPreservedItemValues } from '../../../common/custom-hooks/use-preserved-form-items.hook'
|
|
@@ -28,6 +34,7 @@ export default function LayoutRenderer_FormDataRender({ formRef, elementProps }:
|
|
|
28
34
|
async (
|
|
29
35
|
childFormId: number,
|
|
30
36
|
parentFormId: number,
|
|
37
|
+
displayConfigId: string,
|
|
31
38
|
foreignKeyIds: string[],
|
|
32
39
|
parentDataMap: { [id: string]: any },
|
|
33
40
|
): Promise<
|
|
@@ -70,8 +77,11 @@ export default function LayoutRenderer_FormDataRender({ formRef, elementProps }:
|
|
|
70
77
|
}),
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
const displayConfig = relationship.displayConfigs?.find((config) => config.id === displayConfigId)
|
|
81
|
+
if (!displayConfig) return
|
|
82
|
+
|
|
83
|
+
if (displayConfig.isRenderChildForm) {
|
|
84
|
+
if (!displayConfig.renderChildConfig) return
|
|
75
85
|
|
|
76
86
|
const formDataMap: { [id: string]: any } = {}
|
|
77
87
|
const parentDataIds: string[] = []
|
|
@@ -82,8 +92,9 @@ export default function LayoutRenderer_FormDataRender({ formRef, elementProps }:
|
|
|
82
92
|
})
|
|
83
93
|
|
|
84
94
|
const childResData = await fetchFormDetails(
|
|
85
|
-
|
|
95
|
+
displayConfig.renderChildConfig.formId,
|
|
86
96
|
childFormId,
|
|
97
|
+
displayConfig.renderChildConfig.displayConfigId,
|
|
87
98
|
parentDataIds,
|
|
88
99
|
formDataMap,
|
|
89
100
|
)
|
|
@@ -91,7 +102,7 @@ export default function LayoutRenderer_FormDataRender({ formRef, elementProps }:
|
|
|
91
102
|
return childResData
|
|
92
103
|
} else {
|
|
93
104
|
return {
|
|
94
|
-
config:
|
|
105
|
+
config: displayConfig.config as IFormDataListConfig,
|
|
95
106
|
layout: detailsConfig.layout,
|
|
96
107
|
data: {
|
|
97
108
|
...formData,
|
|
@@ -129,14 +140,15 @@ export default function LayoutRenderer_FormDataRender({ formRef, elementProps }:
|
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
if (!hasInitialFetched.current) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
143
|
+
console.log({ form })
|
|
144
|
+
fetchFormDetails(form.id, form.relationshipConfig.formId, form.relationshipConfig.displayConfigId, [formDataId], {
|
|
145
|
+
[formDataId]: formValues,
|
|
146
|
+
}).then((resData) => {
|
|
147
|
+
const { config, data, layout = [] } = resData ?? {}
|
|
148
|
+
|
|
149
|
+
if (config) setDisplayConfig({ dataListConfig: config, detailsLayout: layout })
|
|
150
|
+
if (data) setDataList(data)
|
|
151
|
+
})
|
|
140
152
|
hasInitialFetched.current = true
|
|
141
153
|
}
|
|
142
154
|
}, [form, fetchFormDetails, formDataId, formValues])
|
|
@@ -165,11 +177,7 @@ type ILayoutRenderer_FormDataRender = {
|
|
|
165
177
|
formRef: FormInstance
|
|
166
178
|
elementProps: {
|
|
167
179
|
label?: string
|
|
168
|
-
form?:
|
|
169
|
-
id: number
|
|
170
|
-
name: string
|
|
171
|
-
relationshipConfig: Partial<IFormRelationshipConfig>
|
|
172
|
-
}
|
|
180
|
+
form?: IRelationshipForm
|
|
173
181
|
filterConfig?: { [key: string]: any } | null
|
|
174
182
|
}
|
|
175
183
|
} & IFormItemPath
|
package/src/enums.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
IReCaptchaElement,
|
|
31
31
|
IDataRender_ButtonProps,
|
|
32
32
|
IFormDataRenderElement,
|
|
33
|
+
IColorPickerElement,
|
|
33
34
|
} from './layout-elements'
|
|
34
35
|
import { ICssStyle, IFlexConfig } from './layout-elements/style'
|
|
35
36
|
import { IFormRelationshipConfig } from './relationship'
|
|
@@ -107,6 +108,7 @@ export type IFormLayoutElement =
|
|
|
107
108
|
| ITitleElement
|
|
108
109
|
| IReCaptchaElement
|
|
109
110
|
| IFormDataRenderElement
|
|
111
|
+
| IColorPickerElement
|
|
110
112
|
|
|
111
113
|
export type IMigrationRule = { operation: MigrationReasonOperationEnum.CreateRepeatingSection; fields: string[] }
|
|
112
114
|
// | { operation: MigrationReasonOperationEnum.RenameField; from: string; to: string }
|
|
@@ -2,7 +2,7 @@ export * from './data-render-config'
|
|
|
2
2
|
export * from './field-option-source'
|
|
3
3
|
export * from './style'
|
|
4
4
|
export * from './conditions'
|
|
5
|
-
import { ICssStyle, IFilterConfig,
|
|
5
|
+
import { ICssStyle, IFilterConfig, IRelationshipForm } from '..'
|
|
6
6
|
import { IFieldElementOptionSource } from './field-option-source'
|
|
7
7
|
import { IDataRenderConfig } from './data-render-config'
|
|
8
8
|
import {
|
|
@@ -245,11 +245,14 @@ export interface IFormDataRenderElement extends BaseFormLayoutElement {
|
|
|
245
245
|
elementType: ElementTypeEnum.FormDataRender
|
|
246
246
|
props: {
|
|
247
247
|
hasNoLabel: boolean
|
|
248
|
-
form?:
|
|
249
|
-
id: number
|
|
250
|
-
name: string
|
|
251
|
-
relationshipConfig: Partial<IFormRelationshipConfig>
|
|
252
|
-
}
|
|
248
|
+
form?: IRelationshipForm
|
|
253
249
|
filterConfig?: { [key: string]: any } | null
|
|
254
250
|
}
|
|
255
251
|
}
|
|
252
|
+
export interface IColorPickerElement extends BaseFormLayoutElement {
|
|
253
|
+
elementType: ElementTypeEnum.ColorPicker
|
|
254
|
+
props: {
|
|
255
|
+
label?: string
|
|
256
|
+
description?: string
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -6,18 +6,33 @@ export type IFormRelationshipConfig = {
|
|
|
6
6
|
type: FormRelationshipEnum
|
|
7
7
|
foreignKey: string
|
|
8
8
|
viewType?: NewFormViewTypeEnum
|
|
9
|
+
displayConfigs?: IRelationshipDisplayConfig[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type IRelationshipDisplayConfig = {
|
|
13
|
+
id: string
|
|
14
|
+
name: string
|
|
9
15
|
} & (
|
|
10
16
|
| {
|
|
11
17
|
isRenderChildForm: true
|
|
12
|
-
renderChildConfig?:
|
|
18
|
+
renderChildConfig?: IRelationshipRenderChildConfig
|
|
13
19
|
}
|
|
14
20
|
| {
|
|
15
21
|
isRenderChildForm: false
|
|
16
|
-
|
|
22
|
+
config?: IFormDataListConfig
|
|
17
23
|
}
|
|
18
24
|
)
|
|
19
25
|
|
|
20
|
-
export interface
|
|
26
|
+
export interface IRelationshipRenderChildConfig {
|
|
21
27
|
formId: number
|
|
28
|
+
displayConfigId: string
|
|
22
29
|
filterConfig?: { [key: string]: any } | null
|
|
23
30
|
}
|
|
31
|
+
|
|
32
|
+
export interface IRelationshipForm {
|
|
33
|
+
id: number
|
|
34
|
+
name: string
|
|
35
|
+
relationshipConfig: Partial<IFormRelationshipConfig> & {
|
|
36
|
+
displayConfigId: string
|
|
37
|
+
}
|
|
38
|
+
}
|