@prismicio/client 7.21.0-alpha.1 → 7.21.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/dist/Client.cjs +120 -132
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.ts +7 -7
- package/dist/Client.js +120 -132
- package/dist/Client.js.map +1 -1
- package/dist/Migration.cjs +83 -101
- package/dist/Migration.cjs.map +1 -1
- package/dist/Migration.d.ts +9 -9
- package/dist/Migration.js +83 -101
- package/dist/Migration.js.map +1 -1
- package/dist/WriteClient.cjs +113 -98
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.ts +6 -6
- package/dist/WriteClient.js +113 -98
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +29 -21
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +13 -10
- package/dist/createClient.js.map +1 -1
- package/dist/createMigration.cjs.map +1 -1
- package/dist/createMigration.d.ts +2 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createWriteClient.cjs.map +1 -1
- package/dist/createWriteClient.d.ts +2 -2
- package/dist/errors/ForbiddenError.d.ts +1 -1
- package/dist/errors/InvalidDataError.d.ts +1 -1
- package/dist/errors/NotFoundError.d.ts +1 -1
- package/dist/errors/ParsingError.d.ts +1 -1
- package/dist/errors/PreviewTokenExpired.d.ts +1 -1
- package/dist/errors/PrismicError.cjs +2 -5
- package/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/errors/PrismicError.js +2 -5
- package/dist/errors/PrismicError.js.map +1 -1
- package/dist/errors/RefExpiredError.d.ts +1 -1
- package/dist/errors/RefNotFoundError.d.ts +1 -1
- package/dist/errors/RepositoryNotFoundError.d.ts +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +9 -2
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +13 -6
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs +22 -22
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +37 -29
- package/dist/helpers/asHTML.js +22 -22
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +17 -16
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +12 -11
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +19 -18
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +36 -35
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +11 -14
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +21 -11
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs +1 -2
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts +2 -2
- package/dist/helpers/documentToLinkField.js +1 -2
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +35 -34
- package/dist/helpers/isFilled.js +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +11 -11
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +121 -120
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +2 -2
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/everyTagFilter.js.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +1 -1
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +1 -1
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +1 -1
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +1 -1
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
- package/dist/lib/getOptionalLinkProperties.d.ts +1 -1
- package/dist/lib/getOptionalLinkProperties.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/isMigrationValue.cjs.map +1 -1
- package/dist/lib/isMigrationValue.d.ts +8 -8
- package/dist/lib/isMigrationValue.js.map +1 -1
- package/dist/lib/isValue.cjs.map +1 -1
- package/dist/lib/isValue.d.ts +10 -10
- package/dist/lib/isValue.js.map +1 -1
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
- package/dist/lib/minifyGraphQLQuery.js.map +1 -1
- package/dist/lib/pLimit.cjs +3 -4
- package/dist/lib/pLimit.cjs.map +1 -1
- package/dist/lib/pLimit.js +3 -4
- package/dist/lib/pLimit.js.map +1 -1
- package/dist/lib/request.cjs +8 -10
- package/dist/lib/request.cjs.map +1 -1
- package/dist/lib/request.js +8 -10
- package/dist/lib/request.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs +4 -6
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.d.ts +8 -8
- package/dist/lib/resolveMigrationDocumentData.js +4 -6
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +2 -2
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +3 -3
- package/dist/lib/serializerHelpers.js +2 -2
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs.map +1 -1
- package/dist/lib/someTagsFilter.js.map +1 -1
- package/dist/lib/throttledLog.cjs.map +1 -1
- package/dist/lib/throttledLog.js.map +1 -1
- package/dist/lib/typeFilter.cjs.map +1 -1
- package/dist/lib/typeFilter.js.map +1 -1
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.d.ts +1 -1
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.ts +6 -6
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.ts +2 -2
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/index.d.ts +7 -7
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +10 -10
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +7 -7
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/api/asset/asset.d.ts +1 -1
- package/dist/types/api/integration.d.ts +1 -1
- package/dist/types/api/migration/document.d.ts +1 -1
- package/dist/types/api/query.d.ts +1 -1
- package/dist/types/api/release.d.ts +1 -1
- package/dist/types/api/repository.d.ts +1 -1
- package/dist/types/migration/Asset.cjs +12 -15
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.d.ts +7 -7
- package/dist/types/migration/Asset.js +12 -15
- package/dist/types/migration/Asset.js.map +1 -1
- package/dist/types/migration/ContentRelationship.d.ts +3 -3
- package/dist/types/migration/Document.cjs +24 -27
- package/dist/types/migration/Document.cjs.map +1 -1
- package/dist/types/migration/Document.d.ts +9 -9
- package/dist/types/migration/Document.js +24 -27
- package/dist/types/migration/Document.js.map +1 -1
- package/dist/types/migration/Link.d.ts +1 -1
- package/dist/types/model/boolean.d.ts +1 -1
- package/dist/types/model/color.d.ts +1 -1
- package/dist/types/model/contentRelationship.d.ts +3 -2
- package/dist/types/model/customType.d.ts +1 -1
- package/dist/types/model/date.d.ts +1 -1
- package/dist/types/model/embed.d.ts +1 -1
- package/dist/types/model/geoPoint.d.ts +1 -1
- package/dist/types/model/group.d.ts +1 -1
- package/dist/types/model/image.d.ts +1 -1
- package/dist/types/model/integration.d.ts +1 -1
- package/dist/types/model/keyText.d.ts +1 -1
- package/dist/types/model/link.d.ts +1 -1
- package/dist/types/model/linkToMedia.d.ts +2 -2
- package/dist/types/model/number.d.ts +1 -1
- package/dist/types/model/range.d.ts +1 -1
- package/dist/types/model/richText.d.ts +1 -1
- package/dist/types/model/select.d.ts +1 -1
- package/dist/types/model/separator.d.ts +1 -1
- package/dist/types/model/sharedSlice.d.ts +2 -2
- package/dist/types/model/sharedSliceVariation.d.ts +1 -1
- package/dist/types/model/slice.d.ts +3 -3
- package/dist/types/model/sliceZone.d.ts +2 -2
- package/dist/types/model/table.d.ts +1 -1
- package/dist/types/model/timestamp.d.ts +1 -1
- package/dist/types/model/title.d.ts +1 -1
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.d.ts +22 -23
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/model/uid.d.ts +1 -1
- package/dist/types/value/color.d.ts +1 -1
- package/dist/types/value/contentRelationship.d.ts +3 -3
- package/dist/types/value/date.d.ts +1 -1
- package/dist/types/value/document.d.ts +4 -4
- package/dist/types/value/embed.d.ts +1 -1
- package/dist/types/value/geoPoint.d.ts +1 -1
- package/dist/types/value/group.d.ts +1 -1
- package/dist/types/value/image.d.ts +1 -1
- package/dist/types/value/integration.d.ts +1 -1
- package/dist/types/value/keyText.d.ts +1 -1
- package/dist/types/value/link.d.ts +5 -5
- package/dist/types/value/linkToMedia.d.ts +2 -2
- package/dist/types/value/number.d.ts +1 -1
- package/dist/types/value/richText.d.ts +3 -3
- package/dist/types/value/select.d.ts +1 -1
- package/dist/types/value/sharedSlice.d.ts +1 -1
- package/dist/types/value/sharedSliceVariation.d.ts +1 -1
- package/dist/types/value/slice.d.ts +1 -1
- package/dist/types/value/sliceZone.d.ts +3 -3
- package/dist/types/value/table.d.ts +2 -2
- package/dist/types/value/timestamp.d.ts +2 -2
- package/dist/types/value/title.d.ts +2 -2
- package/dist/types/value/types.d.ts +18 -18
- package/dist/types/webhook/apiUpdate.d.ts +1 -1
- package/dist/types/webhook/testTrigger.d.ts +1 -1
- package/dist/types/webhook/types.d.ts +2 -2
- package/package.json +11 -11
- package/src/WriteClient.ts +21 -32
- package/src/buildQueryURL.ts +29 -21
- package/src/createClient.ts +11 -8
- package/src/getRepositoryEndpoint.ts +9 -2
- package/src/helpers/asDate.ts +11 -4
- package/src/helpers/asHTML.ts +34 -26
- package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
- package/src/helpers/asImageSrc.ts +11 -10
- package/src/helpers/asImageWidthSrcSet.ts +18 -17
- package/src/helpers/asLink.ts +33 -32
- package/src/helpers/asLinkAttrs.ts +6 -9
- package/src/helpers/asText.ts +20 -10
- package/src/helpers/isFilled.ts +15 -14
- package/src/helpers/mapSliceZone.ts +10 -10
- package/src/index.ts +3 -2
- package/src/isRepositoryEndpoint.ts +2 -2
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/serialize.ts +8 -8
- package/src/richtext/types.ts +6 -6
- package/src/types/migration/Asset.ts +10 -2
- package/src/types/model/contentRelationship.ts +1 -0
- package/src/types/model/types.ts +0 -2
package/dist/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sources":["../../src/filter.ts"],"sourcesContent":["/**\n * Formats the value of a filter element to a stringified version accepted by\n * the Prismic REST API.\n *\n * @param value - Value to format.\n *\n * @returns `value` formatted for the Prismic REST API.\n */\nconst formatValue = (\n\tvalue:\n\t\t| string\n\t\t| number\n\t\t| Date\n\t\t| unknown\n\t\t| (string | number | Date | unknown)[],\n): string => {\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map(formatValue).join(\", \")}]`\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn `\"${value}\"`\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn `${value.getTime()}`\n\t}\n\n\treturn `${value}`\n}\n\n/**\n * Creates a filter builder function for filters with a path and arguments.\n *\n * @typeParam Args - Arguments for the filter.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathWithArgsFilter = <Args extends unknown[]>(name: string) => {\n\t/**\n\t * @param path - Path to the value to be compared.\n\t */\n\tconst fn = (path: string, ...args: Args): string => {\n\t\tconst formattedArgs = args.map(formatValue).join(\", \")\n\t\tconst joiner = path && args.length ? \", \" : \"\"\n\n\t\treturn `[${name}(${path}${joiner}${formattedArgs})]`\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only a path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathFilter = (name: string) => {\n\tconst filterFn = pathWithArgsFilter(name)\n\n\t/**\n\t * @param path - Path for the filter.\n\t */\n\tconst fn = (path: string): string => {\n\t\treturn filterFn(path)\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only arguments and no\n * path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst argsFilter = <Args extends unknown[]>(name: string) => {\n\tconst filterFn = pathWithArgsFilter<Args>(name)\n\n\t/**\n\t * @param args - Arguments for the filter.\n\t */\n\tconst fn = (...args: Args): string => {\n\t\treturn filterFn(\"\", ...args)\n\t}\n\n\treturn fn\n}\n\nexport const filter = {\n\t/**\n\t * The `at` filter checks that the path matches the described value exactly.\n\t * It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#at}\n\t */\n\tat: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"at\",\n\t),\n\n\t/**\n\t * The `not` filter checks that the path doesn't match the provided value\n\t * exactly. It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#not}\n\t */\n\tnot: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"not\",\n\t),\n\n\t/**\n\t * The `any` filter takes an array of values. It works exactly the same way as\n\t * the `at` operator, but checks whether the fragment matches any of the\n\t * values in the array.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#any}\n\t */\n\tany: pathWithArgsFilter<[values: (string | number | boolean | Date)[]]>(\n\t\t\"any\",\n\t),\n\n\t/**\n\t * The `in` filter is used specifically to retrieve an array of documents by\n\t * their IDs or UIDs. This filter is much more efficient at this than the any\n\t * filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#in}\n\t */\n\tin: pathWithArgsFilter<[values: string[]]>(\"in\"),\n\n\t/**\n\t * The `fulltext` filter provides two capabilities:\n\t *\n\t * 1. Checking if a certain string is anywhere inside a document (this is what\n\t * you should use to make your project's search engine feature)\n\t * 2. Checking if the string is contained inside a specific custom type’s Rich\n\t * Text or Key Text fragment.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fulltext}\n\t */\n\tfulltext: pathWithArgsFilter<[searchTerms: string]>(\"fulltext\"),\n\n\t/**\n\t * The `has` filter checks whether a fragment has a value. It will return all\n\t * the documents of the specified type that contain a value for the specified\n\t * field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#has}\n\t */\n\thas: pathFilter(\"has\"),\n\n\t/**\n\t * The `missing` filter checks if a fragment doesn't have a value. It will\n\t * return all the documents of the specified type that do not contain a value\n\t * for the specified field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#missing}\n\t */\n\tmissing: pathFilter(\"missing\"),\n\n\t/**\n\t * The `similar` filter takes the ID of a document, and returns a list of\n\t * documents with similar content. This allows you to build an automated\n\t * content discovery feature (for example, a \"Related posts\" section).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#similar}\n\t */\n\tsimilar: argsFilter<[id: string, value: number]>(\"similar\"),\n\n\t/**\n\t * The `geopoint.near` filter checks that the value in the path is within the\n\t * radius of the given coordinates.\n\t *\n\t * This filter will only work for a geopoint field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#geopointnear}\n\t */\n\tgeopointNear:\n\t\tpathWithArgsFilter<[latitude: number, longitude: number, radius: number]>(\n\t\t\t\"geopoint.near\",\n\t\t),\n\n\t/**\n\t * The `number.lt` filter checks that the value in the number field is less\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberlessthan}\n\t */\n\tnumberLessThan: pathWithArgsFilter<[value: number]>(\"number.lt\"),\n\n\t/**\n\t * The `number.gt` filter checks that the value in the number field is greater\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numbergreaterthan}\n\t */\n\tnumberGreaterThan: pathWithArgsFilter<[value: number]>(\"number.gt\"),\n\n\t/**\n\t * The `number.inRange` filter checks that the value in the path is within the\n\t * two values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberinrange}\n\t */\n\tnumberInRange:\n\t\tpathWithArgsFilter<[lowerLimit: number, upperLimit: number]>(\n\t\t\t\"number.inRange\",\n\t\t),\n\n\t/**\n\t * The `date.after` filter checks that the value in the path is after the date\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateAfter: pathWithArgsFilter<[date: string | number | Date]>(\"date.after\"),\n\n\t/**\n\t * The `date.before` filter checks that the value in the path is before the\n\t * date value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBefore: pathWithArgsFilter<[date: string | number | Date]>(\"date.before\"),\n\n\t/**\n\t * The `date.between` filter checks that the value in the path is within the\n\t * date values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBetween:\n\t\tpathWithArgsFilter<\n\t\t\t[startDate: string | number | Date, endDate: string | number | Date]\n\t\t>(\"date.between\"),\n\n\t/**\n\t * The `date.day-of-month` filter checks that the value in the path is equal\n\t * to the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonth: pathWithArgsFilter<[day: number]>(\"date.day-of-month\"),\n\n\t/**\n\t * The `date.day-of-month-after` filter checks that the value in the path is\n\t * after the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthAfter: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-after\",\n\t),\n\n\t/**\n\t * The `date.day-of-month-before` filter checks that the value in the path is\n\t * before the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthBefore: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-before\",\n\t),\n\n\t/**\n\t * The `date.day-of-week` filter checks that the value in the path is equal to\n\t * the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeek: pathWithArgsFilter<[day: string | number]>(\"date.day-of-week\"),\n\n\t/**\n\t * The `date.day-of-week-after` filter checks that the value in the path is\n\t * after the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekAfter: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-after\",\n\t),\n\n\t/**\n\t * The date.day-of-week-before filter checks that the value in the path is\n\t * before the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekBefore: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-before\",\n\t),\n\n\t/**\n\t * The `date.month` filter checks that the value in the path occurs in the\n\t * month value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonth: pathWithArgsFilter<[month: string | number]>(\"date.month\"),\n\n\t/**\n\t * The `date.month-after` filter checks that the value in the path occurs in\n\t * any month after the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthAfter:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-after\"),\n\n\t/**\n\t * The `date.month-before` filter checks that the value in the path occurs in\n\t * any month before the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthBefore:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-before\"),\n\n\t/**\n\t * The `date.year` filter checks that the value in the path occurs in the year\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateYear: pathWithArgsFilter<[year: number]>(\"date.year\"),\n\n\t/**\n\t * The `date.hour` filter checks that the value in the path occurs within the\n\t * hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHour: pathWithArgsFilter<[hour: number]>(\"date.hour\"),\n\n\t/**\n\t * The `date.hour-after` filter checks that the value in the path occurs after\n\t * the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourAfter: pathWithArgsFilter<[hour: number]>(\"date.hour-after\"),\n\n\t/**\n\t * The `date.hour-before` filter checks that the value in the path occurs\n\t * before the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourBefore: pathWithArgsFilter<[hour: number]>(\"date.hour-before\"),\n}\n"],"names":[],"mappings":"AAQA,MAAM,cA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AA;AAAA,EAS1B,WAAW,mBAA6C,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpE,gBACC,mBAA6C,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhE,iBACC,mBAA6C,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,UAAU,mBAAmC,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxD,UAAU,mBAAmC,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxD,eAAe,mBAAmC,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnE,gBAAgB,mBAAmC,kBAAkB;;"}
|
|
1
|
+
{"version":3,"file":"filter.js","sources":["../../src/filter.ts"],"sourcesContent":["/**\n * Formats the value of a filter element to a stringified version accepted by\n * the Prismic REST API.\n *\n * @param value - Value to format.\n *\n * @returns `value` formatted for the Prismic REST API.\n */\nconst formatValue = (\n\tvalue:\n\t\t| string\n\t\t| number\n\t\t| Date\n\t\t| unknown\n\t\t| (string | number | Date | unknown)[],\n): string => {\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map(formatValue).join(\", \")}]`\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn `\"${value}\"`\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn `${value.getTime()}`\n\t}\n\n\treturn `${value}`\n}\n\n/**\n * Creates a filter builder function for filters with a path and arguments.\n *\n * @typeParam Args - Arguments for the filter.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathWithArgsFilter = <Args extends unknown[]>(name: string) => {\n\t/**\n\t * @param path - Path to the value to be compared.\n\t */\n\tconst fn = (path: string, ...args: Args): string => {\n\t\tconst formattedArgs = args.map(formatValue).join(\", \")\n\t\tconst joiner = path && args.length ? \", \" : \"\"\n\n\t\treturn `[${name}(${path}${joiner}${formattedArgs})]`\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only a path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathFilter = (name: string) => {\n\tconst filterFn = pathWithArgsFilter(name)\n\n\t/**\n\t * @param path - Path for the filter.\n\t */\n\tconst fn = (path: string): string => {\n\t\treturn filterFn(path)\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only arguments and no\n * path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst argsFilter = <Args extends unknown[]>(name: string) => {\n\tconst filterFn = pathWithArgsFilter<Args>(name)\n\n\t/**\n\t * @param args - Arguments for the filter.\n\t */\n\tconst fn = (...args: Args): string => {\n\t\treturn filterFn(\"\", ...args)\n\t}\n\n\treturn fn\n}\n\nexport const filter = {\n\t/**\n\t * The `at` filter checks that the path matches the described value exactly.\n\t * It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#at}\n\t */\n\tat: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"at\",\n\t),\n\n\t/**\n\t * The `not` filter checks that the path doesn't match the provided value\n\t * exactly. It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#not}\n\t */\n\tnot: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"not\",\n\t),\n\n\t/**\n\t * The `any` filter takes an array of values. It works exactly the same way as\n\t * the `at` operator, but checks whether the fragment matches any of the\n\t * values in the array.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#any}\n\t */\n\tany: pathWithArgsFilter<[values: (string | number | boolean | Date)[]]>(\n\t\t\"any\",\n\t),\n\n\t/**\n\t * The `in` filter is used specifically to retrieve an array of documents by\n\t * their IDs or UIDs. This filter is much more efficient at this than the any\n\t * filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#in}\n\t */\n\tin: pathWithArgsFilter<[values: string[]]>(\"in\"),\n\n\t/**\n\t * The `fulltext` filter provides two capabilities:\n\t *\n\t * 1. Checking if a certain string is anywhere inside a document (this is what\n\t * you should use to make your project's search engine feature)\n\t * 2. Checking if the string is contained inside a specific custom type’s Rich\n\t * Text or Key Text fragment.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fulltext}\n\t */\n\tfulltext: pathWithArgsFilter<[searchTerms: string]>(\"fulltext\"),\n\n\t/**\n\t * The `has` filter checks whether a fragment has a value. It will return all\n\t * the documents of the specified type that contain a value for the specified\n\t * field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#has}\n\t */\n\thas: pathFilter(\"has\"),\n\n\t/**\n\t * The `missing` filter checks if a fragment doesn't have a value. It will\n\t * return all the documents of the specified type that do not contain a value\n\t * for the specified field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#missing}\n\t */\n\tmissing: pathFilter(\"missing\"),\n\n\t/**\n\t * The `similar` filter takes the ID of a document, and returns a list of\n\t * documents with similar content. This allows you to build an automated\n\t * content discovery feature (for example, a \"Related posts\" section).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#similar}\n\t */\n\tsimilar: argsFilter<[id: string, value: number]>(\"similar\"),\n\n\t/**\n\t * The `geopoint.near` filter checks that the value in the path is within the\n\t * radius of the given coordinates.\n\t *\n\t * This filter will only work for a geopoint field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#geopointnear}\n\t */\n\tgeopointNear:\n\t\tpathWithArgsFilter<[latitude: number, longitude: number, radius: number]>(\n\t\t\t\"geopoint.near\",\n\t\t),\n\n\t/**\n\t * The `number.lt` filter checks that the value in the number field is less\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberlessthan}\n\t */\n\tnumberLessThan: pathWithArgsFilter<[value: number]>(\"number.lt\"),\n\n\t/**\n\t * The `number.gt` filter checks that the value in the number field is greater\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numbergreaterthan}\n\t */\n\tnumberGreaterThan: pathWithArgsFilter<[value: number]>(\"number.gt\"),\n\n\t/**\n\t * The `number.inRange` filter checks that the value in the path is within the\n\t * two values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberinrange}\n\t */\n\tnumberInRange:\n\t\tpathWithArgsFilter<[lowerLimit: number, upperLimit: number]>(\n\t\t\t\"number.inRange\",\n\t\t),\n\n\t/**\n\t * The `date.after` filter checks that the value in the path is after the date\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateAfter: pathWithArgsFilter<[date: string | number | Date]>(\"date.after\"),\n\n\t/**\n\t * The `date.before` filter checks that the value in the path is before the\n\t * date value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBefore: pathWithArgsFilter<[date: string | number | Date]>(\"date.before\"),\n\n\t/**\n\t * The `date.between` filter checks that the value in the path is within the\n\t * date values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBetween:\n\t\tpathWithArgsFilter<\n\t\t\t[startDate: string | number | Date, endDate: string | number | Date]\n\t\t>(\"date.between\"),\n\n\t/**\n\t * The `date.day-of-month` filter checks that the value in the path is equal\n\t * to the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonth: pathWithArgsFilter<[day: number]>(\"date.day-of-month\"),\n\n\t/**\n\t * The `date.day-of-month-after` filter checks that the value in the path is\n\t * after the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthAfter: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-after\",\n\t),\n\n\t/**\n\t * The `date.day-of-month-before` filter checks that the value in the path is\n\t * before the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthBefore: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-before\",\n\t),\n\n\t/**\n\t * The `date.day-of-week` filter checks that the value in the path is equal to\n\t * the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeek: pathWithArgsFilter<[day: string | number]>(\"date.day-of-week\"),\n\n\t/**\n\t * The `date.day-of-week-after` filter checks that the value in the path is\n\t * after the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekAfter: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-after\",\n\t),\n\n\t/**\n\t * The date.day-of-week-before filter checks that the value in the path is\n\t * before the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekBefore: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-before\",\n\t),\n\n\t/**\n\t * The `date.month` filter checks that the value in the path occurs in the\n\t * month value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonth: pathWithArgsFilter<[month: string | number]>(\"date.month\"),\n\n\t/**\n\t * The `date.month-after` filter checks that the value in the path occurs in\n\t * any month after the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthAfter:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-after\"),\n\n\t/**\n\t * The `date.month-before` filter checks that the value in the path occurs in\n\t * any month before the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthBefore:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-before\"),\n\n\t/**\n\t * The `date.year` filter checks that the value in the path occurs in the year\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateYear: pathWithArgsFilter<[year: number]>(\"date.year\"),\n\n\t/**\n\t * The `date.hour` filter checks that the value in the path occurs within the\n\t * hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHour: pathWithArgsFilter<[hour: number]>(\"date.hour\"),\n\n\t/**\n\t * The `date.hour-after` filter checks that the value in the path occurs after\n\t * the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourAfter: pathWithArgsFilter<[hour: number]>(\"date.hour-after\"),\n\n\t/**\n\t * The `date.hour-before` filter checks that the value in the path occurs\n\t * before the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourBefore: pathWithArgsFilter<[hour: number]>(\"date.hour-before\"),\n}\n"],"names":[],"mappings":"AAQA,MAAM,cAAc,CACnB,UAMW;AACX,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,IAAI,MAAM,IAAI,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,EAC7C;AAEA,MAAI,OAAO,UAAU,UAAU;AAC9B,WAAO,IAAI,KAAK;AAAA,EACjB;AAEA,MAAI,iBAAiB,MAAM;AAC1B,WAAO,GAAG,MAAM,QAAA,CAAS;AAAA,EAC1B;AAEA,SAAO,GAAG,KAAK;AAChB;AAWA,MAAM,qBAAqB,CAAyB,SAAgB;AAInE,QAAM,KAAK,CAAC,SAAiB,SAAsB;AAClD,UAAM,gBAAgB,KAAK,IAAI,WAAW,EAAE,KAAK,IAAI;AACrD,UAAM,SAAS,QAAQ,KAAK,SAAS,OAAO;AAE5C,WAAO,IAAI,IAAI,IAAI,IAAI,GAAG,MAAM,GAAG,aAAa;AAAA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["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"getGraphQLEndpoint.cjs","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAaO,MAAM,qBAAqB,CACjC,mBACuD;AACvD,MAAIA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EACjC,OAAO;AACN,UAAM,IAAIC,aAAAA,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAEX;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGraphQLEndpoint.js","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getGraphQLEndpoint.js","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAaO,MAAM,qBAAqB,CACjC,mBACuD;AACvD,MAAI,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EACjC,OAAO;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAEX;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryEndpoint.cjs","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic
|
|
1
|
+
{"version":3,"file":"getRepositoryEndpoint.cjs","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Content API endpoint.\n *\n * @example\n *\n * ```ts\n * getRepositoryEndpoint(\"my-repo\")\n * // => \"https://my-repo.cdn.prismic.io/api/v2\"\n * ```\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Content API endpoint.\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAsBO,MAAM,wBAAwB,CACpC,mBACsD;AACtD,MAAIA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EACjC,OAAO;AACN,UAAM,IAAIC,aAAAA,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAEX;AACD;;"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get a repository's Prismic
|
|
2
|
+
* Get a repository's Prismic Content API endpoint.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* getRepositoryEndpoint("my-repo")
|
|
8
|
+
* // => "https://my-repo.cdn.prismic.io/api/v2"
|
|
9
|
+
* ```
|
|
3
10
|
*
|
|
4
11
|
* @typeParam RepositoryName - Name of the Prismic repository.
|
|
5
12
|
*
|
|
6
13
|
* @param repositoryName - Name of the repository.
|
|
7
14
|
*
|
|
8
|
-
* @returns The repository's Prismic
|
|
15
|
+
* @returns The repository's Prismic Content API endpoint.
|
|
9
16
|
*
|
|
10
17
|
* @throws {@link Error} Thrown if an invalid repository name is provided.
|
|
11
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryEndpoint.js","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic
|
|
1
|
+
{"version":3,"file":"getRepositoryEndpoint.js","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Content API endpoint.\n *\n * @example\n *\n * ```ts\n * getRepositoryEndpoint(\"my-repo\")\n * // => \"https://my-repo.cdn.prismic.io/api/v2\"\n * ```\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Content API endpoint.\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,wBAAwB,CACpC,mBACsD;AACtD,MAAI,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EACjC,OAAO;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAEX;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryName.cjs","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":["PrismicError"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getRepositoryName.cjs","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":["PrismicError"],"mappings":";;;AAaO,MAAM,oBAAoB,CAAC,uBAAsC;AACvE,MAAI;AACH,UAAM,WAAW,IAAI,IAAI,kBAAkB,EAAE;AAE7C,QACC,SAAS,SAAS,YAAY;AAAA,IAC9B,SAAS,SAAS,UAAU;AAAA,IAC5B,SAAS,SAAS,YAAY,GAC7B;AACD,aAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,IAC7B;AAAA,EACD,QAAQ;AAAA,EAAC;AAET,QAAM,IAAIA,aAAAA,aACT,0DAA0D,kBAAkB,IAC5E,QACA,MAAS;AAEX;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryName.js","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"getRepositoryName.js","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":[],"mappings":";AAaO,MAAM,oBAAoB,CAAC,uBAAsC;AACvE,MAAI;AACH,UAAM,WAAW,IAAI,IAAI,kBAAkB,EAAE;AAE7C,QACC,SAAS,SAAS,YAAY;AAAA,IAC9B,SAAS,SAAS,UAAU;AAAA,IAC5B,SAAS,SAAS,YAAY,GAC7B;AACD,aAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,IAC7B;AAAA,EACD,QAAQ;AAAA,EAAC;AAET,QAAM,IAAI,aACT,0DAA0D,kBAAkB,IAC5E,QACA,MAAS;AAEX;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToolbarSrc.cjs","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"getToolbarSrc.cjs","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAqCO,MAAM,gBAAgB,CAC5B,mBACgF;AAChF,MAAIA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D,cAAc;AAAA,EAChF,OAAO;AACN,UAAM,IAAIC,aAAAA,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAEX;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToolbarSrc.js","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getToolbarSrc.js","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAqCO,MAAM,gBAAgB,CAC5B,mBACgF;AAChF,MAAI,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D,cAAc;AAAA,EAChF,OAAO;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAEX;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asDate.cjs","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"asDate.cjs","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n * Converts a date or timestamp field to a JavaScript Date object.\n *\n * @example\n *\n * ```ts\n * const date = asDate(document.data.release_date)\n * // => Date object or null\n * ```\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic.\n *\n * @returns A Date object, or `null` if the field is empty.\n *\n * @see Learn about date and timestamp fields: {@link https://prismic.io/docs/fields/date}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":";;AA0BO,MAAM,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AAC1B,WAAO;AAAA,EACR;AAGA,MAAI,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAEtE,OAAO;AAEN,WAAO,IAAI,KAAK,oBAAoB;AAAA,EACrC;AACD;;"}
|
package/dist/helpers/asDate.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import type { DateField } from "../types/value/date";
|
|
2
|
-
import type { TimestampField } from "../types/value/timestamp";
|
|
1
|
+
import type { DateField } from "../types/value/date.js";
|
|
2
|
+
import type { TimestampField } from "../types/value/timestamp.js";
|
|
3
3
|
/**
|
|
4
4
|
* The return type of `asDate()`.
|
|
5
5
|
*/
|
|
6
6
|
type AsDateReturnType<Field extends DateField | TimestampField | null | undefined> = Field extends DateField<"filled"> | TimestampField<"filled"> ? Date : null;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Converts a date or timestamp field to a JavaScript Date object.
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
10
|
+
* @example
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const date = asDate(document.data.release_date)
|
|
14
|
+
* // => Date object or null
|
|
15
|
+
* ```
|
|
13
16
|
*
|
|
14
|
-
* @
|
|
17
|
+
* @param dateOrTimestampField - A date or timestamp field from Prismic.
|
|
18
|
+
*
|
|
19
|
+
* @returns A Date object, or `null` if the field is empty.
|
|
20
|
+
*
|
|
21
|
+
* @see Learn about date and timestamp fields: {@link https://prismic.io/docs/fields/date}
|
|
15
22
|
*/
|
|
16
23
|
export declare const asDate: <Field extends DateField | TimestampField | null | undefined>(dateOrTimestampField: Field) => AsDateReturnType<Field>;
|
|
17
24
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asDate.js","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"asDate.js","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n * Converts a date or timestamp field to a JavaScript Date object.\n *\n * @example\n *\n * ```ts\n * const date = asDate(document.data.release_date)\n * // => Date object or null\n * ```\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic.\n *\n * @returns A Date object, or `null` if the field is empty.\n *\n * @see Learn about date and timestamp fields: {@link https://prismic.io/docs/fields/date}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":"AA0BO,MAAM,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AAC1B,WAAO;AAAA,EACR;AAGA,MAAI,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAEtE,OAAO;AAEN,WAAO,IAAI,KAAK,oBAAoB;AAAA,EACrC;AACD;"}
|
package/dist/helpers/asHTML.cjs
CHANGED
|
@@ -7,32 +7,32 @@ const composeSerializers = require("../richtext/composeSerializers.cjs");
|
|
|
7
7
|
const createHTMLRichTextSerializer = (linkResolver, serializer) => {
|
|
8
8
|
const useSerializerOrDefault = (nodeSerializerOrShorthand, defaultWithShorthand) => {
|
|
9
9
|
if (typeof nodeSerializerOrShorthand === "function") {
|
|
10
|
-
return (payload) => {
|
|
11
|
-
return
|
|
12
|
-
};
|
|
10
|
+
return ((payload) => {
|
|
11
|
+
return nodeSerializerOrShorthand?.(payload) || defaultWithShorthand(payload);
|
|
12
|
+
});
|
|
13
13
|
}
|
|
14
14
|
return defaultWithShorthand;
|
|
15
15
|
};
|
|
16
16
|
const mapSerializer = {
|
|
17
|
-
heading1: useSerializerOrDefault(serializer
|
|
18
|
-
heading2: useSerializerOrDefault(serializer
|
|
19
|
-
heading3: useSerializerOrDefault(serializer
|
|
20
|
-
heading4: useSerializerOrDefault(serializer
|
|
21
|
-
heading5: useSerializerOrDefault(serializer
|
|
22
|
-
heading6: useSerializerOrDefault(serializer
|
|
23
|
-
paragraph: useSerializerOrDefault(serializer
|
|
24
|
-
preformatted: useSerializerOrDefault(serializer
|
|
25
|
-
strong: useSerializerOrDefault(serializer
|
|
26
|
-
em: useSerializerOrDefault(serializer
|
|
27
|
-
listItem: useSerializerOrDefault(serializer
|
|
28
|
-
oListItem: useSerializerOrDefault(serializer
|
|
29
|
-
list: useSerializerOrDefault(serializer
|
|
30
|
-
oList: useSerializerOrDefault(serializer
|
|
31
|
-
image: useSerializerOrDefault(serializer
|
|
32
|
-
embed: useSerializerOrDefault(serializer
|
|
33
|
-
hyperlink: useSerializerOrDefault(serializer
|
|
34
|
-
label: useSerializerOrDefault(serializer
|
|
35
|
-
span: useSerializerOrDefault(serializer
|
|
17
|
+
heading1: useSerializerOrDefault(serializer?.heading1, serializerHelpers.serializeStandardTag("h1", serializer?.heading1)),
|
|
18
|
+
heading2: useSerializerOrDefault(serializer?.heading2, serializerHelpers.serializeStandardTag("h2", serializer?.heading2)),
|
|
19
|
+
heading3: useSerializerOrDefault(serializer?.heading3, serializerHelpers.serializeStandardTag("h3", serializer?.heading3)),
|
|
20
|
+
heading4: useSerializerOrDefault(serializer?.heading4, serializerHelpers.serializeStandardTag("h4", serializer?.heading4)),
|
|
21
|
+
heading5: useSerializerOrDefault(serializer?.heading5, serializerHelpers.serializeStandardTag("h5", serializer?.heading5)),
|
|
22
|
+
heading6: useSerializerOrDefault(serializer?.heading6, serializerHelpers.serializeStandardTag("h6", serializer?.heading6)),
|
|
23
|
+
paragraph: useSerializerOrDefault(serializer?.paragraph, serializerHelpers.serializeStandardTag("p", serializer?.paragraph)),
|
|
24
|
+
preformatted: useSerializerOrDefault(serializer?.preformatted, serializerHelpers.serializePreFormatted(serializer?.preformatted)),
|
|
25
|
+
strong: useSerializerOrDefault(serializer?.strong, serializerHelpers.serializeStandardTag("strong", serializer?.strong)),
|
|
26
|
+
em: useSerializerOrDefault(serializer?.em, serializerHelpers.serializeStandardTag("em", serializer?.em)),
|
|
27
|
+
listItem: useSerializerOrDefault(serializer?.listItem, serializerHelpers.serializeStandardTag("li", serializer?.listItem)),
|
|
28
|
+
oListItem: useSerializerOrDefault(serializer?.oListItem, serializerHelpers.serializeStandardTag("li", serializer?.oListItem)),
|
|
29
|
+
list: useSerializerOrDefault(serializer?.list, serializerHelpers.serializeStandardTag("ul", serializer?.list)),
|
|
30
|
+
oList: useSerializerOrDefault(serializer?.oList, serializerHelpers.serializeStandardTag("ol", serializer?.oList)),
|
|
31
|
+
image: useSerializerOrDefault(serializer?.image, serializerHelpers.serializeImage(linkResolver, serializer?.image)),
|
|
32
|
+
embed: useSerializerOrDefault(serializer?.embed, serializerHelpers.serializeEmbed(serializer?.embed)),
|
|
33
|
+
hyperlink: useSerializerOrDefault(serializer?.hyperlink, serializerHelpers.serializeHyperlink(linkResolver, serializer?.hyperlink)),
|
|
34
|
+
label: useSerializerOrDefault(serializer?.label, serializerHelpers.serializeStandardTag("span", serializer?.label)),
|
|
35
|
+
span: useSerializerOrDefault(serializer?.span, serializerHelpers.serializeSpan())
|
|
36
36
|
};
|
|
37
37
|
return wrapMapSerializerWithStringChildren(mapSerializer);
|
|
38
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asHTML.cjs","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text or title field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text or title field with a map or a function to\n * HTML\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it you're\n\t * expected to use the `routes` options from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer, unhandled cases will fallback to the\n\t * default serializer\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param config - Configuration that determines the output of `asHTML()`\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param linkResolver - An optional link resolver function to resolve links,\n\t * without it you're expected to use the `routes` options from the API\n\t * @param serializer - An optional rich text serializer, unhandled cases will\n\t * fallback to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":["serializeStandardTag","serializePreFormatted","serializeImage","serializeEmbed","serializeHyperlink","serializeSpan","wrapMapSerializer","composeSerializers","serialize"],"mappings":";;;;;;AAyJA,MAAM,+BAA+B,CACpC,cACA,eACuC;AACjC,QAAA,yBAAyB,CAG9B,2BACA,yBAG4D;AACxD,QAAA,OAAO,8BAA8B,YAAY;AACpD,aAAQ,CAAC,YAAW;AACnB,gBAEE,uEACG,aAAY,qBAAqB,OAAO;AAAA,MAE9C;AAAA,IAAA;AAGM,WAAA;AAAA,EACR;AAEA,QAAM,gBAA2D;AAAA,IAChE,UAAU,uBACT,yCAAY,UACZA,uCAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,yCAAY,UACZA,uCAAiC,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mbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text field with a map to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text field with a map to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text field with a map or a function to HTML.\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it, you're\n\t * expected to use the `routes` option from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer. Unhandled cases will fall back to the\n\t * default serializer.\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Converts a rich text field to an HTML string.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const html = asHTML(document.data.content)\n\t * // => \"<p>Hello world</p>\"\n\t * ```\n\t *\n\t * @param richTextField - A rich text field from Prismic.\n\t * @param config - Configuration that determines the output of `asHTML()`.\n\t *\n\t * @returns HTML equivalent of the rich text field, or `null` if the field is\n\t * empty.\n\t *\n\t * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Converts a rich text field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text field from Prismic.\n\t * @param linkResolver - An optional link resolver function to resolve links.\n\t * Without it, you're expected to use the `routes` option from the API.\n\t * @param serializer - An optional rich text serializer. Unhandled cases will\n\t * fall back to the default serializer.\n\t *\n\t * @returns HTML equivalent of the rich text field, or `null` if the field is\n\t * empty.\n\t *\n\t * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":["serializeStandardTag","serializePreFormatted","serializeImage","serializeEmbed","serializeHyperlink","serializeSpan","wrapMapSerializer","composeSerializers","serialize"],"mappings":";;;;;;AAwJA,MAAM,+BAA+B,CACpC,cACA,eACuC;AACvC,QAAM,yBAAyB,CAG9B,2BACA,yBAG4D;AAC5D,QAAI,OAAO,8BAA8B,YAAY;AACpD,cAAQ,CAAC,YAAW;AACnB,eAEE,4BACG,OAAO,KAAK,qBAAqB,OAAO;AAAA,MAE9C;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAEA,QAAM,gBAA2D;AAAA,IAChE,UAAU,uBACT,YAAY,UACZA,kBAAAA,qBAAiC,MAAM,YAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,YAAY,UACZA,kBAAAA,qBAAiC,MAAM,YAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,YAAY,UACZA,kBAAAA,qBAAiC,MAAM,YAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,YAAY,UACZA,kBAAAA,qBAAiC,MAAM,YAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,YAAY,UACZA,kBAAAA,qBAAiC,MAAM,YAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,YAAY,UACZA,kBAAAA,qBAAiC,MAAM,YAAY,QAAQ,CAAC;AAAA,IAE7D,WAAW,uBACV,YAAY,WACZA,kBAAAA,qBAAkC,KAAK,YAAY,SAAS,CAAC;AAAA,IAE9D,cAAc,uBACb,YAAY,cACZC,kBAAAA,sBAAsB,YAAY,YAA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B;AAC/C;AAmCO,MAAM,SA4CT,CACH,kBAEG,wBACyB;AAC5B,MAAI,eAAe;AAElB,UAAM,CAAC,4BAA4B,eAAe,IAAI;AACtD,QAAI;AACJ,QACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACD,eAAS;AAAA,QACR,cAAc;AAAA,QACd,YAAY;AAAA,MAAA;AAAA,IAEd,OAAO;AACN,eAAS,EAAE,GAAG,2BAAA;AAAA,IACf;AAEA,QAAI;AACJ,QAAI,OAAO,YAAY;AACtB,UAAI,OAAO,OAAO,eAAe,YAAY;AAC5C,qBAAaC,mBAAAA,mBACZ,CAAC,MAAM,MAAM,MAAM,UAAU;AAAA;AAAA,UAE3B,OAAO,WACP,MACA,MACA,MACA,SAAS,KAAK,EAAE,GAChB,GAAG;AAAA,WAEL,6BAA6B,OAAO,YAAY,CAAC;AAAA,MAEnD,OAAO;AACN,qBAAa,6BACZ,OAAO,cACP,OAAO,UAAU;AAAA,MAEnB;AAAA,IACD,OAAO;AACN,mBAAa,6BAA6B,OAAO,YAAY;AAAA,IAC9D;AAEA,WAAOC,UAAAA,UAAU,eAAe,UAAU,EAAE,KAC3C,EAAE;AAAA,EAEJ,OAAO;AACN,WAAO;AAAA,EACR;AACD;;"}
|
package/dist/helpers/asHTML.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import type { RichTextField } from "../types/value/richText";
|
|
2
|
-
import type { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction } from "../richtext";
|
|
3
|
-
import type { LinkResolverFunction } from "./asLink";
|
|
1
|
+
import type { RichTextField } from "../types/value/richText.js";
|
|
2
|
+
import type { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction } from "../richtext.js";
|
|
3
|
+
import type { LinkResolverFunction } from "./asLink.js";
|
|
4
4
|
/**
|
|
5
|
-
* Serializes a node from a rich text
|
|
5
|
+
* Serializes a node from a rich text field with a function to HTML.
|
|
6
6
|
*
|
|
7
7
|
* Unlike a typical `@prismicio/client/richtext` function serializer, this
|
|
8
8
|
* serializer converts the `children` argument to a single string rather than an
|
|
9
9
|
* array of strings.
|
|
10
10
|
*
|
|
11
|
-
* @see
|
|
11
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
12
12
|
*/
|
|
13
13
|
export type HTMLRichTextFunctionSerializer = (type: Parameters<RichTextFunctionSerializer<string>>[0], node: Parameters<RichTextFunctionSerializer<string>>[1], text: Parameters<RichTextFunctionSerializer<string>>[2], children: Parameters<RichTextFunctionSerializer<string>>[3][number], key: Parameters<RichTextFunctionSerializer<string>>[4]) => string | null | undefined;
|
|
14
14
|
/**
|
|
15
|
-
* Serializes a node from a rich text
|
|
15
|
+
* Serializes a node from a rich text field with a map to HTML.
|
|
16
16
|
*
|
|
17
17
|
* Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
|
|
18
18
|
* converts the `children` property to a single string rather than an array of
|
|
19
19
|
* strings and accepts shorthand declarations.
|
|
20
20
|
*
|
|
21
|
-
* @see
|
|
21
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
22
22
|
*/
|
|
23
23
|
export type HTMLRichTextMapSerializer = {
|
|
24
24
|
[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>["span"] ? HTMLStrictRichTextMapSerializer[P] : HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
* Serializes a node from a rich text
|
|
27
|
+
* Serializes a node from a rich text field with a map to HTML.
|
|
28
28
|
*
|
|
29
29
|
* Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
|
|
30
30
|
* converts the `children` property to a single string rather than an array of
|
|
31
31
|
* strings but doesn't accept shorthand declarations.
|
|
32
32
|
*
|
|
33
|
-
* @see
|
|
33
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
34
34
|
*/
|
|
35
35
|
export type HTMLStrictRichTextMapSerializer = {
|
|
36
36
|
[P in keyof RichTextMapSerializer<string>]: (payload: {
|
|
@@ -76,11 +76,10 @@ export type HTMLRichTextMapSerializerShorthand = {
|
|
|
76
76
|
[Attribute: string]: string | boolean | null | undefined;
|
|
77
77
|
};
|
|
78
78
|
/**
|
|
79
|
-
* Serializes a node from a rich text
|
|
80
|
-
* HTML
|
|
79
|
+
* Serializes a node from a rich text field with a map or a function to HTML.
|
|
81
80
|
*
|
|
82
81
|
* @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}
|
|
83
|
-
* @see
|
|
82
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
84
83
|
*/
|
|
85
84
|
export type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFunctionSerializer;
|
|
86
85
|
/**
|
|
@@ -88,13 +87,13 @@ export type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFun
|
|
|
88
87
|
*/
|
|
89
88
|
type AsHTMLConfig = {
|
|
90
89
|
/**
|
|
91
|
-
* An optional link resolver function to resolve links. Without it you're
|
|
92
|
-
* expected to use the `routes`
|
|
90
|
+
* An optional link resolver function to resolve links. Without it, you're
|
|
91
|
+
* expected to use the `routes` option from the API.
|
|
93
92
|
*/
|
|
94
93
|
linkResolver?: LinkResolverFunction | null;
|
|
95
94
|
/**
|
|
96
|
-
* An optional rich text serializer
|
|
97
|
-
* default serializer
|
|
95
|
+
* An optional rich text serializer. Unhandled cases will fall back to the
|
|
96
|
+
* default serializer.
|
|
98
97
|
*/
|
|
99
98
|
serializer?: HTMLRichTextSerializer | null;
|
|
100
99
|
};
|
|
@@ -111,30 +110,39 @@ type AsHTMLDeprecatedTupleConfig = [
|
|
|
111
110
|
type AsHTMLReturnType<Field extends RichTextField | null | undefined> = Field extends RichTextField ? string : null;
|
|
112
111
|
export declare const asHTML: {
|
|
113
112
|
/**
|
|
114
|
-
*
|
|
113
|
+
* Converts a rich text field to an HTML string.
|
|
115
114
|
*
|
|
116
|
-
* @
|
|
117
|
-
* @param config - Configuration that determines the output of `asHTML()`
|
|
115
|
+
* @example
|
|
118
116
|
*
|
|
119
|
-
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* const html = asHTML(document.data.content)
|
|
119
|
+
* // => "<p>Hello world</p>"
|
|
120
|
+
* ```
|
|
120
121
|
*
|
|
121
|
-
* @
|
|
122
|
+
* @param richTextField - A rich text field from Prismic.
|
|
123
|
+
* @param config - Configuration that determines the output of `asHTML()`.
|
|
124
|
+
*
|
|
125
|
+
* @returns HTML equivalent of the rich text field, or `null` if the field is
|
|
126
|
+
* empty.
|
|
127
|
+
*
|
|
128
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
122
129
|
*/
|
|
123
130
|
<Field extends RichTextField | null | undefined>(richTextField: Field, config?: AsHTMLConfig): AsHTMLReturnType<Field>;
|
|
124
131
|
/**
|
|
125
|
-
*
|
|
132
|
+
* Converts a rich text field to an HTML string.
|
|
126
133
|
*
|
|
127
134
|
* @deprecated Use object-style configuration instead.
|
|
128
135
|
*
|
|
129
|
-
* @param richTextField - A rich text
|
|
130
|
-
* @param linkResolver - An optional link resolver function to resolve links
|
|
131
|
-
*
|
|
132
|
-
* @param serializer - An optional rich text serializer
|
|
133
|
-
*
|
|
136
|
+
* @param richTextField - A rich text field from Prismic.
|
|
137
|
+
* @param linkResolver - An optional link resolver function to resolve links.
|
|
138
|
+
* Without it, you're expected to use the `routes` option from the API.
|
|
139
|
+
* @param serializer - An optional rich text serializer. Unhandled cases will
|
|
140
|
+
* fall back to the default serializer.
|
|
134
141
|
*
|
|
135
|
-
* @returns HTML equivalent of the
|
|
142
|
+
* @returns HTML equivalent of the rich text field, or `null` if the field is
|
|
143
|
+
* empty.
|
|
136
144
|
*
|
|
137
|
-
* @see
|
|
145
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
138
146
|
*/
|
|
139
147
|
<Field extends RichTextField | null | undefined>(richTextField: Field, ...config: AsHTMLDeprecatedTupleConfig): AsHTMLReturnType<Field>;
|
|
140
148
|
};
|