@sanity/form-toolkit 1.2.0 → 2.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/README.md +8 -8
- package/dist/_chunks-cjs/create-handler.js +68 -0
- package/dist/_chunks-cjs/create-handler.js.map +1 -0
- package/dist/_chunks-es/create-handler.mjs +69 -0
- package/dist/_chunks-es/create-handler.mjs.map +1 -0
- package/dist/form-schema/index.d.mts +69 -0
- package/dist/form-schema/index.d.ts +69 -0
- package/dist/{index.js → form-schema/index.js} +5 -150
- package/dist/form-schema/index.js.map +1 -0
- package/dist/{index.mjs → form-schema/index.mjs} +6 -151
- package/dist/form-schema/index.mjs.map +1 -0
- package/dist/formium/index.d.mts +20 -0
- package/dist/formium/index.d.ts +20 -0
- package/dist/formium/index.js +28 -0
- package/dist/formium/index.js.map +1 -0
- package/dist/formium/index.mjs +30 -0
- package/dist/formium/index.mjs.map +1 -0
- package/dist/hubspot/index.d.mts +49 -0
- package/dist/hubspot/index.d.ts +49 -0
- package/dist/hubspot/index.js +44 -0
- package/dist/hubspot/index.js.map +1 -0
- package/dist/hubspot/index.mjs +48 -0
- package/dist/hubspot/index.mjs.map +1 -0
- package/dist/mailchimp/index.d.mts +45 -0
- package/dist/mailchimp/index.d.ts +45 -0
- package/dist/mailchimp/index.js +48 -0
- package/dist/mailchimp/index.js.map +1 -0
- package/dist/mailchimp/index.mjs +49 -0
- package/dist/mailchimp/index.mjs.map +1 -0
- package/package.json +37 -7
- package/src/form-schema/components/form-renderer.tsx +9 -4
- package/src/form-schema/index.ts +2 -1
- package/src/hubspot/index.ts +5 -3
- package/src/index.ts +18 -18
- package/src/mailchimp/index.ts +5 -4
- package/dist/index.d.mts +0 -166
- package/dist/index.d.ts +0 -166
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {EventHandler} from 'h3'
|
|
2
|
+
import {EventHandlerRequest} from 'h3'
|
|
3
|
+
import {IncomingMessage} from 'http'
|
|
4
|
+
import {Plugin as Plugin_2} from 'sanity'
|
|
5
|
+
import {ServerResponse} from 'http'
|
|
6
|
+
|
|
7
|
+
export declare function fetchMailchimpData({
|
|
8
|
+
key,
|
|
9
|
+
server,
|
|
10
|
+
}: {
|
|
11
|
+
key: string
|
|
12
|
+
server: string
|
|
13
|
+
}): Promise<unknown>
|
|
14
|
+
|
|
15
|
+
export declare const mailchimpHandler: (keys: {key: string; server: string}) =>
|
|
16
|
+
| ((req: IncomingMessage, res: ServerResponse) => Promise<void>)
|
|
17
|
+
| EventHandler<EventHandlerRequest, Promise<unknown>>
|
|
18
|
+
| {
|
|
19
|
+
GET: ({request}: {request: Request}) => Promise<Response>
|
|
20
|
+
loader?: undefined
|
|
21
|
+
get?: undefined
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
loader: ({request}: {request: Request}) => Promise<Response>
|
|
25
|
+
GET?: undefined
|
|
26
|
+
get?: undefined
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
get: ({request}: {request: Request}) => Promise<{
|
|
30
|
+
body: string
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': string
|
|
33
|
+
}
|
|
34
|
+
}>
|
|
35
|
+
GET?: undefined
|
|
36
|
+
loader?: undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare const mailchimpInput: Plugin_2<MailchimpInputConfig>
|
|
40
|
+
|
|
41
|
+
declare interface MailchimpInputConfig {
|
|
42
|
+
url: string | URL
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
var sanityPluginAsyncList = require("@sanity/sanity-plugin-async-list"), sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), mailchimp = require("@mailchimp/mailchimp_marketing"), createHandler = require("../_chunks-cjs/create-handler.js");
|
|
4
|
+
function _interopDefaultCompat(e) {
|
|
5
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
|
+
}
|
|
7
|
+
var mailchimp__default = /* @__PURE__ */ _interopDefaultCompat(mailchimp);
|
|
8
|
+
const Option = (option) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Card, { "data-as": "button", padding: 3, radius: 2, tone: "inherit", children: [
|
|
9
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 2, textOverflow: "ellipsis", children: `${option.form.header.text ? `${option.form.header.text} - ` : ""}${option.value}` }),
|
|
10
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Card, { paddingTop: 2, tone: "inherit", style: { background: "inherit" }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, textOverflow: "ellipsis", children: `${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? "" : "s"}` }) })
|
|
11
|
+
] });
|
|
12
|
+
async function fetchMailchimpData({
|
|
13
|
+
key,
|
|
14
|
+
server
|
|
15
|
+
}) {
|
|
16
|
+
mailchimp__default.default.setConfig({
|
|
17
|
+
apiKey: key,
|
|
18
|
+
server
|
|
19
|
+
});
|
|
20
|
+
const signupForms = [], { lists } = await mailchimp__default.default.lists.getAllLists();
|
|
21
|
+
for (const list of lists) {
|
|
22
|
+
const { signup_forms } = await mailchimp__default.default.lists.getListSignupForms(list.id);
|
|
23
|
+
for (const form of signup_forms)
|
|
24
|
+
signupForms.push({
|
|
25
|
+
list,
|
|
26
|
+
form,
|
|
27
|
+
value: form.signup_form_url
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return signupForms;
|
|
31
|
+
}
|
|
32
|
+
const mailchimpHandler = (keys) => createHandler.createHandler(() => fetchMailchimpData(keys)), mailchimpInput = sanity.definePlugin((options) => ({
|
|
33
|
+
name: "sanity-plugin-form-toolkit_mailchimp-input",
|
|
34
|
+
plugins: [
|
|
35
|
+
sanityPluginAsyncList.asyncList({
|
|
36
|
+
schemaType: "mailchimpForm",
|
|
37
|
+
loader: async () => await (await fetch(options.url)).json(),
|
|
38
|
+
autocompleteProps: {
|
|
39
|
+
//@ts-expect-error incorrect typing on props?
|
|
40
|
+
renderOption: (option) => Option(option)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
]
|
|
44
|
+
}));
|
|
45
|
+
exports.fetchMailchimpData = fetchMailchimpData;
|
|
46
|
+
exports.mailchimpHandler = mailchimpHandler;
|
|
47
|
+
exports.mailchimpInput = mailchimpInput;
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/mailchimp/components/option.tsx","../../src/mailchimp/create-handler.ts","../../src/mailchimp/index.ts"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport type {ReactElement} from 'react'\n\nexport const Option = (option: {\n value: string\n form: {\n header: {\n text?: string\n }\n }\n list: {\n name: string\n stats: {\n member_count: number\n }\n }\n}): ReactElement => {\n return (\n <Card data-as=\"button\" padding={3} radius={2} tone=\"inherit\">\n <Text size={2} textOverflow=\"ellipsis\">\n {`${option.form.header.text ? `${option.form.header.text} - ` : ``}${option.value}`}\n </Text>\n <Card paddingTop={2} tone=\"inherit\" style={{background: 'inherit'}}>\n <Text size={1} textOverflow=\"ellipsis\">\n {`${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? '' : 's'}`}\n </Text>\n </Card>\n </Card>\n )\n}\n","import mailchimp from '@mailchimp/mailchimp_marketing'\n\nimport createHandler from '../shared/create-handler'\n\n// Fetch from Mailchimp's API\nexport async function fetchMailchimpData({\n key,\n server,\n}: {\n key: string\n server: string\n}): Promise<unknown> {\n mailchimp.setConfig({\n apiKey: key,\n server: server,\n })\n const signupForms = []\n // @ts-expect-error bad typing for mailchimp\n const {lists} = await mailchimp.lists.getAllLists()\n for (const list of lists) {\n // @ts-expect-error bad typing for mailchimp\n // eslint-disable-next-line camelcase\n const {signup_forms} = await mailchimp.lists.getListSignupForms(list.id)\n // eslint-disable-next-line camelcase\n for (const form of signup_forms) {\n signupForms.push({\n list,\n form,\n value: form.signup_form_url,\n })\n }\n }\n return signupForms\n}\n\n// Create the Mailchimp handler for a specific key and server\nexport const mailchimpHandler = (keys: {key: string; server: string}) => {\n return createHandler(() => fetchMailchimpData(keys))\n}\n","import {asyncList} from '@sanity/sanity-plugin-async-list'\nimport {definePlugin} from 'sanity'\n\nimport {Option} from './components/option'\nimport {mailchimpHandler} from './create-handler'\nimport {fetchMailchimpData} from './create-handler'\ninterface MailchimpInputConfig {\n url: string | URL\n}\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {mailchimpInput} from '@sanity/form-toolkit/mailchimp'\n *\n * export default defineConfig({\n * // ...\n * plugins: [mailchimpInput()],\n * })\n * ```\n */\nexport {fetchMailchimpData, mailchimpHandler}\nexport const mailchimpInput = definePlugin<MailchimpInputConfig>((options) => {\n return {\n name: 'sanity-plugin-form-toolkit_mailchimp-input',\n plugins: [\n asyncList({\n schemaType: 'mailchimpForm',\n loader: async () => {\n const data = await fetch(options.url)\n const body = await data.json()\n return body\n },\n autocompleteProps: {\n //@ts-expect-error incorrect typing on props?\n renderOption: (option) => Option(option),\n },\n }),\n ],\n }\n})\n"],"names":["jsxs","Card","jsx","Text","mailchimp","createHandler","definePlugin","asyncList"],"mappings":";;;;;;;AAGO,MAAM,SAAS,CAAC,WAenBA,2BAAA,KAACC,GAAK,MAAA,EAAA,WAAQ,UAAS,SAAS,GAAG,QAAQ,GAAG,MAAK,WACjD,UAAA;AAAA,EAACC,2BAAAA,IAAAC,GAAA,MAAA,EAAK,MAAM,GAAG,cAAa,YACzB,UAAG,GAAA,OAAO,KAAK,OAAO,OAAO,GAAG,OAAO,KAAK,OAAO,IAAI,QAAQ,EAAE,GAAG,OAAO,KAAK,GACnF,CAAA;AAAA,EACCD,2BAAA,IAAAD,GAAA,MAAA,EAAK,YAAY,GAAG,MAAK,WAAU,OAAO,EAAC,YAAY,aACtD,UAAAC,2BAAAA,IAACC,GAAK,MAAA,EAAA,MAAM,GAAG,cAAa,YACzB,UAAG,GAAA,OAAO,KAAK,IAAI,MAAM,OAAO,KAAK,MAAM,YAAY,UAAU,OAAO,KAAK,MAAM,gBAAgB,IAAI,KAAK,GAAG,IAClH,EACF,CAAA;AAAA,GACF;ACtBJ,eAAsB,mBAAmB;AAAA,EACvC;AAAA,EACA;AACF,GAGqB;AACnBC,qBAAAA,QAAU,UAAU;AAAA,IAClB,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AACK,QAAA,cAAc,CAAA,GAEd,EAAC,MAAS,IAAA,MAAMA,mBAAU,QAAA,MAAM,YAAY;AAClD,aAAW,QAAQ,OAAO;AAGlB,UAAA,EAAC,iBAAgB,MAAMA,mBAAAA,QAAU,MAAM,mBAAmB,KAAK,EAAE;AAEvE,eAAW,QAAQ;AACjB,kBAAY,KAAK;AAAA,QACf;AAAA,QACA;AAAA,QACA,OAAO,KAAK;AAAA,MAAA,CACb;AAAA,EAAA;AAGE,SAAA;AACT;AAGO,MAAM,mBAAmB,CAAC,SACxBC,4BAAc,MAAM,mBAAmB,IAAI,CAAC,GCbxC,iBAAiBC,OAAAA,aAAmC,CAAC,aACzD;AAAA,EACL,MAAM;AAAA,EACN,SAAS;AAAA,IACPC,gCAAU;AAAA,MACR,YAAY;AAAA,MACZ,QAAQ,YAEO,OADA,MAAM,MAAM,QAAQ,GAAG,GACZ,KAAK;AAAA,MAG/B,mBAAmB;AAAA;AAAA,QAEjB,cAAc,CAAC,WAAW,OAAO,MAAM;AAAA,MAAA;AAAA,IAE1C,CAAA;AAAA,EAAA;AAEL,EACD;;;;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { asyncList } from "@sanity/sanity-plugin-async-list";
|
|
2
|
+
import { definePlugin } from "sanity";
|
|
3
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Card, Text } from "@sanity/ui";
|
|
5
|
+
import mailchimp from "@mailchimp/mailchimp_marketing";
|
|
6
|
+
import { createHandler } from "../_chunks-es/create-handler.mjs";
|
|
7
|
+
const Option = (option) => /* @__PURE__ */ jsxs(Card, { "data-as": "button", padding: 3, radius: 2, tone: "inherit", children: [
|
|
8
|
+
/* @__PURE__ */ jsx(Text, { size: 2, textOverflow: "ellipsis", children: `${option.form.header.text ? `${option.form.header.text} - ` : ""}${option.value}` }),
|
|
9
|
+
/* @__PURE__ */ jsx(Card, { paddingTop: 2, tone: "inherit", style: { background: "inherit" }, children: /* @__PURE__ */ jsx(Text, { size: 1, textOverflow: "ellipsis", children: `${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? "" : "s"}` }) })
|
|
10
|
+
] });
|
|
11
|
+
async function fetchMailchimpData({
|
|
12
|
+
key,
|
|
13
|
+
server
|
|
14
|
+
}) {
|
|
15
|
+
mailchimp.setConfig({
|
|
16
|
+
apiKey: key,
|
|
17
|
+
server
|
|
18
|
+
});
|
|
19
|
+
const signupForms = [], { lists } = await mailchimp.lists.getAllLists();
|
|
20
|
+
for (const list of lists) {
|
|
21
|
+
const { signup_forms } = await mailchimp.lists.getListSignupForms(list.id);
|
|
22
|
+
for (const form of signup_forms)
|
|
23
|
+
signupForms.push({
|
|
24
|
+
list,
|
|
25
|
+
form,
|
|
26
|
+
value: form.signup_form_url
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return signupForms;
|
|
30
|
+
}
|
|
31
|
+
const mailchimpHandler = (keys) => createHandler(() => fetchMailchimpData(keys)), mailchimpInput = definePlugin((options) => ({
|
|
32
|
+
name: "sanity-plugin-form-toolkit_mailchimp-input",
|
|
33
|
+
plugins: [
|
|
34
|
+
asyncList({
|
|
35
|
+
schemaType: "mailchimpForm",
|
|
36
|
+
loader: async () => await (await fetch(options.url)).json(),
|
|
37
|
+
autocompleteProps: {
|
|
38
|
+
//@ts-expect-error incorrect typing on props?
|
|
39
|
+
renderOption: (option) => Option(option)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
}));
|
|
44
|
+
export {
|
|
45
|
+
fetchMailchimpData,
|
|
46
|
+
mailchimpHandler,
|
|
47
|
+
mailchimpInput
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/mailchimp/components/option.tsx","../../src/mailchimp/create-handler.ts","../../src/mailchimp/index.ts"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport type {ReactElement} from 'react'\n\nexport const Option = (option: {\n value: string\n form: {\n header: {\n text?: string\n }\n }\n list: {\n name: string\n stats: {\n member_count: number\n }\n }\n}): ReactElement => {\n return (\n <Card data-as=\"button\" padding={3} radius={2} tone=\"inherit\">\n <Text size={2} textOverflow=\"ellipsis\">\n {`${option.form.header.text ? `${option.form.header.text} - ` : ``}${option.value}`}\n </Text>\n <Card paddingTop={2} tone=\"inherit\" style={{background: 'inherit'}}>\n <Text size={1} textOverflow=\"ellipsis\">\n {`${option.list.name} - ${option.list.stats.member_count} member${option.list.stats.member_count == 1 ? '' : 's'}`}\n </Text>\n </Card>\n </Card>\n )\n}\n","import mailchimp from '@mailchimp/mailchimp_marketing'\n\nimport createHandler from '../shared/create-handler'\n\n// Fetch from Mailchimp's API\nexport async function fetchMailchimpData({\n key,\n server,\n}: {\n key: string\n server: string\n}): Promise<unknown> {\n mailchimp.setConfig({\n apiKey: key,\n server: server,\n })\n const signupForms = []\n // @ts-expect-error bad typing for mailchimp\n const {lists} = await mailchimp.lists.getAllLists()\n for (const list of lists) {\n // @ts-expect-error bad typing for mailchimp\n // eslint-disable-next-line camelcase\n const {signup_forms} = await mailchimp.lists.getListSignupForms(list.id)\n // eslint-disable-next-line camelcase\n for (const form of signup_forms) {\n signupForms.push({\n list,\n form,\n value: form.signup_form_url,\n })\n }\n }\n return signupForms\n}\n\n// Create the Mailchimp handler for a specific key and server\nexport const mailchimpHandler = (keys: {key: string; server: string}) => {\n return createHandler(() => fetchMailchimpData(keys))\n}\n","import {asyncList} from '@sanity/sanity-plugin-async-list'\nimport {definePlugin} from 'sanity'\n\nimport {Option} from './components/option'\nimport {mailchimpHandler} from './create-handler'\nimport {fetchMailchimpData} from './create-handler'\ninterface MailchimpInputConfig {\n url: string | URL\n}\n\n/**\n * Usage in `sanity.config.ts` (or .js)\n *\n * ```ts\n * import {defineConfig} from 'sanity'\n * import {mailchimpInput} from '@sanity/form-toolkit/mailchimp'\n *\n * export default defineConfig({\n * // ...\n * plugins: [mailchimpInput()],\n * })\n * ```\n */\nexport {fetchMailchimpData, mailchimpHandler}\nexport const mailchimpInput = definePlugin<MailchimpInputConfig>((options) => {\n return {\n name: 'sanity-plugin-form-toolkit_mailchimp-input',\n plugins: [\n asyncList({\n schemaType: 'mailchimpForm',\n loader: async () => {\n const data = await fetch(options.url)\n const body = await data.json()\n return body\n },\n autocompleteProps: {\n //@ts-expect-error incorrect typing on props?\n renderOption: (option) => Option(option),\n },\n }),\n ],\n }\n})\n"],"names":[],"mappings":";;;;;;AAGO,MAAM,SAAS,CAAC,WAenB,qBAAC,MAAK,EAAA,WAAQ,UAAS,SAAS,GAAG,QAAQ,GAAG,MAAK,WACjD,UAAA;AAAA,EAAC,oBAAA,MAAA,EAAK,MAAM,GAAG,cAAa,YACzB,UAAG,GAAA,OAAO,KAAK,OAAO,OAAO,GAAG,OAAO,KAAK,OAAO,IAAI,QAAQ,EAAE,GAAG,OAAO,KAAK,GACnF,CAAA;AAAA,EACC,oBAAA,MAAA,EAAK,YAAY,GAAG,MAAK,WAAU,OAAO,EAAC,YAAY,aACtD,UAAA,oBAAC,MAAK,EAAA,MAAM,GAAG,cAAa,YACzB,UAAG,GAAA,OAAO,KAAK,IAAI,MAAM,OAAO,KAAK,MAAM,YAAY,UAAU,OAAO,KAAK,MAAM,gBAAgB,IAAI,KAAK,GAAG,IAClH,EACF,CAAA;AAAA,GACF;ACtBJ,eAAsB,mBAAmB;AAAA,EACvC;AAAA,EACA;AACF,GAGqB;AACnB,YAAU,UAAU;AAAA,IAClB,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AACK,QAAA,cAAc,CAAA,GAEd,EAAC,MAAS,IAAA,MAAM,UAAU,MAAM,YAAY;AAClD,aAAW,QAAQ,OAAO;AAGlB,UAAA,EAAC,iBAAgB,MAAM,UAAU,MAAM,mBAAmB,KAAK,EAAE;AAEvE,eAAW,QAAQ;AACjB,kBAAY,KAAK;AAAA,QACf;AAAA,QACA;AAAA,QACA,OAAO,KAAK;AAAA,MAAA,CACb;AAAA,EAAA;AAGE,SAAA;AACT;AAGO,MAAM,mBAAmB,CAAC,SACxB,cAAc,MAAM,mBAAmB,IAAI,CAAC,GCbxC,iBAAiB,aAAmC,CAAC,aACzD;AAAA,EACL,MAAM;AAAA,EACN,SAAS;AAAA,IACP,UAAU;AAAA,MACR,YAAY;AAAA,MACZ,QAAQ,YAEO,OADA,MAAM,MAAM,QAAQ,GAAG,GACZ,KAAK;AAAA,MAG/B,mBAAmB;AAAA;AAAA,QAEjB,cAAc,CAAC,WAAW,OAAO,MAAM;AAAA,MAAA;AAAA,IAE1C,CAAA;AAAA,EAAA;AAEL,EACD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/form-toolkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Tool kit for integrating forms with a Sanity Studio",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -19,15 +19,45 @@
|
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"type": "commonjs",
|
|
21
21
|
"exports": {
|
|
22
|
-
"
|
|
23
|
-
"source": "./src/index.ts",
|
|
24
|
-
"import": "./dist/index.mjs",
|
|
25
|
-
"default": "./dist/index.js"
|
|
22
|
+
"./formium": {
|
|
23
|
+
"source": "./src/formium/index.ts",
|
|
24
|
+
"import": "./dist/formium/index.mjs",
|
|
25
|
+
"default": "./dist/formium/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./hubspot": {
|
|
28
|
+
"source": "./src/hubspot/index.ts",
|
|
29
|
+
"import": "./dist/hubspot/index.mjs",
|
|
30
|
+
"default": "./dist/hubspot/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./mailchimp": {
|
|
33
|
+
"source": "./src/mailchimp/index.ts",
|
|
34
|
+
"import": "./dist/mailchimp/index.mjs",
|
|
35
|
+
"default": "./dist/mailchimp/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./form-schema": {
|
|
38
|
+
"source": "./src/form-schema/index.ts",
|
|
39
|
+
"import": "./dist/form-schema/index.mjs",
|
|
40
|
+
"default": "./dist/form-schema/index.js"
|
|
26
41
|
},
|
|
27
42
|
"./package.json": "./package.json"
|
|
28
43
|
},
|
|
29
44
|
"main": "./dist/index.js",
|
|
30
|
-
"
|
|
45
|
+
"typesVersions": {
|
|
46
|
+
"*": {
|
|
47
|
+
"formium": [
|
|
48
|
+
"./dist/formium/index.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"hubspot": [
|
|
51
|
+
"./dist/hubspot/index.d.ts"
|
|
52
|
+
],
|
|
53
|
+
"mailchimp": [
|
|
54
|
+
"./dist/mailchimp/index.d.ts"
|
|
55
|
+
],
|
|
56
|
+
"form-schema": [
|
|
57
|
+
"./dist/form-schema/index.d.ts"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
31
61
|
"files": [
|
|
32
62
|
"dist",
|
|
33
63
|
"sanity.json",
|
|
@@ -82,7 +112,7 @@
|
|
|
82
112
|
"typescript": "^5.7.2"
|
|
83
113
|
},
|
|
84
114
|
"peerDependencies": {
|
|
85
|
-
"react": "^18",
|
|
115
|
+
"react": "^18 || ^19",
|
|
86
116
|
"sanity": "^3"
|
|
87
117
|
},
|
|
88
118
|
"engines": {
|
|
@@ -4,7 +4,7 @@ import {DefaultField} from './default-field'
|
|
|
4
4
|
import type {FieldComponentProps, FieldState, FormDataProps, FormField} from './types'
|
|
5
5
|
|
|
6
6
|
interface FormRendererProps extends HTMLProps<HTMLFormElement> {
|
|
7
|
-
formData
|
|
7
|
+
formData?: FormDataProps
|
|
8
8
|
// Function to get field state for a given field name
|
|
9
9
|
getFieldState?: (fieldName: string) => FieldState
|
|
10
10
|
// Function to get field error for a given field name
|
|
@@ -36,10 +36,15 @@ export const FormRenderer: FC<FormRendererProps> = (props) => {
|
|
|
36
36
|
|
|
37
37
|
return <DefaultField field={field} fieldState={fieldState} error={error} />
|
|
38
38
|
}
|
|
39
|
+
const elProps = Object.assign({}, props)
|
|
40
|
+
delete elProps.formData
|
|
41
|
+
delete elProps.getFieldState
|
|
42
|
+
delete elProps.getFieldError
|
|
43
|
+
delete elProps.fieldComponents
|
|
39
44
|
|
|
40
45
|
return (
|
|
41
|
-
<form {...
|
|
42
|
-
{formData
|
|
46
|
+
<form {...elProps} id={elProps.id ?? formData?.id?.current}>
|
|
47
|
+
{formData?.fields?.map((field) => (
|
|
43
48
|
<div key={field._key} className="form-field">
|
|
44
49
|
{renderField(field)}
|
|
45
50
|
</div>
|
|
@@ -47,7 +52,7 @@ export const FormRenderer: FC<FormRendererProps> = (props) => {
|
|
|
47
52
|
|
|
48
53
|
{children}
|
|
49
54
|
|
|
50
|
-
<button type="submit">{formData
|
|
55
|
+
<button type="submit">{formData?.submitButton?.text || 'Submit'}</button>
|
|
51
56
|
</form>
|
|
52
57
|
)
|
|
53
58
|
}
|
package/src/form-schema/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {definePlugin} from 'sanity'
|
|
2
|
-
// import {structureTool} from 'sanity/structure'
|
|
3
2
|
|
|
3
|
+
// import {structureTool} from 'sanity/structure'
|
|
4
4
|
import {FormRenderer} from './components/form-renderer'
|
|
5
5
|
import {schema} from './schema-types'
|
|
6
6
|
// import {defaultDocumentNode} from './structure'
|
|
@@ -18,6 +18,7 @@ import {schema} from './schema-types'
|
|
|
18
18
|
* })
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
+
export type {FormDataProps} from './components/types'
|
|
21
22
|
export {FormRenderer}
|
|
22
23
|
export const formSchema = definePlugin(() => {
|
|
23
24
|
return {
|
package/src/hubspot/index.ts
CHANGED
|
@@ -2,7 +2,8 @@ import {asyncList} from '@sanity/sanity-plugin-async-list'
|
|
|
2
2
|
import {definePlugin} from 'sanity'
|
|
3
3
|
|
|
4
4
|
import {Option} from './components/option'
|
|
5
|
-
|
|
5
|
+
import {hubSpotHandler} from './create-handler'
|
|
6
|
+
import {fetchHubSpotData} from './fetch-hubspot-data'
|
|
6
7
|
interface HubSpotInputConfig {
|
|
7
8
|
url: string | URL
|
|
8
9
|
}
|
|
@@ -12,7 +13,7 @@ interface HubSpotInputConfig {
|
|
|
12
13
|
*
|
|
13
14
|
* ```ts
|
|
14
15
|
* import {defineConfig} from 'sanity'
|
|
15
|
-
* import {hubSpotInput} from '@sanity/
|
|
16
|
+
* import {hubSpotInput} from '@sanity/form-toolkit/hubspot'
|
|
16
17
|
*
|
|
17
18
|
* export default defineConfig({
|
|
18
19
|
* // ...
|
|
@@ -24,8 +25,9 @@ interface HubSpotInputConfig {
|
|
|
24
25
|
* })
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
|
-
type ExtendedOption = {value: string; name: string}
|
|
28
28
|
|
|
29
|
+
type ExtendedOption = {value: string; name: string}
|
|
30
|
+
export {fetchHubSpotData, hubSpotHandler}
|
|
29
31
|
export const hubSpotInput = definePlugin<HubSpotInputConfig>((options) => {
|
|
30
32
|
return {
|
|
31
33
|
name: 'sanity-plugin-form-toolkit_hubspot-input',
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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'
|
|
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
8
|
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
9
|
+
// export {
|
|
10
|
+
// fetchHubSpotData,
|
|
11
|
+
// fetchMailchimpData,
|
|
12
|
+
// type FormDataProps,
|
|
13
|
+
// FormRenderer,
|
|
14
|
+
// formSchema,
|
|
15
|
+
// hubSpotHandler,
|
|
16
|
+
// hubSpotInput,
|
|
17
|
+
// mailchimpHandler,
|
|
18
|
+
// mailchimpInput,
|
|
19
|
+
// }
|
package/src/mailchimp/index.ts
CHANGED
|
@@ -2,7 +2,8 @@ import {asyncList} from '@sanity/sanity-plugin-async-list'
|
|
|
2
2
|
import {definePlugin} from 'sanity'
|
|
3
3
|
|
|
4
4
|
import {Option} from './components/option'
|
|
5
|
-
|
|
5
|
+
import {mailchimpHandler} from './create-handler'
|
|
6
|
+
import {fetchMailchimpData} from './create-handler'
|
|
6
7
|
interface MailchimpInputConfig {
|
|
7
8
|
url: string | URL
|
|
8
9
|
}
|
|
@@ -12,15 +13,15 @@ interface MailchimpInputConfig {
|
|
|
12
13
|
*
|
|
13
14
|
* ```ts
|
|
14
15
|
* import {defineConfig} from 'sanity'
|
|
15
|
-
* import {
|
|
16
|
+
* import {mailchimpInput} from '@sanity/form-toolkit/mailchimp'
|
|
16
17
|
*
|
|
17
18
|
* export default defineConfig({
|
|
18
19
|
* // ...
|
|
19
|
-
* plugins: [
|
|
20
|
+
* plugins: [mailchimpInput()],
|
|
20
21
|
* })
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
export {fetchMailchimpData, mailchimpHandler}
|
|
24
25
|
export const mailchimpInput = definePlugin<MailchimpInputConfig>((options) => {
|
|
25
26
|
return {
|
|
26
27
|
name: 'sanity-plugin-form-toolkit_mailchimp-input',
|
package/dist/index.d.mts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import type {ComponentType} from 'react'
|
|
2
|
-
import {EventHandler} from 'h3'
|
|
3
|
-
import {EventHandlerRequest} from 'h3'
|
|
4
|
-
import type {FC} from 'react'
|
|
5
|
-
import type {HTMLProps} from 'react'
|
|
6
|
-
import {IncomingMessage} from 'http'
|
|
7
|
-
import {Plugin as Plugin_2} from 'sanity'
|
|
8
|
-
import {ServerResponse} from 'http'
|
|
9
|
-
|
|
10
|
-
export declare function fetchHubSpotData({token}: {token: string}): Promise<MappedResult[] | null>
|
|
11
|
-
|
|
12
|
-
export declare function fetchMailchimpData({
|
|
13
|
-
key,
|
|
14
|
-
server,
|
|
15
|
-
}: {
|
|
16
|
-
key: string
|
|
17
|
-
server: string
|
|
18
|
-
}): Promise<unknown>
|
|
19
|
-
|
|
20
|
-
declare type FieldChoice = {
|
|
21
|
-
label: string
|
|
22
|
-
value: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare interface FieldComponentProps {
|
|
26
|
-
field: FormField
|
|
27
|
-
fieldState: FieldState
|
|
28
|
-
error?: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
declare type FieldOptions = {
|
|
32
|
-
placeholder?: string
|
|
33
|
-
defaultValue?: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
declare interface FieldState {
|
|
37
|
-
value?: string | number | readonly string[]
|
|
38
|
-
onChange: (value: unknown) => void
|
|
39
|
-
onBlur?: () => void
|
|
40
|
-
ref?: unknown
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export declare type FormDataProps = {
|
|
44
|
-
title: string
|
|
45
|
-
id: {
|
|
46
|
-
current: string
|
|
47
|
-
}
|
|
48
|
-
fields?: FormField[]
|
|
49
|
-
submitButton?: {
|
|
50
|
-
text: string
|
|
51
|
-
position: 'left' | 'center' | 'right'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
declare type FormField = {
|
|
56
|
-
type: string
|
|
57
|
-
label?: string
|
|
58
|
-
name: string
|
|
59
|
-
required: boolean
|
|
60
|
-
validation?: ValidationRule[]
|
|
61
|
-
options?: FieldOptions
|
|
62
|
-
choices?: FieldChoice[]
|
|
63
|
-
_key: string
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export declare const FormRenderer: FC<FormRendererProps>
|
|
67
|
-
|
|
68
|
-
declare interface FormRendererProps extends HTMLProps<HTMLFormElement> {
|
|
69
|
-
formData: FormDataProps
|
|
70
|
-
getFieldState?: (fieldName: string) => FieldState
|
|
71
|
-
getFieldError?: (fieldName: string) => string | undefined
|
|
72
|
-
fieldComponents?: Record<string, ComponentType<FieldComponentProps>>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export declare const formSchema: Plugin_2<void>
|
|
76
|
-
|
|
77
|
-
declare type HubSpotForm = {
|
|
78
|
-
id: string
|
|
79
|
-
name: string
|
|
80
|
-
[key: string]: unknown
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export declare const hubSpotHandler: ({token}: {token: string}) =>
|
|
84
|
-
| ((req: IncomingMessage, res: ServerResponse) => Promise<void>)
|
|
85
|
-
| EventHandler<EventHandlerRequest, Promise<unknown>>
|
|
86
|
-
| {
|
|
87
|
-
GET: ({request}: {request: Request}) => Promise<Response>
|
|
88
|
-
loader?: undefined
|
|
89
|
-
get?: undefined
|
|
90
|
-
}
|
|
91
|
-
| {
|
|
92
|
-
loader: ({request}: {request: Request}) => Promise<Response>
|
|
93
|
-
GET?: undefined
|
|
94
|
-
get?: undefined
|
|
95
|
-
}
|
|
96
|
-
| {
|
|
97
|
-
get: ({request}: {request: Request}) => Promise<{
|
|
98
|
-
body: string
|
|
99
|
-
headers: {
|
|
100
|
-
'Content-Type': string
|
|
101
|
-
}
|
|
102
|
-
}>
|
|
103
|
-
GET?: undefined
|
|
104
|
-
loader?: undefined
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export declare const hubSpotInput: Plugin_2<HubSpotInputConfig>
|
|
108
|
-
|
|
109
|
-
declare interface HubSpotInputConfig {
|
|
110
|
-
url: string | URL
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export declare const mailchimpHandler: (keys: {key: string; server: string}) =>
|
|
114
|
-
| ((req: IncomingMessage, res: ServerResponse) => Promise<void>)
|
|
115
|
-
| EventHandler<EventHandlerRequest, Promise<unknown>>
|
|
116
|
-
| {
|
|
117
|
-
GET: ({request}: {request: Request}) => Promise<Response>
|
|
118
|
-
loader?: undefined
|
|
119
|
-
get?: undefined
|
|
120
|
-
}
|
|
121
|
-
| {
|
|
122
|
-
loader: ({request}: {request: Request}) => Promise<Response>
|
|
123
|
-
GET?: undefined
|
|
124
|
-
get?: undefined
|
|
125
|
-
}
|
|
126
|
-
| {
|
|
127
|
-
get: ({request}: {request: Request}) => Promise<{
|
|
128
|
-
body: string
|
|
129
|
-
headers: {
|
|
130
|
-
'Content-Type': string
|
|
131
|
-
}
|
|
132
|
-
}>
|
|
133
|
-
GET?: undefined
|
|
134
|
-
loader?: undefined
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Usage in `sanity.config.ts` (or .js)
|
|
139
|
-
*
|
|
140
|
-
* ```ts
|
|
141
|
-
* import {defineConfig} from 'sanity'
|
|
142
|
-
* import {formiumInput} from 'sanity-plugin-form-toolkit'
|
|
143
|
-
*
|
|
144
|
-
* export default defineConfig({
|
|
145
|
-
* // ...
|
|
146
|
-
* plugins: [formiumInput()],
|
|
147
|
-
* })
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
export declare const mailchimpInput: Plugin_2<MailchimpInputConfig>
|
|
151
|
-
|
|
152
|
-
declare interface MailchimpInputConfig {
|
|
153
|
-
url: string | URL
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
declare type MappedResult = HubSpotForm & {
|
|
157
|
-
value: string
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
declare type ValidationRule = {
|
|
161
|
-
type: string
|
|
162
|
-
value: string
|
|
163
|
-
message: string
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export {}
|