@sanity/form-toolkit 2.2.3 → 3.0.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/LICENSE +2 -1
- package/dist/_chunks-es/{create-handler.mjs → create-handler.js} +45 -17
- package/dist/_chunks-es/create-handler.js.map +1 -0
- package/dist/form-renderer/index.d.ts +53 -64
- package/dist/form-renderer/index.d.ts.map +1 -0
- package/dist/form-renderer/index.js +123 -108
- package/dist/form-renderer/index.js.map +1 -1
- package/dist/form-schema/index.d.ts +7 -11
- package/dist/form-schema/index.d.ts.map +1 -0
- package/dist/form-schema/index.js +181 -181
- package/dist/form-schema/index.js.map +1 -1
- package/dist/formium/index.d.ts +4 -7
- package/dist/formium/index.d.ts.map +1 -0
- package/dist/formium/index.js +35 -25
- package/dist/formium/index.js.map +1 -1
- package/dist/hubspot/index.d.ts +52 -48
- package/dist/hubspot/index.d.ts.map +1 -0
- package/dist/hubspot/index.js +52 -26
- package/dist/hubspot/index.js.map +1 -1
- package/dist/mailchimp/index.d.ts +56 -42
- package/dist/mailchimp/index.d.ts.map +1 -0
- package/dist/mailchimp/index.js +55 -37
- package/dist/mailchimp/index.js.map +1 -1
- package/package.json +36 -107
- package/dist/_chunks-cjs/create-handler.js +0 -68
- package/dist/_chunks-cjs/create-handler.js.map +0 -1
- package/dist/_chunks-es/create-handler.mjs.map +0 -1
- package/dist/form-renderer/index.d.mts +0 -66
- package/dist/form-renderer/index.mjs +0 -128
- package/dist/form-renderer/index.mjs.map +0 -1
- package/dist/form-schema/index.d.mts +0 -28
- package/dist/form-schema/index.mjs +0 -230
- package/dist/form-schema/index.mjs.map +0 -1
- package/dist/formium/index.d.mts +0 -20
- package/dist/formium/index.mjs +0 -30
- package/dist/formium/index.mjs.map +0 -1
- package/dist/hubspot/index.d.mts +0 -49
- package/dist/hubspot/index.mjs +0 -48
- package/dist/hubspot/index.mjs.map +0 -1
- package/dist/mailchimp/index.d.mts +0 -45
- package/dist/mailchimp/index.mjs +0 -49
- package/dist/mailchimp/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/form-renderer/components/default-field.tsx +0 -123
- package/src/form-renderer/components/form-renderer.tsx +0 -62
- package/src/form-renderer/components/types.ts +0 -51
- package/src/form-renderer/index.ts +0 -4
- package/src/form-schema/components/validation-type.tsx +0 -14
- package/src/form-schema/index.ts +0 -35
- package/src/form-schema/schema-types/form-field.ts +0 -224
- package/src/form-schema/schema-types/form.ts +0 -52
- package/src/form-schema/schema-types/index.ts +0 -9
- package/src/formium/index.ts +0 -52
- package/src/hubspot/components/option.tsx +0 -17
- package/src/hubspot/create-handler.ts +0 -6
- package/src/hubspot/fetch-hubspot-data.ts +0 -33
- package/src/hubspot/index.ts +0 -52
- package/src/index.ts +0 -19
- package/src/mailchimp/components/option.tsx +0 -30
- package/src/mailchimp/create-handler.ts +0 -39
- package/src/mailchimp/index.ts +0 -43
- package/src/shared/create-handler.ts +0 -109
- package/v2-incompatible.js +0 -11
|
@@ -1,51 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { defineType, defineField, useFormValue, definePlugin } from "sanity";
|
|
2
|
+
import { FaWpforms } from "react-icons/fa";
|
|
3
|
+
import { LuTextCursorInput } from "react-icons/lu";
|
|
4
|
+
import { c } from "react/compiler-runtime";
|
|
5
|
+
const formType = (fields) => defineType({
|
|
5
6
|
name: "form",
|
|
6
7
|
title: "Form",
|
|
7
8
|
type: "document",
|
|
8
|
-
icon:
|
|
9
|
-
fields: [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
icon: FaWpforms,
|
|
10
|
+
fields: [defineField({
|
|
11
|
+
name: "title",
|
|
12
|
+
title: "Form Title",
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Internal title for the form",
|
|
15
|
+
validation: (Rule) => Rule.required()
|
|
16
|
+
}), defineField({
|
|
17
|
+
name: "id",
|
|
18
|
+
title: "Form ID",
|
|
19
|
+
type: "slug",
|
|
20
|
+
options: {
|
|
21
|
+
source: "title"
|
|
22
|
+
}
|
|
23
|
+
// validation: (Rule) => Rule.required(),
|
|
24
|
+
}), defineField({
|
|
25
|
+
name: "fields",
|
|
26
|
+
title: "Form Fields",
|
|
27
|
+
type: "array",
|
|
28
|
+
of: [{
|
|
29
|
+
type: "formField"
|
|
30
|
+
}, ...fields]
|
|
31
|
+
}), defineField({
|
|
32
|
+
name: "submitButton",
|
|
33
|
+
title: "Submit Button",
|
|
34
|
+
type: "object",
|
|
35
|
+
fields: [defineField({
|
|
36
|
+
name: "text",
|
|
37
|
+
title: "Button Text",
|
|
13
38
|
type: "string",
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
initialValue: "Submit"
|
|
40
|
+
})]
|
|
41
|
+
})]
|
|
42
|
+
}), ValidationType = (props) => {
|
|
43
|
+
const $ = c(7);
|
|
44
|
+
let t0;
|
|
45
|
+
$[0] !== props.path ? (t0 = props.path.slice(0, 2), $[0] = props.path, $[1] = t0) : t0 = $[1];
|
|
46
|
+
const {
|
|
47
|
+
type
|
|
48
|
+
} = useFormValue(t0);
|
|
49
|
+
if (!type || !props.schemaType?.options) {
|
|
50
|
+
let t12;
|
|
51
|
+
return $[2] !== props ? (t12 = props.renderDefault(props), $[2] = props, $[3] = t12) : t12 = $[3], t12;
|
|
52
|
+
}
|
|
53
|
+
const t1 = validationTypesByFieldType[type];
|
|
54
|
+
let t2;
|
|
55
|
+
return $[4] !== props || $[5] !== t1 ? (t2 = props.renderDefault({
|
|
56
|
+
...props,
|
|
57
|
+
schemaType: {
|
|
58
|
+
...props.schemaType,
|
|
21
59
|
options: {
|
|
22
|
-
|
|
60
|
+
...props.schemaType.options,
|
|
61
|
+
list: t1
|
|
23
62
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
sanity.defineField({
|
|
27
|
-
name: "fields",
|
|
28
|
-
title: "Form Fields",
|
|
29
|
-
type: "array",
|
|
30
|
-
of: [{ type: "formField" }, ...fields]
|
|
31
|
-
}),
|
|
32
|
-
sanity.defineField({
|
|
33
|
-
name: "submitButton",
|
|
34
|
-
title: "Submit Button",
|
|
35
|
-
type: "object",
|
|
36
|
-
fields: [
|
|
37
|
-
sanity.defineField({
|
|
38
|
-
name: "text",
|
|
39
|
-
title: "Button Text",
|
|
40
|
-
type: "string",
|
|
41
|
-
initialValue: "Submit"
|
|
42
|
-
})
|
|
43
|
-
]
|
|
44
|
-
})
|
|
45
|
-
]
|
|
46
|
-
}), ValidationType = (props) => {
|
|
47
|
-
const { type } = sanity.useFormValue([...props.path.slice(0, 2)]);
|
|
48
|
-
return type && props.schemaType?.options && (props.schemaType.options.list = validationTypesByFieldType[type]), props.renderDefault(props);
|
|
63
|
+
}
|
|
64
|
+
}), $[4] = props, $[5] = t1, $[6] = t2) : t2 = $[6], t2;
|
|
49
65
|
}, validationTypesByFieldType = {
|
|
50
66
|
checkbox: ["minSelectedCount", "maxSelectedCount"],
|
|
51
67
|
color: [],
|
|
@@ -64,165 +80,149 @@ const formType = (fields) => sanity.defineType({
|
|
|
64
80
|
textarea: ["minLength", "maxLength"],
|
|
65
81
|
time: [],
|
|
66
82
|
url: ["pattern"]
|
|
67
|
-
},
|
|
83
|
+
}, fieldTypeTitle = (fieldType) => {
|
|
84
|
+
switch (fieldType) {
|
|
85
|
+
case "datetime-local":
|
|
86
|
+
return "Date & Time";
|
|
87
|
+
case "textarea":
|
|
88
|
+
return "Text Area";
|
|
89
|
+
case "tel":
|
|
90
|
+
return "Phone Number";
|
|
91
|
+
default:
|
|
92
|
+
return fieldType.charAt(0).toUpperCase() + fieldType.slice(1);
|
|
93
|
+
}
|
|
94
|
+
}, formFieldType = defineType({
|
|
68
95
|
name: "formField",
|
|
69
96
|
title: "Form Field",
|
|
70
97
|
type: "object",
|
|
71
|
-
icon:
|
|
72
|
-
fields: [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
sanity.defineField({
|
|
122
|
-
name: "validation",
|
|
123
|
-
title: "Validation Rules",
|
|
124
|
-
type: "array",
|
|
125
|
-
hidden: ({ parent }) => {
|
|
126
|
-
if (!parent?.type) return !0;
|
|
127
|
-
const validationTypes = validationTypesByFieldType[parent.type];
|
|
128
|
-
return !validationTypes || validationTypes.length === 0;
|
|
129
|
-
},
|
|
130
|
-
of: [
|
|
131
|
-
{
|
|
132
|
-
type: "object",
|
|
133
|
-
fields: [
|
|
134
|
-
sanity.defineField({
|
|
135
|
-
name: "type",
|
|
136
|
-
title: "Validation Type",
|
|
137
|
-
type: "string",
|
|
138
|
-
options: {
|
|
139
|
-
// TODO: I think this needs to be a custom input component?
|
|
140
|
-
// list: ({parent}) => (parent?.type ? validationTypesByFieldType[parent.type] : []),
|
|
141
|
-
list: []
|
|
142
|
-
},
|
|
143
|
-
components: {
|
|
144
|
-
input: ValidationType
|
|
145
|
-
}
|
|
146
|
-
}),
|
|
147
|
-
sanity.defineField({
|
|
148
|
-
name: "value",
|
|
149
|
-
title: "Value",
|
|
150
|
-
type: "string"
|
|
151
|
-
}),
|
|
152
|
-
sanity.defineField({
|
|
153
|
-
name: "message",
|
|
154
|
-
title: "Error Message",
|
|
155
|
-
type: "string"
|
|
156
|
-
})
|
|
157
|
-
],
|
|
158
|
-
preview: {
|
|
159
|
-
select: {
|
|
160
|
-
title: "type",
|
|
161
|
-
subtitle: "value"
|
|
162
|
-
}
|
|
163
|
-
}
|
|
98
|
+
icon: LuTextCursorInput,
|
|
99
|
+
fields: [defineField({
|
|
100
|
+
name: "type",
|
|
101
|
+
title: "Field Type",
|
|
102
|
+
type: "string",
|
|
103
|
+
options: {
|
|
104
|
+
list: Object.keys(validationTypesByFieldType).map((type) => ({
|
|
105
|
+
title: fieldTypeTitle(type),
|
|
106
|
+
value: type
|
|
107
|
+
}))
|
|
108
|
+
}
|
|
109
|
+
}), defineField({
|
|
110
|
+
name: "label",
|
|
111
|
+
title: "Field Label",
|
|
112
|
+
type: "string"
|
|
113
|
+
}), defineField({
|
|
114
|
+
name: "name",
|
|
115
|
+
title: "Field Name",
|
|
116
|
+
type: "string",
|
|
117
|
+
description: "Must start with a letter and contain only letters, numbers, underscores, or hyphens. Must be unique within the form.",
|
|
118
|
+
validation: (Rule) => Rule.required().custom((name, context) => name ? /^[a-zA-Z][a-zA-Z0-9_-]*$/.test(name) ? (context.document?.fields?.map((field) => field.name) || []).filter((n) => n === name).length > 1 ? "Field name must be unique across all form fields" : ["action", "method", "target", "enctype", "accept-charset", "autocomplete", "novalidate", "rel", "submit", "reset"].includes(name.toLowerCase()) ? "This name is reserved for HTML form attributes. Please choose a different name." : !0 : "Field name must start with a letter and contain only letters, numbers, underscores, or hyphens" : "Required")
|
|
119
|
+
}), defineField({
|
|
120
|
+
name: "required",
|
|
121
|
+
title: "Required",
|
|
122
|
+
type: "boolean",
|
|
123
|
+
initialValue: !1
|
|
124
|
+
}), defineField({
|
|
125
|
+
name: "validation",
|
|
126
|
+
title: "Validation Rules",
|
|
127
|
+
type: "array",
|
|
128
|
+
hidden: ({
|
|
129
|
+
parent
|
|
130
|
+
}) => {
|
|
131
|
+
if (!parent?.type) return !0;
|
|
132
|
+
const validationTypes = validationTypesByFieldType[parent.type];
|
|
133
|
+
return !validationTypes || validationTypes.length === 0;
|
|
134
|
+
},
|
|
135
|
+
of: [{
|
|
136
|
+
type: "object",
|
|
137
|
+
fields: [defineField({
|
|
138
|
+
name: "type",
|
|
139
|
+
title: "Validation Type",
|
|
140
|
+
type: "string",
|
|
141
|
+
options: {
|
|
142
|
+
// TODO: I think this needs to be a custom input component?
|
|
143
|
+
// list: ({parent}) => (parent?.type ? validationTypesByFieldType[parent.type] : []),
|
|
144
|
+
list: []
|
|
145
|
+
},
|
|
146
|
+
components: {
|
|
147
|
+
input: ValidationType
|
|
164
148
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
title: "Label",
|
|
179
|
-
type: "string"
|
|
180
|
-
}),
|
|
181
|
-
sanity.defineField({
|
|
182
|
-
name: "value",
|
|
183
|
-
title: "Value",
|
|
184
|
-
type: "string"
|
|
185
|
-
})
|
|
186
|
-
]
|
|
149
|
+
}), defineField({
|
|
150
|
+
name: "value",
|
|
151
|
+
title: "Value",
|
|
152
|
+
type: "string"
|
|
153
|
+
}), defineField({
|
|
154
|
+
name: "message",
|
|
155
|
+
title: "Error Message",
|
|
156
|
+
type: "string"
|
|
157
|
+
})],
|
|
158
|
+
preview: {
|
|
159
|
+
select: {
|
|
160
|
+
title: "type",
|
|
161
|
+
subtitle: "value"
|
|
187
162
|
}
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
163
|
+
}
|
|
164
|
+
}]
|
|
165
|
+
}), defineField({
|
|
166
|
+
name: "choices",
|
|
167
|
+
title: "Choices",
|
|
168
|
+
type: "array",
|
|
169
|
+
hidden: ({
|
|
170
|
+
parent
|
|
171
|
+
}) => !["select", "radio", "checkbox"].includes(parent?.type),
|
|
172
|
+
of: [{
|
|
193
173
|
type: "object",
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
174
|
+
fields: [defineField({
|
|
175
|
+
name: "label",
|
|
176
|
+
title: "Label",
|
|
177
|
+
type: "string"
|
|
178
|
+
}), defineField({
|
|
179
|
+
name: "value",
|
|
180
|
+
title: "Value",
|
|
181
|
+
type: "string"
|
|
182
|
+
})]
|
|
183
|
+
}]
|
|
184
|
+
}), defineField({
|
|
185
|
+
name: "options",
|
|
186
|
+
title: "Field Options",
|
|
187
|
+
type: "object",
|
|
188
|
+
hidden: ({
|
|
189
|
+
parent
|
|
190
|
+
}) => ["select", "radio", "checkbox", "file"].includes(parent?.type),
|
|
191
|
+
fields: [defineField({
|
|
192
|
+
name: "placeholder",
|
|
193
|
+
title: "Placeholder",
|
|
194
|
+
type: "string"
|
|
195
|
+
}), defineField({
|
|
196
|
+
name: "defaultValue",
|
|
197
|
+
title: "Default Value",
|
|
198
|
+
type: "string"
|
|
199
|
+
})]
|
|
200
|
+
})],
|
|
209
201
|
preview: {
|
|
210
202
|
select: {
|
|
211
203
|
label: "label",
|
|
212
204
|
name: "name",
|
|
213
205
|
type: "type"
|
|
214
206
|
},
|
|
215
|
-
prepare({
|
|
207
|
+
prepare({
|
|
208
|
+
label,
|
|
209
|
+
name,
|
|
210
|
+
type
|
|
211
|
+
}) {
|
|
216
212
|
return {
|
|
217
213
|
title: label || name,
|
|
218
214
|
subtitle: type
|
|
219
215
|
};
|
|
220
216
|
}
|
|
221
217
|
}
|
|
222
|
-
}), schema = (fields) => ({
|
|
218
|
+
}), schema = (fields) => ({
|
|
219
|
+
types: [formType(fields), formFieldType]
|
|
220
|
+
}), formSchema = definePlugin((options) => ({
|
|
223
221
|
name: "form-toolkit_form-schema",
|
|
224
222
|
schema: schema(options?.fields ?? [])
|
|
225
223
|
// plugins: [structureTool({defaultDocumentNode})],
|
|
226
224
|
}));
|
|
227
|
-
|
|
225
|
+
export {
|
|
226
|
+
formSchema
|
|
227
|
+
};
|
|
228
228
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/form-schema/schema-types/form.ts","../../src/form-schema/components/validation-type.tsx","../../src/form-schema/schema-types/form-field.ts","../../src/form-schema/schema-types/index.ts","../../src/form-schema/index.ts"],"sourcesContent":["import {FaWpforms} from 'react-icons/fa'\nimport {defineField, defineType, type SchemaTypeDefinition} from 'sanity'\n\nimport type {FieldsOption} from '..'\n\nexport const formType = (fields: FieldsOption): SchemaTypeDefinition => {\n // const fieldsOf =\n // fields && fields.length ? [{type: 'formField'}, ...fields] : [{type: 'formField'}]\n return defineType({\n name: 'form',\n title: 'Form',\n type: 'document',\n icon: FaWpforms,\n fields: [\n defineField({\n name: 'title',\n title: 'Form Title',\n type: 'string',\n description: 'Internal title for the form',\n validation: (Rule) => Rule.required(),\n }),\n defineField({\n name: 'id',\n title: 'Form ID',\n type: 'slug',\n options: {\n source: 'title',\n },\n // validation: (Rule) => Rule.required(),\n }),\n defineField({\n name: 'fields',\n title: 'Form Fields',\n type: 'array',\n of: [{type: 'formField'}, ...fields],\n }),\n defineField({\n name: 'submitButton',\n title: 'Submit Button',\n type: 'object',\n fields: [\n defineField({\n name: 'text',\n title: 'Button Text',\n type: 'string',\n initialValue: 'Submit',\n }),\n ],\n }),\n ],\n })\n}\n","import type {StringInputProps} from 'sanity'\nimport {useFormValue} from 'sanity'\n\nimport type {FormField} from '../../form-renderer/components/types'\nimport {validationTypesByFieldType} from '../schema-types/form-field'\n\nexport const ValidationType = (props: StringInputProps) => {\n const {type} = useFormValue([...props.path.slice(0, 2)]) as FormField\n if (!type) return props.renderDefault(props)\n if (props.schemaType?.options) {\n props.schemaType.options.list = validationTypesByFieldType[type]\n }\n return props.renderDefault(props)\n}\n","import {LuTextCursorInput} from 'react-icons/lu'\nimport {defineField, defineType} from 'sanity'\n\nimport {ValidationType} from '../components/validation-type'\ninterface ValidationContextDocument {\n fields?: Array<{\n name: string\n type?: string\n }>\n}\n\n// Validation options by field type\nexport const validationTypesByFieldType: Record<string, string[]> = {\n checkbox: ['minSelectedCount', 'maxSelectedCount'],\n color: [],\n date: ['minDate', 'maxDate'],\n 'datetime-local': ['minDate', 'maxDate'],\n email: ['pattern'],\n file: ['maxSize', 'fileType'],\n hidden: [],\n number: ['min', 'max'],\n // password: ['minLength', 'pattern'],\n radio: [],\n range: ['min', 'max', 'step'],\n select: [],\n tel: ['pattern'],\n text: ['minLength', 'maxLength', 'pattern'],\n textarea: ['minLength', 'maxLength'],\n time: [],\n url: ['pattern'],\n}\nexport const formFieldType = defineType({\n name: 'formField',\n title: 'Form Field',\n type: 'object',\n icon: LuTextCursorInput,\n fields: [\n defineField({\n name: 'type',\n title: 'Field Type',\n type: 'string',\n options: {\n list: Object.keys(validationTypesByFieldType).map((type) => {\n const title = (fieldType: string) => {\n switch (fieldType) {\n case 'datetime-local':\n return 'Date & Time'\n case 'textarea':\n return 'Text Area'\n case 'tel':\n return 'Phone Number'\n default:\n return fieldType.charAt(0).toUpperCase() + fieldType.slice(1)\n }\n }\n return {title: title(type), value: type}\n }),\n },\n }),\n defineField({\n name: 'label',\n title: 'Field Label',\n type: 'string',\n }),\n defineField({\n name: 'name',\n title: 'Field Name',\n type: 'string',\n description:\n 'Must start with a letter and contain only letters, numbers, underscores, or hyphens. Must be unique within the form.',\n validation: (Rule) =>\n Rule.required().custom((name, context) => {\n if (!name) {\n return 'Required'\n }\n // Check format (HTML ID/name rules)\n if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(name)) {\n return 'Field name must start with a letter and contain only letters, numbers, underscores, or hyphens'\n }\n\n // Check uniqueness across all fields\n const doc = context.document as ValidationContextDocument\n const allFieldNames = doc?.fields?.map((field) => field.name) || []\n\n // Count occurrences of this name\n const nameCount = allFieldNames.filter((n) => n === name).length\n\n // If we find more than one occurrence (including current field), it's not unique\n if (nameCount > 1) {\n return 'Field name must be unique across all form fields'\n }\n\n // Check for reserved HTML form attributes\n const reservedNames = [\n 'action',\n 'method',\n 'target',\n 'enctype',\n 'accept-charset',\n 'autocomplete',\n 'novalidate',\n 'rel',\n 'submit',\n 'reset',\n ]\n if (reservedNames.includes(name.toLowerCase())) {\n return 'This name is reserved for HTML form attributes. Please choose a different name.'\n }\n\n return true\n }),\n }),\n defineField({\n name: 'required',\n title: 'Required',\n type: 'boolean',\n initialValue: false,\n }),\n defineField({\n name: 'validation',\n title: 'Validation Rules',\n type: 'array',\n hidden: ({parent}) => {\n if (!parent?.type) return true\n const validationTypes = validationTypesByFieldType[parent.type]\n return !validationTypes || validationTypes.length === 0\n },\n of: [\n {\n type: 'object',\n fields: [\n defineField({\n name: 'type',\n title: 'Validation Type',\n type: 'string',\n options: {\n // TODO: I think this needs to be a custom input component?\n // list: ({parent}) => (parent?.type ? validationTypesByFieldType[parent.type] : []),\n list: [],\n },\n components: {\n input: ValidationType,\n },\n }),\n defineField({\n name: 'value',\n title: 'Value',\n type: 'string',\n }),\n defineField({\n name: 'message',\n title: 'Error Message',\n type: 'string',\n }),\n ],\n preview: {\n select: {\n title: 'type',\n subtitle: 'value',\n },\n },\n },\n ],\n }),\n defineField({\n name: 'choices',\n title: 'Choices',\n type: 'array',\n hidden: ({parent}) => {\n return !['select', 'radio', 'checkbox'].includes(parent?.type)\n },\n of: [\n {\n type: 'object',\n fields: [\n defineField({\n name: 'label',\n title: 'Label',\n type: 'string',\n }),\n defineField({\n name: 'value',\n title: 'Value',\n type: 'string',\n }),\n ],\n },\n ],\n }),\n defineField({\n name: 'options',\n title: 'Field Options',\n type: 'object',\n hidden: ({parent}) => {\n return ['select', 'radio', 'checkbox', 'file'].includes(parent?.type)\n },\n fields: [\n defineField({\n name: 'placeholder',\n title: 'Placeholder',\n type: 'string',\n }),\n defineField({\n name: 'defaultValue',\n title: 'Default Value',\n type: 'string',\n }),\n ],\n }),\n ],\n preview: {\n select: {\n label: 'label',\n name: 'name',\n type: 'type',\n },\n prepare({label, name, type}) {\n return {\n title: label || name,\n subtitle: type,\n }\n },\n },\n})\n","import type {SchemaTypeDefinition} from 'sanity'\n\nimport type {FieldsOption} from '..'\nimport {formType} from './form'\nimport {formFieldType} from './form-field'\n\nexport const schema = (fields: FieldsOption): {types: SchemaTypeDefinition[]} => {\n return {types: [formType(fields), formFieldType]}\n}\n","import {definePlugin, type FieldDefinition} from 'sanity'\n\n// import {structureTool} from 'sanity/structure'\n// import {FormRenderer} from './components/form-renderer'\nimport {schema} from './schema-types'\n// import {defaultDocumentNode} from './structure'\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {formSchema} from '@sanity/form-toolkit'\n *\n * export default defineConfig({\n * // ...\n * plugins: [formSchema()],\n * })\n * ```\n */\nexport type FieldsOption = Array<FieldDefinition>\ninterface FormSchemaPluginOptions {\n /**\n * Array of field definitions to be used in the form schema.\n */\n fields?: FieldsOption\n}\n\nexport const formSchema = definePlugin((options: FormSchemaPluginOptions | undefined) => {\n return {\n name: 'form-toolkit_form-schema',\n schema: schema(options?.fields ?? []),\n // plugins: [structureTool({defaultDocumentNode})],\n }\n})\n"],"names":["defineType","FaWpforms","defineField","useFormValue","LuTextCursorInput","definePlugin"],"mappings":";;;AAKa,MAAA,WAAW,CAAC,WAGhBA,kBAAW;AAAA,EAChB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAMC,GAAA;AAAA,EACN,QAAQ;AAAA,IACNC,mBAAY;AAAA,MACV,MAAM;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,MACN,aAAa;AA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;AAAA,cACV,MAAM;AAAA,cACN,OAAO;AAAA,cACP,MAAM;AAAA,YAAA,CACP;AAAA,YACDA,mBAAY;AAAA,cACV,MAAM;AAAA,cACN,OAAO;AAAA,cACP,MAAM;AAAA,YACP,CAAA;AAAA,UAAA;AAAA,QACH;AAAA,MACF;AAAA,IACF,CACD;AAAA,IACDA,mBAAY;AAAA,MACV,MAAM;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ,CAAC,EAAC,OACD,MAAA,CAAC,UAAU,SAAS,YAAY,MAAM,EAAE,SAAS,QAAQ,IAAI;AAAA,MAEtE,QAAQ;AAAA,QACNA,mBAAY;AAAA,UACV,MAAM;AAAA,UACN,OAAO;AAAA,UACP,MAAM;AAAA,QAAA,CACP;AAAA,QACDA,mBAAY;AAAA,UACV,MAAM;AAAA,UACN,OAAO;AAAA,UACP,MAAM;AAAA,QACP,CAAA;AAAA,MAAA;AAAA,IAEJ,CAAA;AAAA,EACH;AAAA,EACA,SAAS;AAAA,IACP,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA,QAAQ,EAAC,OAAO,MAAM,QAAO;AACpB,aAAA;AAAA,QACL,OAAO,SAAS;AAAA,QAChB,UAAU;AAAA,MACZ;AAAA,IAAA;AAAA,EACF;AAEJ,CAAC,GCzNY,SAAS,CAAC,YACd,EAAC,OAAO,CAAC,SAAS,MAAM,GAAG,aAAa,MCqBpC,aAAaG,OAAAA,aAAa,CAAC,aAC/B;AAAA,EACL,MAAM;AAAA,EACN,QAAQ,OAAO,SAAS,UAAU,CAAE,CAAA;AAAA;AAEtC,EACD;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/form-schema/schema-types/form.ts","../../src/form-schema/components/validation-type.tsx","../../src/form-schema/schema-types/form-field.ts","../../src/form-schema/schema-types/index.ts","../../src/form-schema/index.ts"],"sourcesContent":["import {FaWpforms} from 'react-icons/fa'\nimport {defineField, defineType, type SchemaTypeDefinition} from 'sanity'\n\nimport type {FieldsOption} from '..'\n\nexport const formType = (fields: FieldsOption): SchemaTypeDefinition => {\n // const fieldsOf =\n // fields && fields.length ? [{type: 'formField'}, ...fields] : [{type: 'formField'}]\n return defineType({\n name: 'form',\n title: 'Form',\n type: 'document',\n icon: FaWpforms,\n fields: [\n defineField({\n name: 'title',\n title: 'Form Title',\n type: 'string',\n description: 'Internal title for the form',\n validation: (Rule) => Rule.required(),\n }),\n defineField({\n name: 'id',\n title: 'Form ID',\n type: 'slug',\n options: {\n source: 'title',\n },\n // validation: (Rule) => Rule.required(),\n }),\n defineField({\n name: 'fields',\n title: 'Form Fields',\n type: 'array',\n of: [{type: 'formField'}, ...fields],\n }),\n defineField({\n name: 'submitButton',\n title: 'Submit Button',\n type: 'object',\n fields: [\n defineField({\n name: 'text',\n title: 'Button Text',\n type: 'string',\n initialValue: 'Submit',\n }),\n ],\n }),\n ],\n })\n}\n","import type {StringInputProps} from 'sanity'\nimport {useFormValue} from 'sanity'\n\nimport type {FormField} from '../../form-renderer/components/types'\nimport {validationTypesByFieldType} from '../schema-types/form-field'\n\nexport const ValidationType = (props: StringInputProps) => {\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- parent value shape is defined by the formField schema type\n const {type} = useFormValue(props.path.slice(0, 2)) as FormField\n if (!type || !props.schemaType?.options) return props.renderDefault(props)\n return props.renderDefault({\n ...props,\n schemaType: {\n ...props.schemaType,\n options: {...props.schemaType.options, list: validationTypesByFieldType[type]},\n },\n })\n}\n","import {LuTextCursorInput} from 'react-icons/lu'\nimport {defineField, defineType} from 'sanity'\n\nimport {ValidationType} from '../components/validation-type'\ninterface ValidationContextDocument {\n fields?: Array<{\n name: string\n type?: string\n }>\n}\n\n// Validation options by field type\nexport const validationTypesByFieldType: Record<string, string[]> = {\n 'checkbox': ['minSelectedCount', 'maxSelectedCount'],\n 'color': [],\n 'date': ['minDate', 'maxDate'],\n 'datetime-local': ['minDate', 'maxDate'],\n 'email': ['pattern'],\n 'file': ['maxSize', 'fileType'],\n 'hidden': [],\n 'number': ['min', 'max'],\n // password: ['minLength', 'pattern'],\n 'radio': [],\n 'range': ['min', 'max', 'step'],\n 'select': [],\n 'tel': ['pattern'],\n 'text': ['minLength', 'maxLength', 'pattern'],\n 'textarea': ['minLength', 'maxLength'],\n 'time': [],\n 'url': ['pattern'],\n}\nconst fieldTypeTitle = (fieldType: string): string => {\n switch (fieldType) {\n case 'datetime-local':\n return 'Date & Time'\n case 'textarea':\n return 'Text Area'\n case 'tel':\n return 'Phone Number'\n default:\n return fieldType.charAt(0).toUpperCase() + fieldType.slice(1)\n }\n}\n\nexport const formFieldType = defineType({\n name: 'formField',\n title: 'Form Field',\n type: 'object',\n icon: LuTextCursorInput,\n fields: [\n defineField({\n name: 'type',\n title: 'Field Type',\n type: 'string',\n options: {\n list: Object.keys(validationTypesByFieldType).map((type) => {\n return {title: fieldTypeTitle(type), value: type}\n }),\n },\n }),\n defineField({\n name: 'label',\n title: 'Field Label',\n type: 'string',\n }),\n defineField({\n name: 'name',\n title: 'Field Name',\n type: 'string',\n description:\n 'Must start with a letter and contain only letters, numbers, underscores, or hyphens. Must be unique within the form.',\n validation: (Rule) =>\n Rule.required().custom((name, context) => {\n if (!name) {\n return 'Required'\n }\n // Check format (HTML ID/name rules)\n if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(name)) {\n return 'Field name must start with a letter and contain only letters, numbers, underscores, or hyphens'\n }\n\n // Check uniqueness across all fields\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- document shape is defined by the form schema type\n const doc = context.document as ValidationContextDocument\n const allFieldNames = doc?.fields?.map((field) => field.name) || []\n\n // Count occurrences of this name\n const nameCount = allFieldNames.filter((n) => n === name).length\n\n // If we find more than one occurrence (including current field), it's not unique\n if (nameCount > 1) {\n return 'Field name must be unique across all form fields'\n }\n\n // Check for reserved HTML form attributes\n const reservedNames = [\n 'action',\n 'method',\n 'target',\n 'enctype',\n 'accept-charset',\n 'autocomplete',\n 'novalidate',\n 'rel',\n 'submit',\n 'reset',\n ]\n if (reservedNames.includes(name.toLowerCase())) {\n return 'This name is reserved for HTML form attributes. Please choose a different name.'\n }\n\n return true\n }),\n }),\n defineField({\n name: 'required',\n title: 'Required',\n type: 'boolean',\n initialValue: false,\n }),\n defineField({\n name: 'validation',\n title: 'Validation Rules',\n type: 'array',\n hidden: ({parent}) => {\n if (!parent?.type) return true\n const validationTypes = validationTypesByFieldType[parent.type]\n return !validationTypes || validationTypes.length === 0\n },\n of: [\n {\n type: 'object',\n fields: [\n defineField({\n name: 'type',\n title: 'Validation Type',\n type: 'string',\n options: {\n // TODO: I think this needs to be a custom input component?\n // list: ({parent}) => (parent?.type ? validationTypesByFieldType[parent.type] : []),\n list: [],\n },\n components: {\n input: ValidationType,\n },\n }),\n defineField({\n name: 'value',\n title: 'Value',\n type: 'string',\n }),\n defineField({\n name: 'message',\n title: 'Error Message',\n type: 'string',\n }),\n ],\n preview: {\n select: {\n title: 'type',\n subtitle: 'value',\n },\n },\n },\n ],\n }),\n defineField({\n name: 'choices',\n title: 'Choices',\n type: 'array',\n hidden: ({parent}) => {\n return !['select', 'radio', 'checkbox'].includes(parent?.type)\n },\n of: [\n {\n type: 'object',\n fields: [\n defineField({\n name: 'label',\n title: 'Label',\n type: 'string',\n }),\n defineField({\n name: 'value',\n title: 'Value',\n type: 'string',\n }),\n ],\n },\n ],\n }),\n defineField({\n name: 'options',\n title: 'Field Options',\n type: 'object',\n hidden: ({parent}) => {\n return ['select', 'radio', 'checkbox', 'file'].includes(parent?.type)\n },\n fields: [\n defineField({\n name: 'placeholder',\n title: 'Placeholder',\n type: 'string',\n }),\n defineField({\n name: 'defaultValue',\n title: 'Default Value',\n type: 'string',\n }),\n ],\n }),\n ],\n preview: {\n select: {\n label: 'label',\n name: 'name',\n type: 'type',\n },\n prepare({label, name, type}) {\n return {\n title: label || name,\n subtitle: type,\n }\n },\n },\n})\n","import type {SchemaTypeDefinition} from 'sanity'\n\nimport type {FieldsOption} from '..'\nimport {formType} from './form'\nimport {formFieldType} from './form-field'\n\nexport const schema = (fields: FieldsOption): {types: SchemaTypeDefinition[]} => {\n return {types: [formType(fields), formFieldType]}\n}\n","import {definePlugin, type FieldDefinition} from 'sanity'\n\n// import {structureTool} from 'sanity/structure'\n// import {FormRenderer} from './components/form-renderer'\nimport {schema} from './schema-types'\n// import {defaultDocumentNode} from './structure'\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {formSchema} from '@sanity/form-toolkit'\n *\n * export default defineConfig({\n * // ...\n * plugins: [formSchema()],\n * })\n * ```\n */\nexport type FieldsOption = Array<FieldDefinition>\ninterface FormSchemaPluginOptions {\n /**\n * Array of field definitions to be used in the form schema.\n */\n fields?: FieldsOption\n}\n\nexport const formSchema = definePlugin<FormSchemaPluginOptions | void>((options) => {\n return {\n name: 'form-toolkit_form-schema',\n schema: schema(options?.fields ?? []),\n // plugins: [structureTool({defaultDocumentNode})],\n }\n})\n"],"names":["formType","fields","defineType","name","title","type","icon","FaWpforms","defineField","description","validation","Rule","required","options","source","of","initialValue","ValidationType","props","$","_c","t0","path","slice","useFormValue","schemaType","t1","renderDefault","validationTypesByFieldType","t2","list","fieldTypeTitle","fieldType","charAt","toUpperCase","formFieldType","LuTextCursorInput","Object","keys","map","value","custom","context","test","document","field","filter","n","length","includes","toLowerCase","hidden","parent","validationTypes","components","input","preview","select","subtitle","label","prepare","schema","types","formSchema","definePlugin"],"mappings":";;;;AAKO,MAAMA,WAAYC,YAGhBC,WAAW;AAAA,EAChBC,MAAM;AAAA,EACNC,OAAO;AAAA,EACPC,MAAM;AAAA,EACNC,MAAMC;AAAAA,EACNN,QAAQ,CACNO,YAAY;AAAA,IACVL,MAAM;AAAA,IACNC,OAAO;AAAA,IACPC,MAAM;AAAA,IACNI,aAAa;AAAA,IACbC,YAAaC,CAAAA,SAASA,KAAKC,SAAAA;AAAA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MACNC,OAAO;AAAA,MACPC,MAAM;AAAA,IAAA,CACP,CAAC;AAAA,EAAA,CAEL,CAAC;AAAA,EAEJmD,SAAS;AAAA,IACPC,QAAQ;AAAA,MACNE,OAAO;AAAA,MACPxD,MAAM;AAAA,MACNE,MAAM;AAAA,IAAA;AAAA,IAERuD,QAAQ;AAAA,MAACD;AAAAA,MAAOxD;AAAAA,MAAME;AAAAA,IAAAA,GAAO;AAC3B,aAAO;AAAA,QACLD,OAAOuD,SAASxD;AAAAA,QAChBuD,UAAUrD;AAAAA,MAAAA;AAAAA,IAEd;AAAA,EAAA;AAEJ,CAAC,GC3NYwD,SAAU5D,CAAAA,YACd;AAAA,EAAC6D,OAAO,CAAC9D,SAASC,MAAM,GAAGkC,aAAa;AAAC,ICqBrC4B,aAAaC,aAA8CnD,CAAAA,aAC/D;AAAA,EACLV,MAAM;AAAA,EACN0D,QAAQA,OAAOhD,SAASZ,UAAU,CAAA,CAAE;AAAA;AAEtC,EACD;"}
|
package/dist/formium/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface FormiumInputConfig {}
|
|
3
2
|
/**
|
|
4
3
|
* Usage in `sanity.config.ts` (or .js)
|
|
5
4
|
*
|
|
@@ -13,8 +12,6 @@ import {Plugin as Plugin_2} from 'sanity'
|
|
|
13
12
|
* })
|
|
14
13
|
* ```
|
|
15
14
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export {}
|
|
15
|
+
declare const formiumInput: import("sanity").Plugin<void | FormiumInputConfig>;
|
|
16
|
+
export { formiumInput };
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/formium/index.ts"],"mappings":"UAIU,kBAAA;;;AAAkB;AAkB5B;;;;AAAyB;;;;;;cAAZ,YAAA,mBAAY,MAAA,QAAA,kBAAA"}
|
package/dist/formium/index.js
CHANGED
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const formiumInput =
|
|
1
|
+
import { createClient } from "@formium/client";
|
|
2
|
+
import { asyncList } from "@sanity/sanity-plugin-async-list";
|
|
3
|
+
import { definePlugin } from "sanity";
|
|
4
|
+
const formiumInput = definePlugin(() => ({
|
|
5
5
|
name: "sanity-plugin-form-toolkit_formium-input",
|
|
6
|
-
plugins: [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
plugins: [asyncList({
|
|
7
|
+
schemaType: "formiumInput",
|
|
8
|
+
secrets: {
|
|
9
|
+
keys: [{
|
|
10
|
+
key: "projectId",
|
|
11
|
+
title: "Project ID"
|
|
12
|
+
}, {
|
|
13
|
+
key: "token",
|
|
14
|
+
title: "Token"
|
|
15
|
+
}]
|
|
16
|
+
},
|
|
17
|
+
loader: async ({
|
|
18
|
+
secrets
|
|
19
|
+
}) => {
|
|
20
|
+
const formium = createClient(secrets?.projectId || "", {
|
|
21
|
+
apiToken: secrets?.token
|
|
22
|
+
}), {
|
|
23
|
+
data
|
|
24
|
+
} = await formium.findForms();
|
|
25
|
+
return data && data.length ? data.map(({
|
|
26
|
+
name,
|
|
27
|
+
id
|
|
28
|
+
}) => ({
|
|
29
|
+
title: name,
|
|
30
|
+
value: id
|
|
31
|
+
})) : [];
|
|
32
|
+
}
|
|
33
|
+
})]
|
|
26
34
|
}));
|
|
27
|
-
|
|
35
|
+
export {
|
|
36
|
+
formiumInput
|
|
37
|
+
};
|
|
28
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/formium/index.ts"],"sourcesContent":["import {createClient, type Form} from '@formium/client'\nimport {asyncList} from '@sanity/sanity-plugin-async-list'\nimport {definePlugin} from 'sanity'\n\ninterface FormiumInputConfig {\n /* nothing here yet */\n}\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {formiumInput} from 'sanity-plugin-form-toolkit'\n *\n * export default defineConfig({\n * // ...\n * plugins: [formiumInput()],\n * })\n * ```\n */\n// Is Formium dead? All attempts to use the API come back with an expired cert https://github.com/formium/formium/issues/77\nexport const formiumInput = definePlugin<FormiumInputConfig | void>(() => {\n return {\n name: 'sanity-plugin-form-toolkit_formium-input',\n plugins: [\n asyncList({\n schemaType: 'formiumInput',\n secrets: {\n keys: [\n {key: 'projectId', title: 'Project ID'},\n {key: 'token', title: 'Token'},\n ],\n },\n loader: async ({secrets}) => {\n const formium = createClient(secrets?.projectId || '', {\n apiToken: secrets?.token,\n })\n const {data}: {data: Form[]} = await formium.findForms()\n return data && data.length\n ? data.map(({name, id}) => {\n return {\n title: name,\n value: id,\n }\n })\n : []\n },\n }),\n ],\n }\n})\n"],"names":["definePlugin","asyncList","createClient"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/formium/index.ts"],"sourcesContent":["import {createClient, type Form} from '@formium/client'\nimport {asyncList} from '@sanity/sanity-plugin-async-list'\nimport {definePlugin} from 'sanity'\n\ninterface FormiumInputConfig {\n /* nothing here yet */\n}\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {formiumInput} from 'sanity-plugin-form-toolkit'\n *\n * export default defineConfig({\n * // ...\n * plugins: [formiumInput()],\n * })\n * ```\n */\n// Is Formium dead? All attempts to use the API come back with an expired cert https://github.com/formium/formium/issues/77\nexport const formiumInput = definePlugin<FormiumInputConfig | void>(() => {\n return {\n name: 'sanity-plugin-form-toolkit_formium-input',\n plugins: [\n asyncList({\n schemaType: 'formiumInput',\n secrets: {\n keys: [\n {key: 'projectId', title: 'Project ID'},\n {key: 'token', title: 'Token'},\n ],\n },\n loader: async ({secrets}) => {\n const formium = createClient(secrets?.['projectId'] || '', {\n apiToken: secrets?.['token'],\n })\n const {data}: {data: Form[]} = await formium.findForms()\n return data && data.length\n ? data.map(({name, id}) => {\n return {\n title: name,\n value: id,\n }\n })\n : []\n },\n }),\n ],\n }\n})\n"],"names":["formiumInput","definePlugin","name","plugins","asyncList","schemaType","secrets","keys","key","title","loader","formium","createClient","apiToken","data","findForms","length","map","id","value"],"mappings":";;;AAsBO,MAAMA,eAAeC,aAAwC,OAC3D;AAAA,EACLC,MAAM;AAAA,EACNC,SAAS,CACPC,UAAU;AAAA,IACRC,YAAY;AAAA,IACZC,SAAS;AAAA,MACPC,MAAM,CACJ;AAAA,QAACC,KAAK;AAAA,QAAaC,OAAO;AAAA,MAAA,GAC1B;AAAA,QAACD,KAAK;AAAA,QAASC,OAAO;AAAA,MAAA,CAAQ;AAAA,IAAA;AAAA,IAGlCC,QAAQ,OAAO;AAAA,MAACJ;AAAAA,IAAAA,MAAa;AAC3B,YAAMK,UAAUC,aAAaN,SAAU,aAAgB,IAAI;AAAA,QACzDO,UAAUP,SAAU;AAAA,MAAA,CACrB,GACK;AAAA,QAACQ;AAAAA,MAAAA,IAAwB,MAAMH,QAAQI,UAAAA;AAC7C,aAAOD,QAAQA,KAAKE,SAChBF,KAAKG,IAAI,CAAC;AAAA,QAACf;AAAAA,QAAMgB;AAAAA,MAAAA,OACR;AAAA,QACLT,OAAOP;AAAAA,QACPiB,OAAOD;AAAAA,MAAAA,EAEV,IACD,CAAA;AAAA,IACN;AAAA,EAAA,CACD,CAAC;AAEN,EACD;"}
|