From d995cc6a37b2d48ce8aae8f40c6f12a8bc38d67f Mon Sep 17 00:00:00 2001 From: mitchellhamilton Date: Mon, 7 Feb 2022 11:11:43 +1000 Subject: [PATCH 001/124] WIP --- .../component-views/package.json | 4 ++ packages/fields-document/package.json | 8 ++- .../DocumentEditor/component-blocks/api.tsx | 61 +++++++++++++++++-- .../src/component-views/index.tsx | 0 packages/fields-document/src/component.ts | 59 ++++++++++++++++++ 5 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 packages/fields-document/component-views/package.json create mode 100644 packages/fields-document/src/component-views/index.tsx create mode 100644 packages/fields-document/src/component.ts diff --git a/packages/fields-document/component-views/package.json b/packages/fields-document/component-views/package.json new file mode 100644 index 00000000000..d7f7318638e --- /dev/null +++ b/packages/fields-document/component-views/package.json @@ -0,0 +1,4 @@ +{ + "main": "dist/keystone-6-fields-document-component-views.cjs.js", + "module": "dist/keystone-6-fields-document-component-views.esm.js" +} diff --git a/packages/fields-document/package.json b/packages/fields-document/package.json index d41ac90050a..4c3f4dc1653 100644 --- a/packages/fields-document/package.json +++ b/packages/fields-document/package.json @@ -9,14 +9,16 @@ "dist", "component-blocks", "primitives", - "views" + "views", + "component-views" ], "preconstruct": { "entrypoints": [ "component-blocks.tsx", "index.ts", "primitives.ts", - "views.tsx" + "views.tsx", + "component-views/index.tsx" ] }, "peerDependencies": { @@ -66,4 +68,4 @@ "engines": { "node": "^14.15 || ^16.13" } -} +} \ No newline at end of file diff --git a/packages/fields-document/src/DocumentEditor/component-blocks/api.tsx b/packages/fields-document/src/DocumentEditor/component-blocks/api.tsx index ec6477829e5..a1948efd517 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, @@ -44,6 +45,19 @@ export type FormField = { validate(value: unknown): boolean; }; +export type FormFieldWithGraphQLField = FormField & { + graphql: { + output: graphql.Field< + { value: Value }, + Record>, + graphql.OutputType, + 'value' + >; + selection: (fieldKey: string) => string; + input: graphql.Arg; + }; +}; + type InlineMarksConfig = | 'inherit' | { @@ -131,7 +145,7 @@ export const fields = { }: { label: string; defaultValue?: string; - }): FormField { + }): FormFieldWithGraphQLField { return { kind: 'form', Input({ value, onChange, autoFocus }) { @@ -153,6 +167,11 @@ export const fields = { validate(value) { return typeof value === 'string'; }, + graphql: { + input: graphql.arg({ type: graphql.String }), + output: graphql.field({ type: graphql.String }), + selection: x => x, + }, }; }, url({ @@ -161,7 +180,7 @@ export const fields = { }: { label: string; defaultValue?: string; - }): FormField { + }): FormFieldWithGraphQLField { const validate = (value: unknown) => { return typeof value === 'string' && (value === '' || isValidURL(value)); }; @@ -190,6 +209,11 @@ export const fields = { options: undefined, defaultValue, validate, + graphql: { + input: graphql.arg({ type: graphql.String }), + output: graphql.field({ type: graphql.String }), + selection: x => x, + }, }; }, select