@sanity/form-toolkit 2.2.2 → 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.
Files changed (64) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +0 -2
  3. package/dist/_chunks-es/{create-handler.mjs → create-handler.js} +45 -17
  4. package/dist/_chunks-es/create-handler.js.map +1 -0
  5. package/dist/form-renderer/index.d.ts +53 -64
  6. package/dist/form-renderer/index.d.ts.map +1 -0
  7. package/dist/form-renderer/index.js +123 -108
  8. package/dist/form-renderer/index.js.map +1 -1
  9. package/dist/form-schema/index.d.ts +7 -11
  10. package/dist/form-schema/index.d.ts.map +1 -0
  11. package/dist/form-schema/index.js +181 -181
  12. package/dist/form-schema/index.js.map +1 -1
  13. package/dist/formium/index.d.ts +4 -7
  14. package/dist/formium/index.d.ts.map +1 -0
  15. package/dist/formium/index.js +35 -25
  16. package/dist/formium/index.js.map +1 -1
  17. package/dist/hubspot/index.d.ts +52 -48
  18. package/dist/hubspot/index.d.ts.map +1 -0
  19. package/dist/hubspot/index.js +52 -26
  20. package/dist/hubspot/index.js.map +1 -1
  21. package/dist/mailchimp/index.d.ts +56 -42
  22. package/dist/mailchimp/index.d.ts.map +1 -0
  23. package/dist/mailchimp/index.js +55 -37
  24. package/dist/mailchimp/index.js.map +1 -1
  25. package/package.json +36 -107
  26. package/dist/_chunks-cjs/create-handler.js +0 -68
  27. package/dist/_chunks-cjs/create-handler.js.map +0 -1
  28. package/dist/_chunks-es/create-handler.mjs.map +0 -1
  29. package/dist/form-renderer/index.d.mts +0 -66
  30. package/dist/form-renderer/index.mjs +0 -128
  31. package/dist/form-renderer/index.mjs.map +0 -1
  32. package/dist/form-schema/index.d.mts +0 -28
  33. package/dist/form-schema/index.mjs +0 -230
  34. package/dist/form-schema/index.mjs.map +0 -1
  35. package/dist/formium/index.d.mts +0 -20
  36. package/dist/formium/index.mjs +0 -30
  37. package/dist/formium/index.mjs.map +0 -1
  38. package/dist/hubspot/index.d.mts +0 -49
  39. package/dist/hubspot/index.mjs +0 -48
  40. package/dist/hubspot/index.mjs.map +0 -1
  41. package/dist/mailchimp/index.d.mts +0 -45
  42. package/dist/mailchimp/index.mjs +0 -49
  43. package/dist/mailchimp/index.mjs.map +0 -1
  44. package/sanity.json +0 -8
  45. package/src/form-renderer/components/default-field.tsx +0 -123
  46. package/src/form-renderer/components/form-renderer.tsx +0 -62
  47. package/src/form-renderer/components/types.ts +0 -51
  48. package/src/form-renderer/index.ts +0 -4
  49. package/src/form-schema/components/validation-type.tsx +0 -14
  50. package/src/form-schema/index.ts +0 -35
  51. package/src/form-schema/schema-types/form-field.ts +0 -224
  52. package/src/form-schema/schema-types/form.ts +0 -52
  53. package/src/form-schema/schema-types/index.ts +0 -9
  54. package/src/formium/index.ts +0 -52
  55. package/src/hubspot/components/option.tsx +0 -17
  56. package/src/hubspot/create-handler.ts +0 -6
  57. package/src/hubspot/fetch-hubspot-data.ts +0 -33
  58. package/src/hubspot/index.ts +0 -52
  59. package/src/index.ts +0 -19
  60. package/src/mailchimp/components/option.tsx +0 -30
  61. package/src/mailchimp/create-handler.ts +0 -39
  62. package/src/mailchimp/index.ts +0 -43
  63. package/src/shared/create-handler.ts +0 -109
  64. package/v2-incompatible.js +0 -11
@@ -1,52 +0,0 @@
1
- import {asyncList} from '@sanity/sanity-plugin-async-list'
2
- import {definePlugin} from 'sanity'
3
-
4
- import {Option} from './components/option'
5
- import {hubSpotHandler} from './create-handler'
6
- import {fetchHubSpotData} from './fetch-hubspot-data'
7
- interface HubSpotInputConfig {
8
- url: string | URL
9
- }
10
-
11
- /**
12
- * Usage in `sanity.config.ts` (or .js)
13
- *
14
- * ```ts
15
- * import {defineConfig} from 'sanity'
16
- * import {hubSpotInput} from '@sanity/form-toolkit/hubspot'
17
- *
18
- * export default defineConfig({
19
- * // ...
20
- * plugins: [
21
- * hubSpotInput({
22
- * url: 'http://localhost:3000/api/hubspot'
23
- * })
24
- * ],
25
- * })
26
- * ```
27
- */
28
-
29
- type ExtendedOption = {value: string; name: string}
30
- export {fetchHubSpotData, hubSpotHandler}
31
- export const hubSpotInput = definePlugin<HubSpotInputConfig>((options) => {
32
- return {
33
- name: 'sanity-plugin-form-toolkit_hubspot-input',
34
- plugins: [
35
- asyncList({
36
- schemaType: 'hubSpotForm',
37
- loader: async () => {
38
- const data = await fetch(options.url)
39
- const body = await data.json()
40
- return body
41
- },
42
- autocompleteProps: {
43
- renderOption: (option) => Option(option as ExtendedOption),
44
- renderValue(value, option) {
45
- // @ts-expect-error can't extend default type?
46
- return option?.name ?? value
47
- },
48
- },
49
- }),
50
- ],
51
- }
52
- })
package/src/index.ts DELETED
@@ -1,19 +0,0 @@
1
- // import {FormRenderer, formSchema} from './form-schema'
2
- // import type {FormDataProps} from './form-schema/components/types'
3
- // import {hubSpotInput} from './hubspot'
4
- // import {hubSpotHandler} from './hubspot/create-handler'
5
- // import {fetchHubSpotData} from './hubspot/fetch-hubspot-data'
6
- // import {mailchimpInput} from './mailchimp'
7
- // import {fetchMailchimpData, mailchimpHandler} from './mailchimp/create-handler'
8
-
9
- // export {
10
- // fetchHubSpotData,
11
- // fetchMailchimpData,
12
- // type FormDataProps,
13
- // FormRenderer,
14
- // formSchema,
15
- // hubSpotHandler,
16
- // hubSpotInput,
17
- // mailchimpHandler,
18
- // mailchimpInput,
19
- // }
@@ -1,30 +0,0 @@
1
- import {Card, Text} from '@sanity/ui'
2
- import type {ReactElement} from 'react'
3
-
4
- export const Option = (option: {
5
- value: string
6
- form: {
7
- header: {
8
- text?: string
9
- }
10
- }
11
- list: {
12
- name: string
13
- stats: {
14
- member_count: number
15
- }
16
- }
17
- }): ReactElement => {
18
- return (
19
- <Card data-as="button" padding={3} radius={2} tone="inherit">
20
- <Text size={2} textOverflow="ellipsis">
21
- {`${option.form.header.text ? `${option.form.header.text} - ` : ``}${option.value}`}
22
- </Text>
23
- <Card paddingTop={2} tone="inherit" style={{background: 'inherit'}}>
24
- <Text size={1} textOverflow="ellipsis">
25
- {`${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? '' : 's'}`}
26
- </Text>
27
- </Card>
28
- </Card>
29
- )
30
- }
@@ -1,39 +0,0 @@
1
- import mailchimp from '@mailchimp/mailchimp_marketing'
2
-
3
- import createHandler from '../shared/create-handler'
4
-
5
- // Fetch from Mailchimp's API
6
- export async function fetchMailchimpData({
7
- key,
8
- server,
9
- }: {
10
- key: string
11
- server: string
12
- }): Promise<unknown> {
13
- mailchimp.setConfig({
14
- apiKey: key,
15
- server: server,
16
- })
17
- const signupForms = []
18
- // @ts-expect-error bad typing for mailchimp
19
- const {lists} = await mailchimp.lists.getAllLists()
20
- for (const list of lists) {
21
- // @ts-expect-error bad typing for mailchimp
22
- // eslint-disable-next-line camelcase
23
- const {signup_forms} = await mailchimp.lists.getListSignupForms(list.id)
24
- // eslint-disable-next-line camelcase
25
- for (const form of signup_forms) {
26
- signupForms.push({
27
- list,
28
- form,
29
- value: form.signup_form_url,
30
- })
31
- }
32
- }
33
- return signupForms
34
- }
35
-
36
- // Create the Mailchimp handler for a specific key and server
37
- export const mailchimpHandler = (keys: {key: string; server: string}) => {
38
- return createHandler(() => fetchMailchimpData(keys))
39
- }
@@ -1,43 +0,0 @@
1
- import {asyncList} from '@sanity/sanity-plugin-async-list'
2
- import {definePlugin} from 'sanity'
3
-
4
- import {Option} from './components/option'
5
- import {mailchimpHandler} from './create-handler'
6
- import {fetchMailchimpData} from './create-handler'
7
- interface MailchimpInputConfig {
8
- url: string | URL
9
- }
10
-
11
- /**
12
- * Usage in `sanity.config.ts` (or .js)
13
- *
14
- * ```ts
15
- * import {defineConfig} from 'sanity'
16
- * import {mailchimpInput} from '@sanity/form-toolkit/mailchimp'
17
- *
18
- * export default defineConfig({
19
- * // ...
20
- * plugins: [mailchimpInput()],
21
- * })
22
- * ```
23
- */
24
- export {fetchMailchimpData, mailchimpHandler}
25
- export const mailchimpInput = definePlugin<MailchimpInputConfig>((options) => {
26
- return {
27
- name: 'sanity-plugin-form-toolkit_mailchimp-input',
28
- plugins: [
29
- asyncList({
30
- schemaType: 'mailchimpForm',
31
- loader: async () => {
32
- const data = await fetch(options.url)
33
- const body = await data.json()
34
- return body
35
- },
36
- autocompleteProps: {
37
- //@ts-expect-error incorrect typing on props?
38
- renderOption: (option) => Option(option),
39
- },
40
- }),
41
- ],
42
- }
43
- })
@@ -1,109 +0,0 @@
1
- import {defineEventHandler, type H3Event} from 'h3' // For Nuxt.js/Nitro
2
- import type {IncomingMessage, ServerResponse} from 'http'
3
-
4
- // Utility function to detect the framework at runtime
5
- const detectFramework = (): string => {
6
- if (process.env.NEXT_RUNTIME) {
7
- return 'nextjs'
8
- } else if (process.env.NUXT_ENV) {
9
- return 'nuxt'
10
- } else if (process.env.SVELTEKIT_ENV) {
11
- return 'sveltekit'
12
- } else if (process.env.REMIX_ENV) {
13
- return 'remix'
14
- } else if (process.env.ASTRO_ENV) {
15
- return 'astro'
16
- }
17
- throw new Error('Unable to detect framework.')
18
- }
19
-
20
- // Create a generic handler with predefined logic
21
- const createHandler = (handlerFunc: () => Promise<unknown>) => {
22
- const framework = detectFramework()
23
-
24
- // Handler logic to fetch Mailchimp data
25
- const handlerLogic = async ({
26
- // eslint-disable-next-line
27
- req,
28
- res,
29
- }: {
30
- req: IncomingMessage | Request
31
- res?: ServerResponse
32
- }): Promise<unknown> => {
33
- try {
34
- const data = await handlerFunc()
35
-
36
- if (res) {
37
- // Send response directly for frameworks like Next.js and Nuxt.js
38
- res.writeHead(200, {'Content-Type': 'application/json'})
39
- res.end(JSON.stringify(data))
40
- }
41
-
42
- // Return the response for frameworks like SvelteKit, Remix, and Astro
43
- return data
44
- } catch (error) {
45
- if (error instanceof Error) {
46
- if (res) {
47
- res.writeHead(500, {'Content-Type': 'application/json'})
48
- res.end(JSON.stringify({error: error.message}))
49
- }
50
- return {error: error.message}
51
- }
52
- // Handle non-Error types (e.g., strings, objects)
53
- if (res) {
54
- res.writeHead(500, {'Content-Type': 'application/json'})
55
- res.end(JSON.stringify({error: 'An unexpected error occurred'}))
56
- }
57
- return {error: 'An unexpected error occurred'}
58
- }
59
- }
60
-
61
- // Framework-specific implementations
62
- if (framework === 'nextjs') {
63
- return async (req: IncomingMessage, res: ServerResponse) => {
64
- // Set CORS headers
65
- res.setHeader('Access-Control-Allow-Origin', '*') // Allow all origins
66
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') // Allowed HTTP methods
67
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization') // Allowed headers
68
-
69
- await handlerLogic({req, res})
70
- }
71
- } else if (framework === 'nuxt') {
72
- return defineEventHandler(async (event: H3Event) => {
73
- const req = event.node.req
74
- const res = event.node.res
75
- return handlerLogic({req, res})
76
- })
77
- } else if (framework === 'sveltekit') {
78
- return {
79
- GET: async ({request}: {request: Request}) => {
80
- const result = await handlerLogic({req: request})
81
- return new Response(JSON.stringify(result), {
82
- headers: {'Content-Type': 'application/json'},
83
- })
84
- },
85
- }
86
- } else if (framework === 'remix') {
87
- return {
88
- loader: async ({request}: {request: Request}) => {
89
- const result = await handlerLogic({req: request})
90
- return new Response(JSON.stringify(result), {
91
- headers: {'Content-Type': 'application/json'},
92
- })
93
- },
94
- }
95
- } else if (framework === 'astro') {
96
- return {
97
- get: async ({request}: {request: Request}) => {
98
- const result = await handlerLogic({req: request})
99
- return {
100
- body: JSON.stringify(result),
101
- headers: {'Content-Type': 'application/json'},
102
- }
103
- },
104
- }
105
- }
106
- throw new Error(`Unsupported framework: ${framework}`)
107
- }
108
-
109
- export default createHandler
@@ -1,11 +0,0 @@
1
- const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
2
- const {name, version, sanityExchangeUrl} = require('./package.json')
3
-
4
- export default showIncompatiblePluginDialog({
5
- name: name,
6
- versions: {
7
- v3: version,
8
- v2: undefined,
9
- },
10
- sanityExchangeUrl,
11
- })