@duffcloudservices/site-forms 0.1.1 → 0.1.2
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/README.md +260 -260
- package/dist/index.js.map +1 -1
- package/dist/site-forms.css +1 -0
- package/package.json +72 -73
- package/src/DcsForm.vue +303 -303
- package/src/__tests__/fields.test.ts +82 -82
- package/src/__tests__/multi-step.test.ts +46 -46
- package/src/__tests__/schema.test.ts +42 -42
- package/src/__tests__/style-import.test.ts +9 -0
- package/src/__tests__/submission.test.ts +77 -77
- package/src/__tests__/visible-if.test.ts +111 -111
- package/src/composables/useDcsForm.ts +201 -201
- package/src/composables/useFormSubmission.ts +113 -113
- package/src/composables/useFormValidation.ts +127 -127
- package/src/fields/DcsFormCheckbox.vue +35 -35
- package/src/fields/DcsFormCheckboxGroup.vue +52 -52
- package/src/fields/DcsFormDate.vue +34 -34
- package/src/fields/DcsFormFieldWrapper.vue +39 -39
- package/src/fields/DcsFormFile.vue +38 -38
- package/src/fields/DcsFormHidden.vue +17 -17
- package/src/fields/DcsFormHtmlBlock.vue +19 -19
- package/src/fields/DcsFormRadio.vue +45 -45
- package/src/fields/DcsFormSection.vue +19 -19
- package/src/fields/DcsFormSelect.vue +62 -62
- package/src/fields/DcsFormText.vue +54 -54
- package/src/fields/DcsFormTextarea.vue +43 -43
- package/src/index.ts +53 -51
- package/src/loaders/yaml.ts +51 -51
- package/src/schema/validate.ts +58 -58
- package/src/shims.d.ts +10 -10
- package/src/style.css +221 -0
- package/src/types.ts +140 -140
package/src/types.ts
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Form type definitions — vendored snapshot of the canonical form types
|
|
3
|
-
* generated from `contracts/spec/domains/portal-site-forms.yaml` (see
|
|
4
|
-
* `contracts/generated/typescript/types.gen.ts`).
|
|
5
|
-
*
|
|
6
|
-
* This is an intentional fork of the generated types so the published
|
|
7
|
-
* package has zero runtime/peer dependency on the (workspace-internal,
|
|
8
|
-
* never published) `@dcs/contracts` package. When the form schema in
|
|
9
|
-
* `contracts/spec/domains/portal-site-forms.yaml` changes, refresh both
|
|
10
|
-
* this file and `src/schema/form-definition.schema.json`.
|
|
11
|
-
*
|
|
12
|
-
* Consumers should import these types from `@duffcloudservices/site-forms`
|
|
13
|
-
* so the package remains the single import surface for managed-form
|
|
14
|
-
* runtime code on customer sites.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export type PortalFormFieldType =
|
|
18
|
-
| 'text'
|
|
19
|
-
| 'email'
|
|
20
|
-
| 'tel'
|
|
21
|
-
| 'textarea'
|
|
22
|
-
| 'select'
|
|
23
|
-
| 'multiselect'
|
|
24
|
-
| 'radio'
|
|
25
|
-
| 'checkbox'
|
|
26
|
-
| 'checkbox-group'
|
|
27
|
-
| 'date'
|
|
28
|
-
| 'file'
|
|
29
|
-
| 'hidden'
|
|
30
|
-
| 'section-heading'
|
|
31
|
-
| 'html-block'
|
|
32
|
-
|
|
33
|
-
export type PortalFormFieldWidth = 'full' | 'half' | 'third'
|
|
34
|
-
|
|
35
|
-
export interface PortalFormFieldOption {
|
|
36
|
-
value: string
|
|
37
|
-
label: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface PortalFormFieldValidation {
|
|
41
|
-
regex?: string
|
|
42
|
-
minLength?: number
|
|
43
|
-
maxLength?: number
|
|
44
|
-
min?: number
|
|
45
|
-
max?: number
|
|
46
|
-
accept?: string[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface PortalFormFieldVisibleIf {
|
|
50
|
-
fieldId: string
|
|
51
|
-
equals: string | number | boolean
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface PortalFormField {
|
|
55
|
-
id: string
|
|
56
|
-
type: PortalFormFieldType
|
|
57
|
-
label: string
|
|
58
|
-
helpText?: string
|
|
59
|
-
placeholder?: string
|
|
60
|
-
defaultValue?: string | number | boolean | string[]
|
|
61
|
-
required?: boolean
|
|
62
|
-
width?: PortalFormFieldWidth
|
|
63
|
-
options?: PortalFormFieldOption[]
|
|
64
|
-
validation?: PortalFormFieldValidation
|
|
65
|
-
visibleIf?: PortalFormFieldVisibleIf
|
|
66
|
-
/**
|
|
67
|
-
* Marks the field as collecting Protected Health Information.
|
|
68
|
-
* When true the value must never appear in notification emails
|
|
69
|
-
* or logs and the owning site must be in the Medical category
|
|
70
|
-
* (see `compliance.instructions.md`).
|
|
71
|
-
*/
|
|
72
|
-
phi?: boolean
|
|
73
|
-
html?: string
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface PortalFormStep {
|
|
77
|
-
id: string
|
|
78
|
-
title: string
|
|
79
|
-
description?: string
|
|
80
|
-
fieldIds: string[]
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface PortalFormSubmissionLeadConfig {
|
|
84
|
-
kind: 'lead'
|
|
85
|
-
category?: string
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface PortalFormSubmissionEmailConfig {
|
|
89
|
-
kind: 'email'
|
|
90
|
-
to: string[]
|
|
91
|
-
subjectTemplate?: string
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface PortalFormSubmissionWebhookConfig {
|
|
95
|
-
kind: 'webhook'
|
|
96
|
-
url: string
|
|
97
|
-
signingSecretRef?: string
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export type PortalFormSubmissionConfig =
|
|
101
|
-
| PortalFormSubmissionLeadConfig
|
|
102
|
-
| PortalFormSubmissionEmailConfig
|
|
103
|
-
| PortalFormSubmissionWebhookConfig
|
|
104
|
-
|
|
105
|
-
export interface PortalFormDefinition {
|
|
106
|
-
formId: string
|
|
107
|
-
title: string
|
|
108
|
-
description?: string
|
|
109
|
-
submitLabel?: string
|
|
110
|
-
successMessage?: string
|
|
111
|
-
submission: PortalFormSubmissionConfig
|
|
112
|
-
steps?: PortalFormStep[]
|
|
113
|
-
fields: PortalFormField[]
|
|
114
|
-
version?: number
|
|
115
|
-
createdAt?: string
|
|
116
|
-
updatedAt?: string
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Map of field id -> current value held by the form. */
|
|
120
|
-
export type FormValues = Record<string, unknown>
|
|
121
|
-
|
|
122
|
-
/** Per-field validation errors keyed by field id. */
|
|
123
|
-
export type FormErrors = Record<string, string | undefined>
|
|
124
|
-
|
|
125
|
-
export interface DcsFormSubmitPayload {
|
|
126
|
-
formId: string
|
|
127
|
-
values: FormValues
|
|
128
|
-
captchaToken?: string
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface DcsFormSubmitSuccess {
|
|
132
|
-
payload: DcsFormSubmitPayload
|
|
133
|
-
response: unknown
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface DcsFormSubmitError {
|
|
137
|
-
payload: DcsFormSubmitPayload
|
|
138
|
-
error: Error
|
|
139
|
-
status?: number
|
|
140
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Form type definitions — vendored snapshot of the canonical form types
|
|
3
|
+
* generated from `contracts/spec/domains/portal-site-forms.yaml` (see
|
|
4
|
+
* `contracts/generated/typescript/types.gen.ts`).
|
|
5
|
+
*
|
|
6
|
+
* This is an intentional fork of the generated types so the published
|
|
7
|
+
* package has zero runtime/peer dependency on the (workspace-internal,
|
|
8
|
+
* never published) `@dcs/contracts` package. When the form schema in
|
|
9
|
+
* `contracts/spec/domains/portal-site-forms.yaml` changes, refresh both
|
|
10
|
+
* this file and `src/schema/form-definition.schema.json`.
|
|
11
|
+
*
|
|
12
|
+
* Consumers should import these types from `@duffcloudservices/site-forms`
|
|
13
|
+
* so the package remains the single import surface for managed-form
|
|
14
|
+
* runtime code on customer sites.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type PortalFormFieldType =
|
|
18
|
+
| 'text'
|
|
19
|
+
| 'email'
|
|
20
|
+
| 'tel'
|
|
21
|
+
| 'textarea'
|
|
22
|
+
| 'select'
|
|
23
|
+
| 'multiselect'
|
|
24
|
+
| 'radio'
|
|
25
|
+
| 'checkbox'
|
|
26
|
+
| 'checkbox-group'
|
|
27
|
+
| 'date'
|
|
28
|
+
| 'file'
|
|
29
|
+
| 'hidden'
|
|
30
|
+
| 'section-heading'
|
|
31
|
+
| 'html-block'
|
|
32
|
+
|
|
33
|
+
export type PortalFormFieldWidth = 'full' | 'half' | 'third'
|
|
34
|
+
|
|
35
|
+
export interface PortalFormFieldOption {
|
|
36
|
+
value: string
|
|
37
|
+
label: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PortalFormFieldValidation {
|
|
41
|
+
regex?: string
|
|
42
|
+
minLength?: number
|
|
43
|
+
maxLength?: number
|
|
44
|
+
min?: number
|
|
45
|
+
max?: number
|
|
46
|
+
accept?: string[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PortalFormFieldVisibleIf {
|
|
50
|
+
fieldId: string
|
|
51
|
+
equals: string | number | boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PortalFormField {
|
|
55
|
+
id: string
|
|
56
|
+
type: PortalFormFieldType
|
|
57
|
+
label: string
|
|
58
|
+
helpText?: string
|
|
59
|
+
placeholder?: string
|
|
60
|
+
defaultValue?: string | number | boolean | string[]
|
|
61
|
+
required?: boolean
|
|
62
|
+
width?: PortalFormFieldWidth
|
|
63
|
+
options?: PortalFormFieldOption[]
|
|
64
|
+
validation?: PortalFormFieldValidation
|
|
65
|
+
visibleIf?: PortalFormFieldVisibleIf
|
|
66
|
+
/**
|
|
67
|
+
* Marks the field as collecting Protected Health Information.
|
|
68
|
+
* When true the value must never appear in notification emails
|
|
69
|
+
* or logs and the owning site must be in the Medical category
|
|
70
|
+
* (see `compliance.instructions.md`).
|
|
71
|
+
*/
|
|
72
|
+
phi?: boolean
|
|
73
|
+
html?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PortalFormStep {
|
|
77
|
+
id: string
|
|
78
|
+
title: string
|
|
79
|
+
description?: string
|
|
80
|
+
fieldIds: string[]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface PortalFormSubmissionLeadConfig {
|
|
84
|
+
kind: 'lead'
|
|
85
|
+
category?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface PortalFormSubmissionEmailConfig {
|
|
89
|
+
kind: 'email'
|
|
90
|
+
to: string[]
|
|
91
|
+
subjectTemplate?: string
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PortalFormSubmissionWebhookConfig {
|
|
95
|
+
kind: 'webhook'
|
|
96
|
+
url: string
|
|
97
|
+
signingSecretRef?: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type PortalFormSubmissionConfig =
|
|
101
|
+
| PortalFormSubmissionLeadConfig
|
|
102
|
+
| PortalFormSubmissionEmailConfig
|
|
103
|
+
| PortalFormSubmissionWebhookConfig
|
|
104
|
+
|
|
105
|
+
export interface PortalFormDefinition {
|
|
106
|
+
formId: string
|
|
107
|
+
title: string
|
|
108
|
+
description?: string
|
|
109
|
+
submitLabel?: string
|
|
110
|
+
successMessage?: string
|
|
111
|
+
submission: PortalFormSubmissionConfig
|
|
112
|
+
steps?: PortalFormStep[]
|
|
113
|
+
fields: PortalFormField[]
|
|
114
|
+
version?: number
|
|
115
|
+
createdAt?: string
|
|
116
|
+
updatedAt?: string
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Map of field id -> current value held by the form. */
|
|
120
|
+
export type FormValues = Record<string, unknown>
|
|
121
|
+
|
|
122
|
+
/** Per-field validation errors keyed by field id. */
|
|
123
|
+
export type FormErrors = Record<string, string | undefined>
|
|
124
|
+
|
|
125
|
+
export interface DcsFormSubmitPayload {
|
|
126
|
+
formId: string
|
|
127
|
+
values: FormValues
|
|
128
|
+
captchaToken?: string
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface DcsFormSubmitSuccess {
|
|
132
|
+
payload: DcsFormSubmitPayload
|
|
133
|
+
response: unknown
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface DcsFormSubmitError {
|
|
137
|
+
payload: DcsFormSubmitPayload
|
|
138
|
+
error: Error
|
|
139
|
+
status?: number
|
|
140
|
+
}
|