gatsby-source-prismic
Version:
Gatsby source plugin for building websites using Prismic as a data source
1 lines • 4.34 kB
Source Map (JSON)
{"version":3,"file":"buildGatsbyImageDataFieldConfig.cjs","sources":["../../../src/lib/buildGatsbyImageDataFieldConfig.ts"],"sourcesContent":["import { ImageFieldImage, isFilled } from \"@prismicio/client\";\nimport type { GatsbyCache } from \"gatsby\";\nimport { getGatsbyImageFieldConfig } from \"gatsby-plugin-image/graphql-utils\";\nimport type { ObjectTypeComposerFieldConfigAsObjectDefinition } from \"graphql-compose\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport {\n\tDEFAULT_IMGIX_PARAMS,\n\tGatsbyImageDataPlaceholderKind,\n} from \"../constants\";\n\nimport {\n\tGatsbyImageDataArgs,\n\tresolveGatsbyImageData,\n} from \"./resolveGatsbyImageData.server\";\n\nexport type BuildGatsbyImageDataFieldConfigConfig = {\n\tcache: GatsbyCache;\n\tpluginOptions: PluginOptions;\n};\n\nexport const buildGatsbyImageDataFieldConfig = <TContext>(\n\tconfig: BuildGatsbyImageDataFieldConfigConfig,\n): ObjectTypeComposerFieldConfigAsObjectDefinition<\n\tImageFieldImage,\n\tTContext,\n\tGatsbyImageDataArgs\n> => {\n\tconst fieldConfig = getGatsbyImageFieldConfig<\n\t\tImageFieldImage,\n\t\tTContext,\n\t\tGatsbyImageDataArgs\n\t>(async (source, args) => {\n\t\tif (isFilled.imageThumbnail(source)) {\n\t\t\treturn resolveGatsbyImageData(\n\t\t\t\t{\n\t\t\t\t\turl: source.url,\n\t\t\t\t\twidth: source.dimensions.width,\n\t\t\t\t\theight: source.dimensions.height,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t...args,\n\t\t\t\t\timgixParams: {\n\t\t\t\t\t\t...DEFAULT_IMGIX_PARAMS,\n\t\t\t\t\t\t...config.pluginOptions.imageImgixParams,\n\t\t\t\t\t\t...args.imgixParams,\n\t\t\t\t\t},\n\t\t\t\t\tplaceholderImgixParams: {\n\t\t\t\t\t\t...DEFAULT_IMGIX_PARAMS,\n\t\t\t\t\t\t...config.pluginOptions.imageImgixParams,\n\t\t\t\t\t\t...config.pluginOptions.imagePlaceholderImgixParams,\n\t\t\t\t\t\t...args.placeholderImgixParams,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcache: config.cache,\n\t\t\t\t\tpluginName: \"gatsby-source-prismic\",\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}) as ObjectTypeComposerFieldConfigAsObjectDefinition<\n\t\tImageFieldImage,\n\t\tTContext,\n\t\tGatsbyImageDataArgs\n\t>;\n\n\t// We need to set this separately since the above type cast raises the field\n\t// config to a graphql-compose definition. This allows us to reference types\n\t// by name, which is needed for the arguments.\n\tfieldConfig.args = {\n\t\t...(fieldConfig.args as NonNullable<typeof fieldConfig.args>),\n\t\tplaceholder: {\n\t\t\ttype: \"PrismicGatsbyImageDataPlaceholder\",\n\t\t\tdefaultValue: GatsbyImageDataPlaceholderKind.DominantColor,\n\t\t},\n\t\timgixParams: {\n\t\t\ttype: \"PrismicImgixURLParams\",\n\t\t},\n\t\tplaceholderImgixParams: {\n\t\t\ttype: \"PrismicImgixURLParams\",\n\t\t},\n\t};\n\n\t// @ts-expect-error - outputPixelDensities is not supported in\n\t// `gatsby-source-prismic` since it is not natively supported in\n\t// `gatsby-plugin-image`'s `generateImageData()` function.\n\t//\n\t// If you are familiar with `outputPixelDensities` and would like to\n\t// implement it, please submit a PR!\n\tdelete fieldConfig.args.outputPixelDensities;\n\n\t// `getGatsbyImageFieldConfig` returns a \"JSON!\" type. This is undesired when\n\t// the source does not contain a value (i.e. null). Here, we are manually\n\t// overriding the type to be nullable.\n\tfieldConfig.type = \"JSON\";\n\n\treturn fieldConfig;\n};\n"],"names":["getGatsbyImageFieldConfig","isFilled","resolveGatsbyImageData","DEFAULT_IMGIX_PARAMS","GatsbyImageDataPlaceholderKind"],"mappings":";;;;;;AAsBa,MAAA,kCAAkC,CAC9C,WAKG;AACH,QAAM,cAAcA,aAAAA,0BAIlB,OAAO,QAAQ,SAAQ;AACpB,QAAAC,QAAA,SAAS,eAAe,MAAM,GAAG;AACpC,aAAOC,qDACN;AAAA,QACC,KAAK,OAAO;AAAA,QACZ,OAAO,OAAO,WAAW;AAAA,QACzB,QAAQ,OAAO,WAAW;AAAA,MAAA,GAE3B;AAAA,QACC,GAAG;AAAA,QACH,aAAa;AAAA,UACZ,GAAGC,UAAA;AAAA,UACH,GAAG,OAAO,cAAc;AAAA,UACxB,GAAG,KAAK;AAAA,QACR;AAAA,QACD,wBAAwB;AAAA,UACvB,GAAGA,UAAA;AAAA,UACH,GAAG,OAAO,cAAc;AAAA,UACxB,GAAG,OAAO,cAAc;AAAA,UACxB,GAAG,KAAK;AAAA,QACR;AAAA,MAAA,GAEF;AAAA,QACC,OAAO,OAAO;AAAA,QACd,YAAY;AAAA,MAAA,CACZ;AAAA,IAAA,OAEI;AACC,aAAA;AAAA,IACP;AAAA,EAAA,CACD;AASD,cAAY,OAAO;AAAA,IAClB,GAAI,YAAY;AAAA,IAChB,aAAa;AAAA,MACZ,MAAM;AAAA,MACN,cAAcC,UAA+B,+BAAA;AAAA,IAC7C;AAAA,IACD,aAAa;AAAA,MACZ,MAAM;AAAA,IACN;AAAA,IACD,wBAAwB;AAAA,MACvB,MAAM;AAAA,IACN;AAAA,EAAA;AASF,SAAO,YAAY,KAAK;AAKxB,cAAY,OAAO;AAEZ,SAAA;AACR;;"}