@prismicio/client 7.2.0 → 7.3.1

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.
Files changed (131) hide show
  1. package/dist/createClient.cjs +18 -2
  2. package/dist/createClient.cjs.map +1 -1
  3. package/dist/createClient.js +18 -2
  4. package/dist/createClient.js.map +1 -1
  5. package/dist/errors/ForbiddenError.cjs.map +1 -1
  6. package/dist/errors/ForbiddenError.d.ts +1 -1
  7. package/dist/errors/ForbiddenError.js.map +1 -1
  8. package/dist/errors/NotFoundError.cjs.map +1 -1
  9. package/dist/errors/NotFoundError.d.ts +1 -1
  10. package/dist/errors/NotFoundError.js.map +1 -1
  11. package/dist/errors/ParsingError.cjs.map +1 -1
  12. package/dist/errors/ParsingError.d.ts +1 -1
  13. package/dist/errors/ParsingError.js.map +1 -1
  14. package/dist/errors/PreviewTokenExpired.cjs +7 -0
  15. package/dist/errors/PreviewTokenExpired.cjs.map +1 -0
  16. package/dist/errors/PreviewTokenExpired.d.ts +8 -0
  17. package/dist/errors/PreviewTokenExpired.js +7 -0
  18. package/dist/errors/PreviewTokenExpired.js.map +1 -0
  19. package/dist/errors/RefExpiredError.cjs +7 -0
  20. package/dist/errors/RefExpiredError.cjs.map +1 -0
  21. package/dist/errors/RefExpiredError.d.ts +8 -0
  22. package/dist/errors/RefExpiredError.js +7 -0
  23. package/dist/errors/RefExpiredError.js.map +1 -0
  24. package/dist/errors/RefNotFoundError.cjs +7 -0
  25. package/dist/errors/RefNotFoundError.cjs.map +1 -0
  26. package/dist/errors/RefNotFoundError.d.ts +8 -0
  27. package/dist/errors/RefNotFoundError.js +7 -0
  28. package/dist/errors/RefNotFoundError.js.map +1 -0
  29. package/dist/errors/RepositoryNotFoundError.cjs +7 -0
  30. package/dist/errors/RepositoryNotFoundError.cjs.map +1 -0
  31. package/dist/errors/RepositoryNotFoundError.d.ts +3 -0
  32. package/dist/errors/RepositoryNotFoundError.js +7 -0
  33. package/dist/errors/RepositoryNotFoundError.js.map +1 -0
  34. package/dist/helpers/asHTML.cjs +43 -50
  35. package/dist/helpers/asHTML.cjs.map +1 -1
  36. package/dist/helpers/asHTML.d.ts +31 -6
  37. package/dist/helpers/asHTML.js +42 -49
  38. package/dist/helpers/asHTML.js.map +1 -1
  39. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +1 -1
  40. package/dist/helpers/asImageSrc.d.ts +1 -1
  41. package/dist/helpers/asImageWidthSrcSet.cjs +1 -1
  42. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  43. package/dist/helpers/asImageWidthSrcSet.d.ts +1 -1
  44. package/dist/helpers/asImageWidthSrcSet.js +1 -1
  45. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  46. package/dist/helpers/asLinkAttrs.d.ts +1 -1
  47. package/dist/helpers/asText.cjs +2 -2
  48. package/dist/helpers/asText.cjs.map +1 -1
  49. package/dist/helpers/asText.js +1 -1
  50. package/dist/helpers/asText.js.map +1 -1
  51. package/dist/helpers/isFilled.d.ts +10 -13
  52. package/dist/index.cjs +12 -7
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.d.ts +30 -2
  55. package/dist/index.js +10 -2
  56. package/dist/index.js.map +1 -1
  57. package/dist/lib/serializerHelpers.cjs +91 -35
  58. package/dist/lib/serializerHelpers.cjs.map +1 -1
  59. package/dist/lib/serializerHelpers.d.ts +8 -8
  60. package/dist/lib/serializerHelpers.js +91 -35
  61. package/dist/lib/serializerHelpers.js.map +1 -1
  62. package/dist/package.json.cjs +1 -1
  63. package/dist/package.json.js +1 -1
  64. package/dist/richtext/asText.cjs +13 -0
  65. package/dist/richtext/asText.cjs.map +1 -0
  66. package/dist/richtext/asText.d.ts +12 -0
  67. package/dist/richtext/asText.js +13 -0
  68. package/dist/richtext/asText.js.map +1 -0
  69. package/dist/richtext/asTree.cjs +123 -0
  70. package/dist/richtext/asTree.cjs.map +1 -0
  71. package/dist/richtext/asTree.d.ts +14 -0
  72. package/dist/richtext/asTree.js +123 -0
  73. package/dist/richtext/asTree.js.map +1 -0
  74. package/dist/richtext/composeSerializers.cjs +17 -0
  75. package/dist/richtext/composeSerializers.cjs.map +1 -0
  76. package/dist/richtext/composeSerializers.d.ts +16 -0
  77. package/dist/richtext/composeSerializers.js +17 -0
  78. package/dist/richtext/composeSerializers.js.map +1 -0
  79. package/dist/richtext/index.d.ts +7 -0
  80. package/dist/richtext/serialize.cjs +19 -0
  81. package/dist/richtext/serialize.cjs.map +1 -0
  82. package/dist/richtext/serialize.d.ts +19 -0
  83. package/dist/richtext/serialize.js +19 -0
  84. package/dist/richtext/serialize.js.map +1 -0
  85. package/dist/richtext/types.cjs +11 -0
  86. package/dist/richtext/types.cjs.map +1 -0
  87. package/dist/richtext/types.d.ts +71 -0
  88. package/dist/richtext/types.js +11 -0
  89. package/dist/richtext/types.js.map +1 -0
  90. package/dist/richtext/wrapMapSerializer.cjs +24 -0
  91. package/dist/richtext/wrapMapSerializer.cjs.map +1 -0
  92. package/dist/richtext/wrapMapSerializer.d.ts +15 -0
  93. package/dist/richtext/wrapMapSerializer.js +24 -0
  94. package/dist/richtext/wrapMapSerializer.js.map +1 -0
  95. package/dist/richtext.cjs +15 -0
  96. package/dist/richtext.cjs.map +1 -0
  97. package/dist/richtext.js +15 -0
  98. package/dist/richtext.js.map +1 -0
  99. package/dist/types/value/image.d.ts +9 -0
  100. package/dist/types/value/linkToMedia.d.ts +1 -0
  101. package/dist/types/value/richText.cjs.map +1 -1
  102. package/dist/types/value/richText.d.ts +7 -0
  103. package/dist/types/value/richText.js.map +1 -1
  104. package/dist/types/value/sharedSlice.d.ts +1 -1
  105. package/dist/types/value/slice.d.ts +1 -1
  106. package/package.json +34 -15
  107. package/src/createClient.ts +35 -8
  108. package/src/errors/ForbiddenError.ts +5 -3
  109. package/src/errors/NotFoundError.ts +3 -1
  110. package/src/errors/ParsingError.ts +3 -1
  111. package/src/errors/PreviewTokenExpired.ts +12 -0
  112. package/src/errors/RefExpiredError.ts +14 -0
  113. package/src/errors/RefNotFoundError.ts +14 -0
  114. package/src/errors/RepositoryNotFoundError.ts +5 -0
  115. package/src/helpers/asHTML.ts +166 -76
  116. package/src/helpers/asImageWidthSrcSet.ts +2 -0
  117. package/src/helpers/asText.ts +2 -2
  118. package/src/index.ts +11 -4
  119. package/src/lib/serializerHelpers.ts +140 -67
  120. package/src/richtext/asText.ts +27 -0
  121. package/src/richtext/asTree.ts +211 -0
  122. package/src/richtext/composeSerializers.ts +36 -0
  123. package/src/richtext/index.ts +14 -0
  124. package/src/richtext/serialize.ts +54 -0
  125. package/src/richtext/types.ts +153 -0
  126. package/src/richtext/wrapMapSerializer.ts +46 -0
  127. package/src/types/value/image.ts +9 -0
  128. package/src/types/value/linkToMedia.ts +1 -0
  129. package/src/types/value/richText.ts +7 -0
  130. package/src/types/value/sharedSlice.ts +1 -1
  131. package/src/types/value/slice.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"asText.cjs","sources":["../../../src/helpers/asText.ts"],"sourcesContent":["import { asText as baseAsText } from \"@prismicio/richtext\";\n\nimport { RichTextField } from \"../types/value/richText\";\n\n/**\n * Configuration that determines the output of `asText()`.\n */\ntype AsTextConfig = {\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue ` ` (a space)\n\t */\n\tseparator?: string;\n};\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsTextDeprecatedTupleConfig = [separator?: string];\n\n/**\n * The return type of `asText()`.\n */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null;\n\nexport const asText: {\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 `asText()`\n\t *\n\t * @returns Plain text 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?: AsTextConfig,\n\t): AsTextReturnType<Field>;\n\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 separator - Separator used to join each element, defaults to a space\n\t *\n\t * @returns Plain text 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: AsTextDeprecatedTupleConfig\n\t): AsTextReturnType<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?: AsTextConfig] | AsTextDeprecatedTupleConfig\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrSeparator] = configObjectOrTuple;\n\t\tlet config: AsTextConfig;\n\t\tif (typeof configObjectOrSeparator === \"string\") {\n\t\t\tconfig = {\n\t\t\t\tseparator: configObjectOrSeparator,\n\t\t\t};\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrSeparator };\n\t\t}\n\n\t\treturn baseAsText(\n\t\t\trichTextField,\n\t\t\tconfig.separator,\n\t\t) as AsTextReturnType<Field>;\n\t} else {\n\t\treturn null as AsTextReturnType<Field>;\n\t}\n};\n"],"names":["baseAsText"],"mappings":";;;AA4Ba,MAAA,SAgCT,CACH,kBAEG,wBACyB;AAC5B,MAAI,eAAe;AAEZ,UAAA,CAAC,uBAAuB,IAAI;AAC9B,QAAA;AACA,QAAA,OAAO,4BAA4B,UAAU;AACvC,eAAA;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,WAEN;AACG,eAAA,EAAE,GAAG;IACd;AAEM,WAAAA,gBACN,eACA,OAAO,SAAS;AAAA,EAAA,OAEX;AACC,WAAA;AAAA,EACP;AACF;;"}
1
+ {"version":3,"file":"asText.cjs","sources":["../../../src/helpers/asText.ts"],"sourcesContent":["import { RichTextField } from \"../types/value/richText\";\n\nimport { asText as baseAsText } from \"../richtext/asText\";\n\n/**\n * Configuration that determines the output of `asText()`.\n */\ntype AsTextConfig = {\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue ` ` (a space)\n\t */\n\tseparator?: string;\n};\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsTextDeprecatedTupleConfig = [separator?: string];\n\n/**\n * The return type of `asText()`.\n */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null;\n\nexport const asText: {\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 `asText()`\n\t *\n\t * @returns Plain text 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?: AsTextConfig,\n\t): AsTextReturnType<Field>;\n\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 separator - Separator used to join each element, defaults to a space\n\t *\n\t * @returns Plain text 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: AsTextDeprecatedTupleConfig\n\t): AsTextReturnType<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?: AsTextConfig] | AsTextDeprecatedTupleConfig\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrSeparator] = configObjectOrTuple;\n\t\tlet config: AsTextConfig;\n\t\tif (typeof configObjectOrSeparator === \"string\") {\n\t\t\tconfig = {\n\t\t\t\tseparator: configObjectOrSeparator,\n\t\t\t};\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrSeparator };\n\t\t}\n\n\t\treturn baseAsText(\n\t\t\trichTextField,\n\t\t\tconfig.separator,\n\t\t) as AsTextReturnType<Field>;\n\t} else {\n\t\treturn null as AsTextReturnType<Field>;\n\t}\n};\n"],"names":["baseAsText"],"mappings":";;;AA4Ba,MAAA,SAgCT,CACH,kBAEG,wBACyB;AAC5B,MAAI,eAAe;AAEZ,UAAA,CAAC,uBAAuB,IAAI;AAC9B,QAAA;AACA,QAAA,OAAO,4BAA4B,UAAU;AACvC,eAAA;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,WAEN;AACG,eAAA,EAAE,GAAG;IACd;AAEM,WAAAA,gBACN,eACA,OAAO,SAAS;AAAA,EAAA,OAEX;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -1,4 +1,4 @@
1
- import { asText as asText$1 } from "@prismicio/richtext";
1
+ import { asText as asText$1 } from "../richtext/asText.js";
2
2
  const asText = (richTextField, ...configObjectOrTuple) => {
3
3
  if (richTextField) {
4
4
  const [configObjectOrSeparator] = configObjectOrTuple;
@@ -1 +1 @@
1
- {"version":3,"file":"asText.js","sources":["../../../src/helpers/asText.ts"],"sourcesContent":["import { asText as baseAsText } from \"@prismicio/richtext\";\n\nimport { RichTextField } from \"../types/value/richText\";\n\n/**\n * Configuration that determines the output of `asText()`.\n */\ntype AsTextConfig = {\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue ` ` (a space)\n\t */\n\tseparator?: string;\n};\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsTextDeprecatedTupleConfig = [separator?: string];\n\n/**\n * The return type of `asText()`.\n */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null;\n\nexport const asText: {\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 `asText()`\n\t *\n\t * @returns Plain text 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?: AsTextConfig,\n\t): AsTextReturnType<Field>;\n\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 separator - Separator used to join each element, defaults to a space\n\t *\n\t * @returns Plain text 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: AsTextDeprecatedTupleConfig\n\t): AsTextReturnType<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?: AsTextConfig] | AsTextDeprecatedTupleConfig\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrSeparator] = configObjectOrTuple;\n\t\tlet config: AsTextConfig;\n\t\tif (typeof configObjectOrSeparator === \"string\") {\n\t\t\tconfig = {\n\t\t\t\tseparator: configObjectOrSeparator,\n\t\t\t};\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrSeparator };\n\t\t}\n\n\t\treturn baseAsText(\n\t\t\trichTextField,\n\t\t\tconfig.separator,\n\t\t) as AsTextReturnType<Field>;\n\t} else {\n\t\treturn null as AsTextReturnType<Field>;\n\t}\n};\n"],"names":["baseAsText"],"mappings":";AA4Ba,MAAA,SAgCT,CACH,kBAEG,wBACyB;AAC5B,MAAI,eAAe;AAEZ,UAAA,CAAC,uBAAuB,IAAI;AAC9B,QAAA;AACA,QAAA,OAAO,4BAA4B,UAAU;AACvC,eAAA;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,WAEN;AACG,eAAA,EAAE,GAAG;IACd;AAEM,WAAAA,SACN,eACA,OAAO,SAAS;AAAA,EAAA,OAEX;AACC,WAAA;AAAA,EACP;AACF;"}
1
+ {"version":3,"file":"asText.js","sources":["../../../src/helpers/asText.ts"],"sourcesContent":["import { RichTextField } from \"../types/value/richText\";\n\nimport { asText as baseAsText } from \"../richtext/asText\";\n\n/**\n * Configuration that determines the output of `asText()`.\n */\ntype AsTextConfig = {\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue ` ` (a space)\n\t */\n\tseparator?: string;\n};\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsTextDeprecatedTupleConfig = [separator?: string];\n\n/**\n * The return type of `asText()`.\n */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null;\n\nexport const asText: {\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 `asText()`\n\t *\n\t * @returns Plain text 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?: AsTextConfig,\n\t): AsTextReturnType<Field>;\n\n\t/**\n\t * Serializes a rich text or title field to a plain text 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 separator - Separator used to join each element, defaults to a space\n\t *\n\t * @returns Plain text 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: AsTextDeprecatedTupleConfig\n\t): AsTextReturnType<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?: AsTextConfig] | AsTextDeprecatedTupleConfig\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrSeparator] = configObjectOrTuple;\n\t\tlet config: AsTextConfig;\n\t\tif (typeof configObjectOrSeparator === \"string\") {\n\t\t\tconfig = {\n\t\t\t\tseparator: configObjectOrSeparator,\n\t\t\t};\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrSeparator };\n\t\t}\n\n\t\treturn baseAsText(\n\t\t\trichTextField,\n\t\t\tconfig.separator,\n\t\t) as AsTextReturnType<Field>;\n\t} else {\n\t\treturn null as AsTextReturnType<Field>;\n\t}\n};\n"],"names":["baseAsText"],"mappings":";AA4Ba,MAAA,SAgCT,CACH,kBAEG,wBACyB;AAC5B,MAAI,eAAe;AAEZ,UAAA,CAAC,uBAAuB,IAAI;AAC9B,QAAA;AACA,QAAA,OAAO,4BAA4B,UAAU;AACvC,eAAA;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,WAEN;AACG,eAAA,EAAE,GAAG;IACd;AAEM,WAAAA,SACN,eACA,OAAO,SAAS;AAAA,EAAA,OAEX;AACC,WAAA;AAAA,EACP;AACF;"}
@@ -1,7 +1,7 @@
1
1
  import type { ColorField } from "../types/value/color";
2
2
  import type { ContentRelationshipField } from "../types/value/contentRelationship";
3
3
  import type { DateField } from "../types/value/date";
4
- import type { AnyOEmbed } from "../types/value/embed";
4
+ import type { AnyOEmbed, EmbedField } from "../types/value/embed";
5
5
  import type { GeoPointField } from "../types/value/geoPoint";
6
6
  import type { GroupField } from "../types/value/group";
7
7
  import type { ImageField, ImageFieldImage } from "../types/value/image";
@@ -51,7 +51,7 @@ export declare const imageThumbnail: (thumbnail: ImageFieldImage | null | undefi
51
51
  *
52
52
  * @returns `true` if `field` is filled, `false` otherwise.
53
53
  */
54
- export declare const image: <ThumbnailNames extends string | null = never>(field: import("../types/value/types").Simplify<(import("../types/value/image").EmptyImageFieldImage & Record<Extract<ThumbnailNames, string>, import("../types/value/image").EmptyImageFieldImage>) | (import("../types/value/image").FilledImageFieldImage & Record<Extract<ThumbnailNames, string>, import("../types/value/image").FilledImageFieldImage>)> | null | undefined) => field is import("../types/value/types").Simplify<import("../types/value/image").FilledImageFieldImage & Record<Extract<ThumbnailNames, string>, import("../types/value/image").FilledImageFieldImage>>;
54
+ export declare const image: <ThumbnailNames extends string | null = never>(field: ImageField<ThumbnailNames> | null | undefined) => field is import("../types/value/types").Simplify<import("../types/value/image").FilledImageFieldImage & Record<Extract<ThumbnailNames, string>, import("../types/value/image").FilledImageFieldImage>>;
55
55
  /**
56
56
  * Determines if a link field is filled.
57
57
  *
@@ -59,7 +59,7 @@ export declare const image: <ThumbnailNames extends string | null = never>(field
59
59
  *
60
60
  * @returns `true` if `field` is filled, `false` otherwise.
61
61
  */
62
- export declare const link: <TypeEnum = string, LangEnum = string, DataInterface extends unknown = unknown>(field: import("../types/value/link").EmptyLinkField<"Any"> | import("../types/value/link").FilledLinkToWebField | import("../types/value/linkToMedia").FilledLinkToMediaField | import("../types/value/contentRelationship").FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface> | null | undefined) => field is import("../types/value/link").FilledLinkToWebField | import("../types/value/linkToMedia").FilledLinkToMediaField | import("../types/value/contentRelationship").FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
62
+ export declare const link: <TypeEnum = string, LangEnum = string, DataInterface extends unknown = unknown>(field: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined) => field is import("../types/value/link").FilledLinkToWebField | import("../types/value/linkToMedia").FilledLinkToMediaField | import("../types/value/contentRelationship").FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
63
63
  /**
64
64
  * Determines if a link to media field is filled.
65
65
  *
@@ -75,7 +75,7 @@ export declare const linkToMedia: (field: LinkToMediaField | null | undefined) =
75
75
  *
76
76
  * @returns `true` if `field` is filled, `false` otherwise.
77
77
  */
78
- export declare const contentRelationship: <TypeEnum = string, LangEnum = string, DataInterface extends unknown = unknown>(field: import("../types/value/link").EmptyLinkField<"Document"> | import("../types/value/contentRelationship").FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface> | null | undefined) => field is import("../types/value/contentRelationship").FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
78
+ export declare const contentRelationship: <TypeEnum = string, LangEnum = string, DataInterface extends unknown = unknown>(field: ContentRelationshipField<TypeEnum, LangEnum, DataInterface> | null | undefined) => field is import("../types/value/contentRelationship").FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>;
79
79
  /**
80
80
  * Determines if a date field is filled.
81
81
  *
@@ -123,7 +123,7 @@ export declare const keyText: (field: KeyTextField | null | undefined) => field
123
123
  *
124
124
  * @returns `true` if `field` is filled, `false` otherwise.
125
125
  */
126
- export declare const select: <Enum extends string>(field: Enum | null | undefined) => field is Enum;
126
+ export declare const select: <Enum extends string>(field: SelectField<Enum> | undefined) => field is Enum;
127
127
  /**
128
128
  * Determines if an embed field is filled.
129
129
  *
@@ -131,10 +131,7 @@ export declare const select: <Enum extends string>(field: Enum | null | undefine
131
131
  *
132
132
  * @returns `true` if `field` is filled, `false` otherwise.
133
133
  */
134
- export declare const embed: <Field extends import("../types/value/types").EmptyObjectField | (AnyOEmbed & {
135
- embed_url: string;
136
- html: string | null;
137
- })>(field: Field | null | undefined) => field is Extract<Field, AnyOEmbed & {
134
+ export declare const embed: <Field extends EmbedField<AnyOEmbed>>(field: Field | null | undefined) => field is Extract<Field, AnyOEmbed & {
138
135
  embed_url: string;
139
136
  html: string | null;
140
137
  }>;
@@ -156,11 +153,11 @@ export declare const geoPoint: (field: GeoPointField | null | undefined) => fiel
156
153
  *
157
154
  * @returns `true` if `field` is filled, `false` otherwise.
158
155
  */
159
- export declare const integrationField: <Data extends Record<string, unknown>>(field: Data | null | undefined) => field is Data;
156
+ export declare const integrationField: <Data extends Record<string, unknown>>(field: IntegrationField<Data> | undefined) => field is Data;
160
157
  /**
161
158
  * @deprecated Renamed to `integrationField`.
162
159
  */
163
- export declare const integrationFields: <Data extends Record<string, unknown>>(field: Data | null | undefined) => field is Data;
160
+ export declare const integrationFields: <Data extends Record<string, unknown>>(field: IntegrationField<Data> | undefined) => field is Data;
164
161
  /**
165
162
  * Determines if a Group has at least one item.
166
163
  *
@@ -168,7 +165,7 @@ export declare const integrationFields: <Data extends Record<string, unknown>>(f
168
165
  *
169
166
  * @returns `true` if `group` contains at least one item, `false` otherwise.
170
167
  */
171
- export declare const group: <Fields extends Record<string, AnyRegularField>>(group: [] | [Fields, ...Fields[]] | null | undefined) => group is [Fields, ...Fields[]];
168
+ export declare const group: <Fields extends Record<string, AnyRegularField>>(group: GroupField<Fields> | null | undefined) => group is [Fields, ...Fields[]];
172
169
  /**
173
170
  * Determines if a Slice Zone has at least one Slice.
174
171
  *
@@ -176,4 +173,4 @@ export declare const group: <Fields extends Record<string, AnyRegularField>>(gro
176
173
  *
177
174
  * @returns `true` if `slices` contains at least one Slice, `false` otherwise.
178
175
  */
179
- export declare const sliceZone: <Slices extends Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<string, import("..").SharedSliceVariation<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>>>>(slices: [] | [Slices, ...Slices[]] | null | undefined) => slices is [Slices, ...Slices[]];
176
+ export declare const sliceZone: <Slices extends Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice>(slices: SliceZone<Slices> | null | undefined) => slices is [Slices, ...Slices[]];
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const richText = require("./types/value/richText.cjs");
3
4
  const filter = require("./filter.cjs");
4
5
  const createClient = require("./createClient.cjs");
5
6
  const getRepositoryEndpoint = require("./getRepositoryEndpoint.cjs");
@@ -21,12 +22,14 @@ const asImagePixelDensitySrcSet = require("./helpers/asImagePixelDensitySrcSet.c
21
22
  const unstable_mapSliceZone = require("./helpers/unstable_mapSliceZone.cjs");
22
23
  const isFilled = require("./helpers/isFilled.cjs");
23
24
  const documentToLinkField = require("./helpers/documentToLinkField.cjs");
24
- const richtext = require("@prismicio/richtext");
25
25
  const PrismicError = require("./errors/PrismicError.cjs");
26
26
  const ForbiddenError = require("./errors/ForbiddenError.cjs");
27
27
  const NotFoundError = require("./errors/NotFoundError.cjs");
28
+ const RefNotFoundError = require("./errors/RefNotFoundError.cjs");
29
+ const RefExpiredError = require("./errors/RefExpiredError.cjs");
30
+ const PreviewTokenExpired = require("./errors/PreviewTokenExpired.cjs");
28
31
  const ParsingError = require("./errors/ParsingError.cjs");
29
- const richText = require("./types/value/richText.cjs");
32
+ const RepositoryNotFoundError = require("./errors/RepositoryNotFoundError.cjs");
30
33
  const link = require("./types/value/link.cjs");
31
34
  const embed = require("./types/value/embed.cjs");
32
35
  const types = require("./types/model/types.cjs");
@@ -35,6 +38,8 @@ const sliceZone = require("./types/model/sliceZone.cjs");
35
38
  const slice = require("./types/model/slice.cjs");
36
39
  const types$1 = require("./types/webhook/types.cjs");
37
40
  const predicate = filter.filter;
41
+ const Element = richText.RichTextNodeType;
42
+ exports.RichTextNodeType = richText.RichTextNodeType;
38
43
  exports.filter = filter.filter;
39
44
  exports.Client = createClient.Client;
40
45
  exports.createClient = createClient.createClient;
@@ -57,15 +62,14 @@ exports.asImagePixelDensitySrcSet = asImagePixelDensitySrcSet.asImagePixelDensit
57
62
  exports.unstable_mapSliceZone = unstable_mapSliceZone.unstable_mapSliceZone;
58
63
  exports.isFilled = isFilled;
59
64
  exports.documentToLinkField = documentToLinkField.documentToLinkField;
60
- Object.defineProperty(exports, "Element", {
61
- enumerable: true,
62
- get: () => richtext.Element
63
- });
64
65
  exports.PrismicError = PrismicError.PrismicError;
65
66
  exports.ForbiddenError = ForbiddenError.ForbiddenError;
66
67
  exports.NotFoundError = NotFoundError.NotFoundError;
68
+ exports.RefNotFoundError = RefNotFoundError.RefNotFoundError;
69
+ exports.RefExpiredError = RefExpiredError.RefExpiredError;
70
+ exports.PreviewTokenExpiredError = PreviewTokenExpired.PreviewTokenExpiredError;
67
71
  exports.ParsingError = ParsingError.ParsingError;
68
- exports.RichTextNodeType = richText.RichTextNodeType;
72
+ exports.RepositoryNotFoundError = RepositoryNotFoundError.RepositoryNotFoundError;
69
73
  exports.LinkType = link.LinkType;
70
74
  exports.OEmbedType = embed.OEmbedType;
71
75
  exports.CustomTypeModelFieldType = types.CustomTypeModelFieldType;
@@ -73,5 +77,6 @@ exports.CustomTypeModelLinkSelectType = link$1.CustomTypeModelLinkSelectType;
73
77
  exports.CustomTypeModelSliceType = sliceZone.CustomTypeModelSliceType;
74
78
  exports.CustomTypeModelSliceDisplay = slice.CustomTypeModelSliceDisplay;
75
79
  exports.WebhookType = types$1.WebhookType;
80
+ exports.Element = Element;
76
81
  exports.predicate = predicate;
77
82
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport { unstable_mapSliceZone } from \"./helpers/unstable_mapSliceZone\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\n// RichText element types.\nexport { Element } from \"@prismicio/richtext\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { ParsingError } from \"./errors/ParsingError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\nexport { RichTextNodeType } from \"./types/value/richText\";\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":["filter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAYA,OAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\nimport { RichTextNodeType } from \"./types/value/richText\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport { unstable_mapSliceZone } from \"./helpers/unstable_mapSliceZone\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { RefNotFoundError } from \"./errors/RefNotFoundError\";\nexport { RefExpiredError } from \"./errors/RefExpiredError\";\nexport { PreviewTokenExpiredError } from \"./errors/PreviewTokenExpired\";\nexport { ParsingError } from \"./errors/ParsingError\";\nexport { RepositoryNotFoundError } from \"./errors/RepositoryNotFoundError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\n/**\n * @deprecated Use {@link RichTextNodeType} instead.\n */\n// TODO: Remove in v8.\nconst Element = RichTextNodeType;\nexport { RichTextNodeType, Element };\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":["filter","RichTextNodeType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,YAAYA,OAAA;AAmFlB,MAAM,UAAUC,SAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { CustomTypeModelIntegrationField } from "./types/model/integration";
2
2
  import type { IntegrationField } from "./types/value/integration";
3
+ import { RichTextNodeType } from "./types/value/richText";
3
4
  import type { HTMLRichTextFunctionSerializer, HTMLRichTextMapSerializer } from "./helpers/asHTML";
4
5
  import { filter } from "./filter";
5
6
  export { createClient, Client } from "./createClient";
@@ -58,7 +59,6 @@ export { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet";
58
59
  export { unstable_mapSliceZone } from "./helpers/unstable_mapSliceZone";
59
60
  export * as isFilled from "./helpers/isFilled";
60
61
  export { documentToLinkField } from "./helpers/documentToLinkField";
61
- export { Element } from "@prismicio/richtext";
62
62
  export type { LinkResolverFunction } from "./helpers/asLink";
63
63
  export type { AsLinkAttrsConfig } from "./helpers/asLinkAttrs";
64
64
  /**
@@ -74,8 +74,36 @@ export type { HTMLRichTextSerializer } from "./helpers/asHTML";
74
74
  export { PrismicError } from "./errors/PrismicError";
75
75
  export { ForbiddenError } from "./errors/ForbiddenError";
76
76
  export { NotFoundError } from "./errors/NotFoundError";
77
+ export { RefNotFoundError } from "./errors/RefNotFoundError";
78
+ export { RefExpiredError } from "./errors/RefExpiredError";
79
+ export { PreviewTokenExpiredError } from "./errors/PreviewTokenExpired";
77
80
  export { ParsingError } from "./errors/ParsingError";
78
- export { RichTextNodeType } from "./types/value/richText";
81
+ export { RepositoryNotFoundError } from "./errors/RepositoryNotFoundError";
82
+ /**
83
+ * @deprecated Use {@link RichTextNodeType} instead.
84
+ */
85
+ declare const Element: {
86
+ readonly heading1: "heading1";
87
+ readonly heading2: "heading2";
88
+ readonly heading3: "heading3";
89
+ readonly heading4: "heading4";
90
+ readonly heading5: "heading5";
91
+ readonly heading6: "heading6";
92
+ readonly paragraph: "paragraph";
93
+ readonly preformatted: "preformatted";
94
+ readonly strong: "strong";
95
+ readonly em: "em";
96
+ readonly listItem: "list-item";
97
+ readonly oListItem: "o-list-item";
98
+ readonly list: "group-list-item";
99
+ readonly oList: "group-o-list-item";
100
+ readonly image: "image";
101
+ readonly embed: "embed";
102
+ readonly hyperlink: "hyperlink";
103
+ readonly label: "label";
104
+ readonly span: "span";
105
+ };
106
+ export { RichTextNodeType, Element };
79
107
  export { LinkType } from "./types/value/link";
80
108
  export { OEmbedType } from "./types/value/embed";
81
109
  export type { PrismicDocument, PrismicDocumentWithUID, PrismicDocumentWithoutUID, PrismicDocumentHeader, AlternateLanguage, } from "./types/value/document";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { RichTextNodeType } from "./types/value/richText.js";
1
2
  import { filter } from "./filter.js";
2
3
  import { Client, createClient } from "./createClient.js";
3
4
  import { getRepositoryEndpoint } from "./getRepositoryEndpoint.js";
@@ -19,12 +20,14 @@ import { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet.j
19
20
  import { unstable_mapSliceZone } from "./helpers/unstable_mapSliceZone.js";
20
21
  import * as isFilled from "./helpers/isFilled.js";
21
22
  import { documentToLinkField } from "./helpers/documentToLinkField.js";
22
- import { Element } from "@prismicio/richtext";
23
23
  import { PrismicError } from "./errors/PrismicError.js";
24
24
  import { ForbiddenError } from "./errors/ForbiddenError.js";
25
25
  import { NotFoundError } from "./errors/NotFoundError.js";
26
+ import { RefNotFoundError } from "./errors/RefNotFoundError.js";
27
+ import { RefExpiredError } from "./errors/RefExpiredError.js";
28
+ import { PreviewTokenExpiredError } from "./errors/PreviewTokenExpired.js";
26
29
  import { ParsingError } from "./errors/ParsingError.js";
27
- import { RichTextNodeType } from "./types/value/richText.js";
30
+ import { RepositoryNotFoundError } from "./errors/RepositoryNotFoundError.js";
28
31
  import { LinkType } from "./types/value/link.js";
29
32
  import { OEmbedType } from "./types/value/embed.js";
30
33
  import { CustomTypeModelFieldType } from "./types/model/types.js";
@@ -33,6 +36,7 @@ import { CustomTypeModelSliceType } from "./types/model/sliceZone.js";
33
36
  import { CustomTypeModelSliceDisplay } from "./types/model/slice.js";
34
37
  import { WebhookType } from "./types/webhook/types.js";
35
38
  const predicate = filter;
39
+ const Element = RichTextNodeType;
36
40
  export {
37
41
  Client,
38
42
  CustomTypeModelFieldType,
@@ -45,7 +49,11 @@ export {
45
49
  NotFoundError,
46
50
  OEmbedType,
47
51
  ParsingError,
52
+ PreviewTokenExpiredError,
48
53
  PrismicError,
54
+ RefExpiredError,
55
+ RefNotFoundError,
56
+ RepositoryNotFoundError,
49
57
  RichTextNodeType,
50
58
  WebhookType,
51
59
  asDate,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport { unstable_mapSliceZone } from \"./helpers/unstable_mapSliceZone\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\n// RichText element types.\nexport { Element } from \"@prismicio/richtext\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { ParsingError } from \"./errors/ParsingError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\nexport { RichTextNodeType } from \"./types/value/richText\";\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// Imports are used for deprecations.\nimport type { CustomTypeModelIntegrationField } from \"./types/model/integration\";\nimport type { IntegrationField } from \"./types/value/integration\";\nimport { RichTextNodeType } from \"./types/value/richText\";\n\nimport type {\n\tHTMLRichTextFunctionSerializer,\n\tHTMLRichTextMapSerializer,\n} from \"./helpers/asHTML\";\n\nimport { filter } from \"./filter\";\n\n//=============================================================================\n// Client - Query content from Prismic.\n//=============================================================================\n\n// Primary Client API.\nexport { createClient, Client } from \"./createClient\";\n\n// API endpoint helpers.\nexport { getRepositoryEndpoint } from \"./getRepositoryEndpoint\";\nexport { getRepositoryName } from \"./getRepositoryName\";\nexport { getGraphQLEndpoint } from \"./getGraphQLEndpoint\";\nexport { isRepositoryName } from \"./isRepositoryName\";\nexport { isRepositoryEndpoint } from \"./isRepositoryEndpoint\";\nexport { buildQueryURL } from \"./buildQueryURL\";\n\n// Toolbar helpers.\nexport { getToolbarSrc } from \"./getToolbarSrc\";\n\n// Query filters API.\n/**\n * @deprecated Renamed to `filter`\n */\n// TODO: Remove when we remove support for deprecated `predicate` export.\nconst predicate = filter;\nexport { filter, predicate };\n\n// A collection of well-known cookie names shared between Prismic libraries and systems.\nexport * as cookie from \"./cookie\";\n\n// General types used to query content from Prismic. These are made public to allow users to better type their projects.\nexport type {\n\tAbortSignalLike,\n\tClientConfig,\n\tCreateClient,\n\tFetchLike,\n\tHttpRequestLike,\n\tRequestInitLike,\n\tResponseLike,\n} from \"./createClient\";\nexport type {\n\tBuildQueryURLArgs,\n\tOrdering,\n\tQueryParams,\n\tRoute,\n} from \"./buildQueryURL\";\n\n//=============================================================================\n// Helpers - Manipulate content from Prismic.\n//=============================================================================\n\n// Primary Helpers API.\nexport { asDate } from \"./helpers/asDate\";\nexport { asLink } from \"./helpers/asLink\";\nexport { asLinkAttrs } from \"./helpers/asLinkAttrs\";\nexport { asText } from \"./helpers/asText\";\nexport { asHTML } from \"./helpers/asHTML\";\nexport { asImageSrc } from \"./helpers/asImageSrc\";\nexport { asImageWidthSrcSet } from \"./helpers/asImageWidthSrcSet\";\nexport { asImagePixelDensitySrcSet } from \"./helpers/asImagePixelDensitySrcSet\";\nexport { unstable_mapSliceZone } from \"./helpers/unstable_mapSliceZone\";\nexport * as isFilled from \"./helpers/isFilled\";\n\n// Conversion helper.\nexport { documentToLinkField } from \"./helpers/documentToLinkField\";\n\nexport type { LinkResolverFunction } from \"./helpers/asLink\";\nexport type { AsLinkAttrsConfig } from \"./helpers/asLinkAttrs\";\n\n/**\n * @deprecated Renamed to `HTMLRichTextMapSerializer`\n */\ntype HTMLMapSerializer = HTMLRichTextMapSerializer;\n/**\n * @deprecated Renamed to `HTMLRichTextFunctionSerializer`\n */\ntype HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;\nexport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLRichTextFunctionSerializer,\n\tHTMLMapSerializer,\n\tHTMLFunctionSerializer,\n};\nexport type { HTMLRichTextSerializer } from \"./helpers/asHTML\";\n\n//=============================================================================\n// Errors - Custom errors for Prismic APIs.\n//=============================================================================\n\nexport { PrismicError } from \"./errors/PrismicError\";\nexport { ForbiddenError } from \"./errors/ForbiddenError\";\nexport { NotFoundError } from \"./errors/NotFoundError\";\nexport { RefNotFoundError } from \"./errors/RefNotFoundError\";\nexport { RefExpiredError } from \"./errors/RefExpiredError\";\nexport { PreviewTokenExpiredError } from \"./errors/PreviewTokenExpired\";\nexport { ParsingError } from \"./errors/ParsingError\";\nexport { RepositoryNotFoundError } from \"./errors/RepositoryNotFoundError\";\n\n//=============================================================================\n// Types - Types representing Prismic content, models, and API payloads.\n//=============================================================================\n\n// Values - Types representing Prismic content.\n/**\n * @deprecated Use {@link RichTextNodeType} instead.\n */\n// TODO: Remove in v8.\nconst Element = RichTextNodeType;\nexport { RichTextNodeType, Element };\nexport { LinkType } from \"./types/value/link\";\nexport { OEmbedType } from \"./types/value/embed\";\n\nexport type {\n\tPrismicDocument,\n\tPrismicDocumentWithUID,\n\tPrismicDocumentWithoutUID,\n\tPrismicDocumentHeader,\n\tAlternateLanguage,\n} from \"./types/value/document\";\n\nexport type {\n\t// RichText & Title\n\tRichTextField,\n\t// RichText & Title (block nodes)\n\tRTTextNodeBase,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTListItemNode,\n\tRTOListItemNode,\n\t// RichText & Title (span nodes)\n\tRTSpanNodeBase,\n\tRTStrongNode,\n\tRTEmNode,\n\tRTLabelNode,\n\t// RichText & Title (media nodes)\n\tRTImageNode,\n\tRTEmbedNode,\n\t// RichText & Title (link nodes)\n\tRTLinkNode,\n\t// RichText & Title (serialization related nodes)\n\tRTListNode,\n\tRTOListNode,\n\tRTSpanNode,\n\t// RichText & Title (helpers)\n\tRTNode,\n\tRTTextNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTAnyNode,\n} from \"./types/value/richText\";\nexport type { TitleField } from \"./types/value/title\";\n\nexport type {\n\tImageField,\n\tImageFieldImage,\n\tFilledImageFieldImage,\n\tEmptyImageFieldImage,\n} from \"./types/value/image\";\n\nexport type {\n\tEmptyLinkField,\n\tLinkField,\n\tFilledLinkToWebField,\n} from \"./types/value/link\";\nexport type {\n\tContentRelationshipField,\n\tFilledContentRelationshipField,\n} from \"./types/value/contentRelationship\";\nexport type {\n\tLinkToMediaField,\n\tFilledLinkToMediaField,\n} from \"./types/value/linkToMedia\";\n\nexport type {\n\tOEmbedExtra,\n\tPhotoOEmbed,\n\tVideoOEmbed,\n\tLinkOEmbed,\n\tRichOEmbed,\n\tAnyOEmbed,\n\tEmbedField,\n} from \"./types/value/embed\";\n\nexport type { BooleanField } from \"./types/value/boolean\";\nexport type { ColorField } from \"./types/value/color\";\nexport type { DateField } from \"./types/value/date\";\nexport type { KeyTextField } from \"./types/value/keyText\";\nexport type { NumberField } from \"./types/value/number\";\nexport type { SelectField } from \"./types/value/select\";\nexport type { TimestampField } from \"./types/value/timestamp\";\nexport type { GeoPointField } from \"./types/value/geoPoint\";\n\n/**\n * @deprecated Renamed to `IntegrationField`\n */\n// TODO: Remove when we remove support for deprecated `IntegrationFields` export.\ntype IntegrationFields = IntegrationField;\nexport { IntegrationField, IntegrationFields };\n\nexport type { GroupField } from \"./types/value/group\";\n\nexport type { SliceZone } from \"./types/value/sliceZone\";\nexport type { Slice } from \"./types/value/slice\";\nexport type { SharedSlice } from \"./types/value/sharedSlice\";\nexport type { SharedSliceVariation } from \"./types/value/sharedSliceVariation\";\n\nexport type { FieldState, AnyRegularField } from \"./types/value/types\";\n\n// Models - Types representing Prismic content models.\nexport { CustomTypeModelFieldType } from \"./types/model/types\";\nexport { CustomTypeModelLinkSelectType } from \"./types/model/link\";\nexport { CustomTypeModelSliceType } from \"./types/model/sliceZone\";\nexport { CustomTypeModelSliceDisplay } from \"./types/model/slice\";\n\nexport type {\n\tCustomTypeModel,\n\tCustomTypeModelDefinition,\n\tCustomTypeModelTab,\n} from \"./types/model/customType\";\n\nexport type {\n\tCustomTypeModelRichTextField,\n\tCustomTypeModelRichTextMultiField,\n\tCustomTypeModelRichTextSingleField,\n} from \"./types/model/richText\";\nexport type { CustomTypeModelTitleField } from \"./types/model/title\";\n\nexport type {\n\tCustomTypeModelImageField,\n\tCustomTypeModelImageConstraint,\n\tCustomTypeModelImageThumbnail,\n} from \"./types/model/image\";\n\nexport type { CustomTypeModelContentRelationshipField } from \"./types/model/contentRelationship\";\nexport type { CustomTypeModelLinkField } from \"./types/model/link\";\nexport type { CustomTypeModelLinkToMediaField } from \"./types/model/linkToMedia\";\n\nexport type { CustomTypeModelEmbedField } from \"./types/model/embed\";\n\nexport type { CustomTypeModelBooleanField } from \"./types/model/boolean\";\nexport type { CustomTypeModelColorField } from \"./types/model/color\";\nexport type { CustomTypeModelDateField } from \"./types/model/date\";\nexport type { CustomTypeModelKeyTextField } from \"./types/model/keyText\";\nexport type { CustomTypeModelNumberField } from \"./types/model/number\";\nexport type { CustomTypeModelSelectField } from \"./types/model/select\";\nexport type { CustomTypeModelTimestampField } from \"./types/model/timestamp\";\nexport type { CustomTypeModelGeoPointField } from \"./types/model/geoPoint\";\n\n/**\n * @deprecated Renamed to `CustomTypeModelIntegrationField`.\n */\n// TODO: Remove when we remove support for deprecated `CustomTypeModelIntegrationField` export.\ntype CustomTypeModelIntegrationFieldsField = CustomTypeModelIntegrationField;\nexport {\n\tCustomTypeModelIntegrationField,\n\tCustomTypeModelIntegrationFieldsField,\n};\nexport type { CustomTypeModelGroupField } from \"./types/model/group\";\nexport type {\n\tCustomTypeModelSliceZoneField,\n\tCustomTypeModelSliceLabel,\n\tCustomTypeModelSharedSlice,\n} from \"./types/model/sliceZone\";\nexport type {\n\tCustomTypeModelSlice,\n\tCustomTypeModelLegacySlice,\n} from \"./types/model/slice\";\nexport type { SharedSliceModel } from \"./types/model/sharedSlice\";\nexport type { SharedSliceModelVariation } from \"./types/model/sharedSliceVariation\";\n\nexport type { CustomTypeModelUIDField } from \"./types/model/uid\";\n\nexport type { CustomTypeModelRangeField } from \"./types/model/range\";\nexport type { CustomTypeModelSeparatorField } from \"./types/model/separator\";\n\nexport type {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldForGroup,\n} from \"./types/model/types\";\n\n// API - Types representing Prismic Rest API V2 responses.\nexport type { Query } from \"./types/api/query\";\n\nexport type { Ref } from \"./types/api/ref\";\n\nexport type { Release } from \"./types/api/release\";\n\nexport type {\n\tRepository,\n\tLanguage,\n\tForm,\n\tFormField,\n} from \"./types/api/repository\";\n\nexport type { Tags } from \"./types/api/tags\";\n\n// Webhook - Types representing Prismic webhooks.\nexport { WebhookType } from \"./types/webhook/types\";\n\nexport type { WebhookBody } from \"./types/webhook/types\";\n\nexport type { WebhookBodyAPIUpdate } from \"./types/webhook/apiUpdate\";\n\nexport type { WebhookBodyTestTrigger } from \"./types/webhook/testTrigger\";\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,YAAY;AAmFlB,MAAM,UAAU;"}
@@ -1,50 +1,106 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const link = require("../types/value/link.cjs");
4
- const richText = require("../types/value/richText.cjs");
5
4
  const asLink = require("../helpers/asLink.cjs");
6
5
  const escapeHTML = require("./escapeHTML.cjs");
7
- const getLabel = (node) => {
8
- return "data" in node && "label" in node.data ? ` class="${node.data.label}"` : "";
9
- };
10
- const serializeStandardTag = (tag, node, children) => {
11
- return `<${tag}${getLabel(node)}>${children.join("")}</${tag}>`;
12
- };
13
- const serializePreFormatted = (node) => {
14
- return `<pre${getLabel(node)}>${escapeHTML.escapeHTML(node.text)}</pre>`;
15
- };
16
- const serializeImage = (linkResolver, node) => {
17
- let imageTag = `<img src="${node.url}" alt="${escapeHTML.escapeHTML(node.alt)}"${node.copyright ? ` copyright="${escapeHTML.escapeHTML(node.copyright)}"` : ""} />`;
18
- if (node.linkTo) {
19
- imageTag = serializeHyperlink(linkResolver, {
20
- type: richText.RichTextNodeType.hyperlink,
21
- data: node.linkTo,
22
- start: 0,
23
- end: 0
24
- }, [imageTag]);
6
+ const formatAttributes = (node, attributes) => {
7
+ const _attributes = { ...attributes };
8
+ if ("data" in node && "label" in node.data && node.data.label) {
9
+ _attributes.class = _attributes.class ? `${_attributes.class} ${node.data.label}` : node.data.label;
25
10
  }
26
- return `<p class="block-img">${imageTag}</p>`;
11
+ const result = [];
12
+ for (const key in _attributes) {
13
+ const value = _attributes[key];
14
+ if (value) {
15
+ if (typeof value === "boolean") {
16
+ result.push(key);
17
+ } else {
18
+ result.push(`${key}="${escapeHTML.escapeHTML(value)}"`);
19
+ }
20
+ }
21
+ }
22
+ if (result.length) {
23
+ result.unshift("");
24
+ }
25
+ return result.join(" ");
27
26
  };
28
- const serializeEmbed = (node) => {
29
- return `<div data-oembed="${node.oembed.embed_url}" data-oembed-type="${node.oembed.type}" data-oembed-provider="${node.oembed.provider_name}"${getLabel(node)}>${node.oembed.html}</div>`;
27
+ const getGeneralAttributes = (serializerOrShorthand) => {
28
+ return serializerOrShorthand && typeof serializerOrShorthand !== "function" ? serializerOrShorthand : {};
30
29
  };
31
- const serializeHyperlink = (linkResolver, node, children) => {
32
- switch (node.data.link_type) {
33
- case link.LinkType.Web: {
34
- return `<a href="${escapeHTML.escapeHTML(node.data.url)}" ${node.data.target ? `target="${node.data.target}" ` : ""}rel="noopener noreferrer"${getLabel(node)}>${children.join("")}</a>`;
35
- }
36
- case link.LinkType.Document: {
37
- return `<a href="${asLink.asLink(node.data, linkResolver)}"${getLabel(node)}>${children.join("")}</a>`;
30
+ const serializeStandardTag = (tag, serializerOrShorthand) => {
31
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
32
+ return ({ node, children }) => {
33
+ return `<${tag}${formatAttributes(node, generalAttributes)}>${children}</${tag}>`;
34
+ };
35
+ };
36
+ const serializePreFormatted = (serializerOrShorthand) => {
37
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
38
+ return ({ node }) => {
39
+ return `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML.escapeHTML(node.text)}</pre>`;
40
+ };
41
+ };
42
+ const serializeImage = (linkResolver, serializerOrShorthand) => {
43
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
44
+ return ({ node }) => {
45
+ const attributes = {
46
+ ...generalAttributes,
47
+ src: node.url,
48
+ alt: node.alt,
49
+ copyright: node.copyright
50
+ };
51
+ let imageTag = `<img${formatAttributes(node, attributes)} />`;
52
+ if (node.linkTo) {
53
+ imageTag = serializeHyperlink(linkResolver)({
54
+ type: "hyperlink",
55
+ node: {
56
+ type: "hyperlink",
57
+ data: node.linkTo,
58
+ start: 0,
59
+ end: 0
60
+ },
61
+ text: "",
62
+ children: imageTag,
63
+ key: ""
64
+ });
38
65
  }
39
- case link.LinkType.Media: {
40
- return `<a href="${node.data.url}"${getLabel(node)}>${children.join("")}</a>`;
66
+ return `<p class="block-img">${imageTag}</p>`;
67
+ };
68
+ };
69
+ const serializeEmbed = (serializerOrShorthand) => {
70
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
71
+ return ({ node }) => {
72
+ const attributes = {
73
+ ...generalAttributes,
74
+ ["data-oembed"]: node.oembed.embed_url,
75
+ ["data-oembed-type"]: node.oembed.type,
76
+ ["data-oembed-provider"]: node.oembed.provider_name
77
+ };
78
+ return `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`;
79
+ };
80
+ };
81
+ const serializeHyperlink = (linkResolver, serializerOrShorthand) => {
82
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
83
+ return ({ node, children }) => {
84
+ const attributes = {
85
+ ...generalAttributes
86
+ };
87
+ if (node.data.link_type === link.LinkType.Web) {
88
+ attributes.href = node.data.url;
89
+ attributes.target = node.data.target;
90
+ attributes.rel = "noopener noreferrer";
91
+ } else if (node.data.link_type === link.LinkType.Document) {
92
+ attributes.href = asLink.asLink(node.data, { linkResolver });
93
+ } else if (node.data.link_type === link.LinkType.Media) {
94
+ attributes.href = node.data.url;
41
95
  }
42
- }
96
+ return `<a${formatAttributes(node, attributes)}>${children}</a>`;
97
+ };
43
98
  };
44
- const serializeSpan = (content) => {
45
- return content ? escapeHTML.escapeHTML(content).replace(/\n/g, "<br />") : "";
99
+ const serializeSpan = () => {
100
+ return ({ text }) => {
101
+ return text ? escapeHTML.escapeHTML(text).replace(/\n/g, "<br />") : "";
102
+ };
46
103
  };
47
- exports.getLabel = getLabel;
48
104
  exports.serializeEmbed = serializeEmbed;
49
105
  exports.serializeHyperlink = serializeHyperlink;
50
106
  exports.serializeImage = serializeImage;
@@ -1 +1 @@
1
- {"version":3,"file":"serializerHelpers.cjs","sources":["../../../src/lib/serializerHelpers.ts"],"sourcesContent":["import { LinkType } from \"../types/value/link\";\nimport {\n\tRTBlockNode,\n\tRTEmbedNode,\n\tRTImageNode,\n\tRTInlineNode,\n\tRTLinkNode,\n\tRTPreformattedNode,\n\tRichTextNodeType,\n} from \"../types/value/richText\";\n\nimport { LinkResolverFunction, asLink } from \"../helpers/asLink\";\n\nimport { escapeHTML } from \"./escapeHTML\";\n\nexport const getLabel = (node: RTBlockNode | RTInlineNode): string => {\n\treturn \"data\" in node && \"label\" in node.data\n\t\t? ` class=\"${node.data.label}\"`\n\t\t: \"\";\n};\n\nexport const serializeStandardTag = (\n\ttag: string,\n\tnode: RTBlockNode | RTInlineNode,\n\tchildren: string[],\n): string => {\n\treturn `<${tag}${getLabel(node)}>${children.join(\"\")}</${tag}>`;\n};\n\nexport const serializePreFormatted = (node: RTPreformattedNode): string => {\n\treturn `<pre${getLabel(node)}>${escapeHTML(node.text)}</pre>`;\n};\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tnode: RTImageNode,\n): string => {\n\tlet imageTag = `<img src=\"${node.url}\" alt=\"${escapeHTML(node.alt)}\"${\n\t\tnode.copyright ? ` copyright=\"${escapeHTML(node.copyright)}\"` : \"\"\n\t} />`;\n\n\t// If the image has a link, we wrap it with an anchor tag\n\tif (node.linkTo) {\n\t\timageTag = serializeHyperlink(\n\t\t\tlinkResolver,\n\t\t\t{\n\t\t\t\ttype: RichTextNodeType.hyperlink,\n\t\t\t\tdata: node.linkTo,\n\t\t\t\tstart: 0,\n\t\t\t\tend: 0,\n\t\t\t},\n\t\t\t[imageTag],\n\t\t);\n\t}\n\n\treturn `<p class=\"block-img\">${imageTag}</p>`;\n};\n\nexport const serializeEmbed = (node: RTEmbedNode): string => {\n\treturn `<div data-oembed=\"${node.oembed.embed_url}\" data-oembed-type=\"${\n\t\tnode.oembed.type\n\t}\" data-oembed-provider=\"${node.oembed.provider_name}\"${getLabel(node)}>${\n\t\tnode.oembed.html\n\t}</div>`;\n};\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tnode: RTLinkNode,\n\tchildren: string[],\n): string => {\n\tswitch (node.data.link_type) {\n\t\tcase LinkType.Web: {\n\t\t\treturn `<a href=\"${escapeHTML(node.data.url)}\" ${\n\t\t\t\tnode.data.target ? `target=\"${node.data.target}\" ` : \"\"\n\t\t\t}rel=\"noopener noreferrer\"${getLabel(node)}>${children.join(\"\")}</a>`;\n\t\t}\n\n\t\tcase LinkType.Document: {\n\t\t\treturn `<a href=\"${asLink(node.data, linkResolver)}\"${getLabel(\n\t\t\t\tnode,\n\t\t\t)}>${children.join(\"\")}</a>`;\n\t\t}\n\n\t\tcase LinkType.Media: {\n\t\t\treturn `<a href=\"${node.data.url}\"${getLabel(node)}>${children.join(\n\t\t\t\t\"\",\n\t\t\t)}</a>`;\n\t\t}\n\t}\n};\n\nexport const serializeSpan = (content?: string): string => {\n\treturn content ? escapeHTML(content).replace(/\\n/g, \"<br />\") : \"\";\n};\n"],"names":["escapeHTML","RichTextNodeType","LinkType","asLink"],"mappings":";;;;;;AAea,MAAA,WAAW,CAAC,SAA4C;AAC7D,SAAA,UAAU,QAAQ,WAAW,KAAK,OACtC,WAAW,KAAK,KAAK,KAAK,MAC1B;AACJ;AAEO,MAAM,uBAAuB,CACnC,KACA,MACA,aACW;AACX,SAAO,IAAI,GAAG,GAAG,SAAS,IAAI,CAAC,IAAI,SAAS,KAAK,EAAE,CAAC,KAAK,GAAG;AAC7D;AAEa,MAAA,wBAAwB,CAAC,SAAoC;AAClE,SAAA,OAAO,SAAS,IAAI,CAAC,IAAIA,WAAW,WAAA,KAAK,IAAI,CAAC;AACtD;AAEa,MAAA,iBAAiB,CAC7B,cAIA,SACW;AACX,MAAI,WAAW,aAAa,KAAK,GAAG,UAAUA,sBAAW,KAAK,GAAG,CAAC,IACjE,KAAK,YAAY,eAAeA,WAAAA,WAAW,KAAK,SAAS,CAAC,MAAM,EACjE;AAGA,MAAI,KAAK,QAAQ;AAChB,eAAW,mBACV,cACA;AAAA,MACC,MAAMC,SAAiB,iBAAA;AAAA,MACvB,MAAM,KAAK;AAAA,MACX,OAAO;AAAA,MACP,KAAK;AAAA,IAAA,GAEN,CAAC,QAAQ,CAAC;AAAA,EAEX;AAED,SAAO,wBAAwB,QAAQ;AACxC;AAEa,MAAA,iBAAiB,CAAC,SAA6B;AAC3D,SAAO,qBAAqB,KAAK,OAAO,SAAS,uBAChD,KAAK,OAAO,IACb,2BAA2B,KAAK,OAAO,aAAa,IAAI,SAAS,IAAI,CAAC,IACrE,KAAK,OAAO,IACb;AACD;AAEO,MAAM,qBAAqB,CACjC,cAIA,MACA,aACW;AACH,UAAA,KAAK,KAAK,WAAW;AAAA,IAC5B,KAAKC,KAAAA,SAAS,KAAK;AACX,aAAA,YAAYF,WAAAA,WAAW,KAAK,KAAK,GAAG,CAAC,KAC3C,KAAK,KAAK,SAAS,WAAW,KAAK,KAAK,MAAM,OAAO,EACtD,4BAA4B,SAAS,IAAI,CAAC,IAAI,SAAS,KAAK,EAAE,CAAC;AAAA,IAC/D;AAAA,IAED,KAAKE,KAAAA,SAAS,UAAU;AACvB,aAAO,YAAYC,OAAA,OAAO,KAAK,MAAM,YAAY,CAAC,IAAI,SACrD,IAAI,CACJ,IAAI,SAAS,KAAK,EAAE,CAAC;AAAA,IACtB;AAAA,IAED,KAAKD,KAAAA,SAAS,OAAO;AACpB,aAAO,YAAY,KAAK,KAAK,GAAG,IAAI,SAAS,IAAI,CAAC,IAAI,SAAS,KAC9D,EAAE,CACF;AAAA,IACD;AAAA,EACD;AACF;AAEa,MAAA,gBAAgB,CAAC,YAA4B;AACzD,SAAO,UAAUF,WAAW,WAAA,OAAO,EAAE,QAAQ,OAAO,QAAQ,IAAI;AACjE;;;;;;;;"}
1
+ {"version":3,"file":"serializerHelpers.cjs","sources":["../../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\";\nimport { LinkType } from \"../types/value/link\";\nimport { RTAnyNode } from \"../types/value/richText\";\n\nimport {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\";\nimport { LinkResolverFunction, asLink } from \"../helpers/asLink\";\n\nimport { escapeHTML } from \"./escapeHTML\";\n\ntype Attributes = Record<string, string | boolean | null | undefined>;\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes };\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label;\n\t}\n\n\tconst result = [];\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key];\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key);\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\");\n\t}\n\n\treturn result.join(\" \");\n};\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {};\n};\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand);\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`;\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>;\n};\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand);\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`;\n\t};\n};\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand);\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t};\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`;\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!;\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`;\n\t};\n};\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand);\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t};\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${\n\t\t\tnode.oembed.html\n\t\t}</div>`;\n\t};\n};\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand);\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t};\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url;\n\t\t\tattributes.target = node.data.target;\n\t\t\tattributes.rel = \"noopener noreferrer\";\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver });\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url;\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`;\n\t};\n};\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\";\n\t};\n};\n"],"names":["escapeHTML","LinkType","asLink"],"mappings":";;;;;AAaA,MAAM,mBAAmB,CAAC,MAAiB,eAAkC;AACtE,QAAA,cAAc,EAAE,GAAG;AAGzB,MAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,OAAO;AAC9D,gBAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,KAAK,IAAI,KAAK,KAAK,KAAK,KACvC,KAAK,KAAK;AAAA,EACb;AAED,QAAM,SAAS,CAAA;AAEf,aAAW,OAAO,aAAa;AACxB,UAAA,QAAQ,YAAY,GAAG;AAE7B,QAAI,OAAO;AACN,UAAA,OAAO,UAAU,WAAW;AAC/B,eAAO,KAAK,GAAG;AAAA,MAAA,OACT;AACN,eAAO,KAAK,GAAG,GAAG,KAAKA,WAAAA,WAAW,KAAK,CAAC,GAAG;AAAA,MAC3C;AAAA,IACD;AAAA,EACD;AAGD,MAAI,OAAO,QAAQ;AAClB,WAAO,QAAQ,EAAE;AAAA,EACjB;AAEM,SAAA,OAAO,KAAK,GAAG;AACvB;AAEA,MAAM,uBAAuB,CAC5B,0BACe;AACf,SAAO,yBAAyB,OAAO,0BAA0B,aAC9D,wBACA,CAAA;AACJ;AAEa,MAAA,uBAAuB,CAGnC,KACA,0BAC4D;AACtD,QAAA,oBAAoB,qBAAqB,qBAAqB;AAEpE,SAAQ,CAAC,EAAE,MAAM,eAAc;AACvB,WAAA,IAAI,GAAG,GAAG,iBAChB,MACA,iBAAiB,CACjB,IAAI,QAAQ,KAAK,GAAG;AAAA,EAAA;AAEvB;AAEa,MAAA,wBAAwB,CACpC,0BACiE;AAC3D,QAAA,oBAAoB,qBAAqB,qBAAqB;AAE7D,SAAA,CAAC,EAAE,WAAU;AACZ,WAAA,OAAO,iBAAiB,MAAM,iBAAiB,CAAC,IAAIA,WAAAA,WAC1D,KAAK,IAAI,CACT;AAAA,EAAA;AAEH;AAEa,MAAA,iBAAiB,CAC7B,cAIA,0BAC0D;AACpD,QAAA,oBAAoB,qBAAqB,qBAAqB;AAE7D,SAAA,CAAC,EAAE,WAAU;AACnB,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA,MACH,KAAK,KAAK;AAAA,MACV,KAAK,KAAK;AAAA,MACV,WAAW,KAAK;AAAA,IAAA;AAGjB,QAAI,WAAW,OAAO,iBAAiB,MAAM,UAAU,CAAC;AAGxD,QAAI,KAAK,QAAQ;AACL,iBAAA,mBAAmB,YAAY,EAAE;AAAA,QAC3C,MAAM;AAAA,QACN,MAAM;AAAA,UACL,MAAM;AAAA,UACN,MAAM,KAAK;AAAA,UACX,OAAO;AAAA,UACP,KAAK;AAAA,QACL;AAAA,QACD,MAAM;AAAA,QACN,UAAU;AAAA,QACV,KAAK;AAAA,MAAA,CACL;AAAA,IACD;AAED,WAAO,wBAAwB,QAAQ;AAAA,EAAA;AAEzC;AAEa,MAAA,iBAAiB,CAC7B,0BAC0D;AACpD,QAAA,oBAAoB,qBAAqB,qBAAqB;AAE7D,SAAA,CAAC,EAAE,WAAU;AACnB,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA,MACH,CAAC,aAAa,GAAG,KAAK,OAAO;AAAA,MAC7B,CAAC,kBAAkB,GAAG,KAAK,OAAO;AAAA,MAClC,CAAC,sBAAsB,GAAG,KAAK,OAAO;AAAA,IAAA;AAGhC,WAAA,OAAO,iBAAiB,MAAM,UAAU,CAAC,IAC/C,KAAK,OAAO,IACb;AAAA,EAAA;AAEF;AAEa,MAAA,qBAAqB,CACjC,cAIA,0BAC8D;AACxD,QAAA,oBAAoB,qBAAqB,qBAAqB;AAEpE,SAAO,CAAC,EAAE,MAAM,eAAsB;AACrC,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA,IAAA;AAGJ,QAAI,KAAK,KAAK,cAAcC,KAAAA,SAAS,KAAK;AAC9B,iBAAA,OAAO,KAAK,KAAK;AACjB,iBAAA,SAAS,KAAK,KAAK;AAC9B,iBAAW,MAAM;AAAA,IACP,WAAA,KAAK,KAAK,cAAcA,KAAAA,SAAS,UAAU;AACrD,iBAAW,OAAOC,cAAO,KAAK,MAAM,EAAE,cAAc;AAAA,IAC1C,WAAA,KAAK,KAAK,cAAcD,KAAAA,SAAS,OAAO;AACvC,iBAAA,OAAO,KAAK,KAAK;AAAA,IAC5B;AAED,WAAO,KAAK,iBAAiB,MAAM,UAAU,CAAC,IAAI,QAAQ;AAAA,EAAA;AAE5D;AAEO,MAAM,gBAAgB,MAEzB;AACI,SAAA,CAAC,EAAE,WAAkB;AAC3B,WAAO,OAAOD,WAAW,WAAA,IAAI,EAAE,QAAQ,OAAO,QAAQ,IAAI;AAAA,EAAA;AAE5D;;;;;;;"}