diff --git a/packages/fields-document/form/package.json b/packages/fields-document/form/package.json new file mode 100644 index 00000000000..93c74c9368b --- /dev/null +++ b/packages/fields-document/form/package.json @@ -0,0 +1,4 @@ +{ + "main": "dist/keystone-6-fields-document-form.cjs.js", + "module": "dist/keystone-6-fields-document-form.esm.js" +} diff --git a/packages/fields-document/package.json b/packages/fields-document/package.json index ef153dd4c8f..fff55694f8c 100644 --- a/packages/fields-document/package.json +++ b/packages/fields-document/package.json @@ -9,14 +9,16 @@ "dist", "component-blocks", "primitives", - "views" + "views", + "structure-views", ], "preconstruct": { "entrypoints": [ "component-blocks.tsx", "index.ts", "primitives.ts", - "views.tsx" + "views.tsx", + "structure-views.tsx" ] }, "peerDependencies": { @@ -34,6 +36,7 @@ "@keystone-ui/core": "^5.0.1", "@keystone-ui/fields": "^7.1.1", "@keystone-ui/icons": "^6.0.1", + "@keystone-ui/modals": "^6.0.1", "@keystone-ui/popover": "^6.0.1", "@keystone-ui/tooltip": "^6.0.1", "@types/react": "^18.0.9", diff --git a/packages/fields-document/src/DocumentEditor/component-blocks/api.tsx b/packages/fields-document/src/DocumentEditor/component-blocks/api.tsx index df745b3c403..a73f8a867ea 100644 --- a/packages/fields-document/src/DocumentEditor/component-blocks/api.tsx +++ b/packages/fields-document/src/DocumentEditor/component-blocks/api.tsx @@ -1,5 +1,6 @@ /** @jsxRuntime classic */ /** @jsx jsx */ +import { graphql } from '@keystone-6/core'; import { jsx } from '@keystone-ui/core'; import { FieldContainer, @@ -52,6 +53,21 @@ export type FormField = { validate(value: unknown): boolean; }; +export type FormFieldWithGraphQLField = FormField< + Value, + Options +> & { + graphql: { + output: graphql.Field< + { value: Value }, + Record>, + graphql.OutputType, + 'value' + >; + input: graphql.NullableInputType; + }; +}; + type InlineMarksConfig = | 'inherit' | { @@ -137,6 +153,17 @@ export type ComponentSchema = // this is written like this rather than ArrayField to avoid TypeScript erroring about circularity | { kind: 'array'; element: ComponentSchema }; +export type ComponentSchemaForGraphQL = + | FormFieldWithGraphQLField + | ObjectField> + | ConditionalField< + FormFieldWithGraphQLField, + { [key: string]: ComponentSchemaForGraphQL } + > + | RelationshipField + // this is written like this rather than ArrayField to avoid TypeScript erroring about circularity + | { kind: 'array'; element: ComponentSchemaForGraphQL }; + export const fields = { text({ label, @@ -144,7 +171,7 @@ export const fields = { }: { label: string; defaultValue?: string; - }): FormField { + }): FormFieldWithGraphQLField { return { kind: 'form', Input({ value, onChange, autoFocus }) { @@ -166,6 +193,10 @@ export const fields = { validate(value) { return typeof value === 'string'; }, + graphql: { + input: graphql.String, + output: graphql.field({ type: graphql.String }), + }, }; }, url({ @@ -174,7 +205,7 @@ export const fields = { }: { label: string; defaultValue?: string; - }): FormField { + }): FormFieldWithGraphQLField { const validate = (value: unknown) => { return typeof value === 'string' && (value === '' || isValidURL(value)); }; @@ -203,6 +234,10 @@ export const fields = { options: undefined, defaultValue, validate, + graphql: { + input: graphql.String, + output: graphql.field({ type: graphql.String }), + }, }; }, select