@duffcloudservices/site-forms 0.1.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.
Files changed (51) hide show
  1. package/README.md +213 -0
  2. package/dist/DcsForm.vue.d.ts +67 -0
  3. package/dist/composables/useDcsForm.d.ts +36 -0
  4. package/dist/composables/useFormSubmission.d.ts +18 -0
  5. package/dist/composables/useFormValidation.d.ts +19 -0
  6. package/dist/fields/DcsFormCheckbox.vue.d.ts +12 -0
  7. package/dist/fields/DcsFormCheckboxGroup.vue.d.ts +12 -0
  8. package/dist/fields/DcsFormDate.vue.d.ts +14 -0
  9. package/dist/fields/DcsFormFieldWrapper.vue.d.ts +27 -0
  10. package/dist/fields/DcsFormFile.vue.d.ts +12 -0
  11. package/dist/fields/DcsFormHidden.vue.d.ts +7 -0
  12. package/dist/fields/DcsFormHtmlBlock.vue.d.ts +6 -0
  13. package/dist/fields/DcsFormRadio.vue.d.ts +12 -0
  14. package/dist/fields/DcsFormSection.vue.d.ts +21 -0
  15. package/dist/fields/DcsFormSelect.vue.d.ts +35 -0
  16. package/dist/fields/DcsFormText.vue.d.ts +34 -0
  17. package/dist/fields/DcsFormTextarea.vue.d.ts +34 -0
  18. package/dist/index.d.ts +22 -0
  19. package/dist/index.js +918 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/loaders/yaml.d.ts +12 -0
  22. package/dist/schema/validate.d.ts +9 -0
  23. package/dist/types.d.ts +106 -0
  24. package/package.json +73 -0
  25. package/src/DcsForm.vue +299 -0
  26. package/src/__tests__/fields.test.ts +82 -0
  27. package/src/__tests__/multi-step.test.ts +46 -0
  28. package/src/__tests__/schema.test.ts +42 -0
  29. package/src/__tests__/submission.test.ts +77 -0
  30. package/src/__tests__/visible-if.test.ts +111 -0
  31. package/src/composables/useDcsForm.ts +201 -0
  32. package/src/composables/useFormSubmission.ts +113 -0
  33. package/src/composables/useFormValidation.ts +127 -0
  34. package/src/fields/DcsFormCheckbox.vue +35 -0
  35. package/src/fields/DcsFormCheckboxGroup.vue +52 -0
  36. package/src/fields/DcsFormDate.vue +34 -0
  37. package/src/fields/DcsFormFieldWrapper.vue +39 -0
  38. package/src/fields/DcsFormFile.vue +38 -0
  39. package/src/fields/DcsFormHidden.vue +17 -0
  40. package/src/fields/DcsFormHtmlBlock.vue +19 -0
  41. package/src/fields/DcsFormRadio.vue +45 -0
  42. package/src/fields/DcsFormSection.vue +19 -0
  43. package/src/fields/DcsFormSelect.vue +62 -0
  44. package/src/fields/DcsFormText.vue +54 -0
  45. package/src/fields/DcsFormTextarea.vue +43 -0
  46. package/src/index.ts +51 -0
  47. package/src/loaders/yaml.ts +51 -0
  48. package/src/schema/form-definition.schema.json +633 -0
  49. package/src/schema/validate.ts +58 -0
  50. package/src/shims.d.ts +10 -0
  51. package/src/types.ts +140 -0
package/src/types.ts ADDED
@@ -0,0 +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
+ }