@prismicio/types-internal 1.5.3 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/lib/common/WidgetKey.d.ts +3 -0
  2. package/lib/common/WidgetKey.js +8 -0
  3. package/lib/common/index.d.ts +1 -0
  4. package/lib/common/index.js +4 -0
  5. package/lib/content/Document.d.ts +4285 -2573
  6. package/lib/content/Document.js +87 -10
  7. package/lib/content/LegacyContentCtx.d.ts +41 -0
  8. package/lib/content/LegacyContentCtx.js +65 -0
  9. package/lib/content/fields/EmptyContent.d.ts +16 -0
  10. package/lib/content/fields/EmptyContent.js +30 -0
  11. package/lib/content/fields/GroupContent.d.ts +1063 -364
  12. package/lib/content/fields/GroupContent.js +65 -6
  13. package/lib/content/fields/UIDContent.d.ts +10 -1
  14. package/lib/content/fields/UIDContent.js +17 -4
  15. package/lib/content/fields/WidgetContent.d.ts +6820 -0
  16. package/lib/content/fields/WidgetContent.js +57 -0
  17. package/lib/content/fields/index.d.ts +1 -2989
  18. package/lib/content/fields/index.js +1 -18
  19. package/lib/content/fields/nestable/BooleanContent.d.ts +10 -1
  20. package/lib/content/fields/nestable/BooleanContent.js +17 -4
  21. package/lib/content/fields/nestable/EmbedContent.d.ts +56 -5
  22. package/lib/content/fields/nestable/EmbedContent.js +57 -6
  23. package/lib/content/fields/nestable/FieldContent/ColorContent.d.ts +18 -0
  24. package/lib/content/fields/nestable/FieldContent/ColorContent.js +34 -0
  25. package/lib/content/fields/nestable/FieldContent/DateContent.d.ts +18 -0
  26. package/lib/content/fields/nestable/FieldContent/DateContent.js +34 -0
  27. package/lib/content/fields/nestable/FieldContent/NumberContent.d.ts +18 -0
  28. package/lib/content/fields/nestable/FieldContent/NumberContent.js +34 -0
  29. package/lib/content/fields/nestable/FieldContent/RangeContent.d.ts +18 -0
  30. package/lib/content/fields/nestable/FieldContent/RangeContent.js +34 -0
  31. package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +18 -0
  32. package/lib/content/fields/nestable/FieldContent/SelectContent.js +34 -0
  33. package/lib/content/fields/nestable/FieldContent/TextContent.d.ts +18 -0
  34. package/lib/content/fields/nestable/FieldContent/TextContent.js +34 -0
  35. package/lib/content/fields/nestable/FieldContent/TimestampContent.d.ts +18 -0
  36. package/lib/content/fields/nestable/FieldContent/TimestampContent.js +34 -0
  37. package/lib/content/fields/nestable/FieldContent/common.d.ts +1 -0
  38. package/lib/content/fields/nestable/FieldContent/common.js +4 -0
  39. package/lib/content/fields/nestable/FieldContent/index.d.ts +49 -0
  40. package/lib/content/fields/nestable/FieldContent/index.js +38 -0
  41. package/lib/content/fields/nestable/FieldContent.d.ts +7 -1
  42. package/lib/content/fields/nestable/FieldContent.js +19 -4
  43. package/lib/content/fields/nestable/GeoPointContent.d.ts +19 -4
  44. package/lib/content/fields/nestable/GeoPointContent.js +22 -5
  45. package/lib/content/fields/nestable/ImageContent.d.ts +109 -11
  46. package/lib/content/fields/nestable/ImageContent.js +64 -6
  47. package/lib/content/fields/nestable/IntegrationFieldContent.d.ts +10 -1
  48. package/lib/content/fields/nestable/IntegrationFieldContent.js +20 -4
  49. package/lib/content/fields/nestable/LinkContent.d.ts +240 -87
  50. package/lib/content/fields/nestable/LinkContent.js +133 -36
  51. package/lib/content/fields/nestable/NestableContent.d.ts +711 -251
  52. package/lib/content/fields/nestable/NestableContent.js +116 -13
  53. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +594 -0
  54. package/lib/content/fields/nestable/RichTextContent/Blocks.js +151 -0
  55. package/lib/content/fields/nestable/RichTextContent/index.d.ts +489 -0
  56. package/lib/content/fields/nestable/RichTextContent/index.js +27 -0
  57. package/lib/content/fields/nestable/SeparatorContent.d.ts +8 -1
  58. package/lib/content/fields/nestable/SeparatorContent.js +15 -4
  59. package/lib/content/fields/slices/CompositeSliceContent.d.ts +296 -362
  60. package/lib/content/fields/slices/RepeatableContent.d.ts +148 -181
  61. package/lib/content/fields/slices/SharedSliceContent.d.ts +296 -362
  62. package/lib/content/fields/slices/SimpleSliceContent.d.ts +296 -362
  63. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1709 -0
  64. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +81 -0
  65. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +582 -0
  66. package/lib/content/fields/slices/Slice/RepeatableContent.js +18 -0
  67. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +1713 -0
  68. package/lib/content/fields/slices/Slice/SharedSliceContent.js +98 -0
  69. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +1429 -0
  70. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +24 -0
  71. package/lib/content/fields/slices/Slice/index.d.ts +3216 -0
  72. package/lib/content/fields/slices/Slice/index.js +41 -0
  73. package/lib/content/fields/slices/SliceItem.d.ts +3498 -0
  74. package/lib/content/fields/slices/SliceItem.js +61 -0
  75. package/lib/content/fields/slices/SlicesContent.d.ts +4243 -3576
  76. package/lib/content/fields/slices/SlicesContent.js +28 -18
  77. package/lib/content/fields/slices/index.d.ts +4 -3
  78. package/lib/content/fields/slices/index.js +4 -3
  79. package/lib/content/index.d.ts +1 -0
  80. package/lib/content/index.js +1 -0
  81. package/lib/content/utils.d.ts +10 -0
  82. package/lib/content/utils.js +19 -0
  83. package/lib/customtypes/CustomType.d.ts +366 -366
  84. package/lib/customtypes/CustomType.js +4 -7
  85. package/lib/customtypes/Section.d.ts +366 -366
  86. package/lib/customtypes/Section.js +2 -2
  87. package/lib/customtypes/diff/SharedSlice.d.ts +4 -4
  88. package/lib/customtypes/diff/Variation.d.ts +4 -4
  89. package/lib/customtypes/widgets/Group.d.ts +1 -0
  90. package/lib/customtypes/widgets/Group.js +6 -5
  91. package/lib/customtypes/widgets/UID.d.ts +1 -0
  92. package/lib/customtypes/widgets/UID.js +3 -2
  93. package/lib/customtypes/widgets/Widget.d.ts +384 -362
  94. package/lib/customtypes/widgets/Widget.js +29 -8
  95. package/lib/customtypes/widgets/index.d.ts +6 -7
  96. package/lib/customtypes/widgets/index.js +6 -11
  97. package/lib/customtypes/widgets/nestable/BooleanField.d.ts +10 -3
  98. package/lib/customtypes/widgets/nestable/BooleanField.js +6 -6
  99. package/lib/customtypes/widgets/nestable/Color.d.ts +8 -3
  100. package/lib/customtypes/widgets/nestable/Color.js +6 -6
  101. package/lib/customtypes/widgets/nestable/Date.d.ts +9 -3
  102. package/lib/customtypes/widgets/nestable/Date.js +6 -6
  103. package/lib/customtypes/widgets/nestable/Embed.d.ts +9 -3
  104. package/lib/customtypes/widgets/nestable/Embed.js +6 -6
  105. package/lib/customtypes/widgets/nestable/GeoPoint.d.ts +7 -3
  106. package/lib/customtypes/widgets/nestable/GeoPoint.js +6 -6
  107. package/lib/customtypes/widgets/nestable/Image.d.ts +25 -3
  108. package/lib/customtypes/widgets/nestable/Image.js +8 -8
  109. package/lib/customtypes/widgets/nestable/IntegrationField.d.ts +9 -3
  110. package/lib/customtypes/widgets/nestable/IntegrationField.js +6 -6
  111. package/lib/customtypes/widgets/nestable/Link.d.ts +14 -2
  112. package/lib/customtypes/widgets/nestable/Link.js +7 -6
  113. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -3
  114. package/lib/customtypes/widgets/nestable/NestableWidget.js +30 -30
  115. package/lib/customtypes/widgets/nestable/Number.d.ts +11 -3
  116. package/lib/customtypes/widgets/nestable/Number.js +6 -6
  117. package/lib/customtypes/widgets/nestable/Range.d.ts +11 -3
  118. package/lib/customtypes/widgets/nestable/Range.js +6 -6
  119. package/lib/customtypes/widgets/nestable/RichText.d.ts +1 -0
  120. package/lib/customtypes/widgets/nestable/RichText.js +3 -3
  121. package/lib/customtypes/widgets/nestable/Select.d.ts +10 -3
  122. package/lib/customtypes/widgets/nestable/Select.js +6 -6
  123. package/lib/customtypes/widgets/nestable/Separator.d.ts +7 -3
  124. package/lib/customtypes/widgets/nestable/Separator.js +6 -6
  125. package/lib/customtypes/widgets/nestable/Text.d.ts +9 -2
  126. package/lib/customtypes/widgets/nestable/Text.js +7 -6
  127. package/lib/customtypes/widgets/nestable/Timestamp.d.ts +9 -3
  128. package/lib/customtypes/widgets/nestable/Timestamp.js +6 -6
  129. package/lib/customtypes/widgets/nestable/index.d.ts +15 -15
  130. package/lib/customtypes/widgets/nestable/index.js +15 -31
  131. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +1 -0
  132. package/lib/customtypes/widgets/slices/CompositeSlice.js +7 -6
  133. package/lib/customtypes/widgets/slices/LegacySlice.js +2 -2
  134. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +1 -0
  135. package/lib/customtypes/widgets/slices/SharedSlice.js +7 -7
  136. package/lib/customtypes/widgets/slices/SharedSliceRef.js +2 -2
  137. package/lib/customtypes/widgets/slices/Slices.d.ts +364 -362
  138. package/lib/customtypes/widgets/slices/Slices.js +8 -8
  139. package/lib/customtypes/widgets/slices/SlicesTypes.d.ts +6 -5
  140. package/lib/customtypes/widgets/slices/SlicesTypes.js +8 -4
  141. package/lib/documents/DocumentData.d.ts +3 -14
  142. package/lib/documents/DocumentData.js +5 -60
  143. package/lib/documents/widgets/nestable/ImageContent.d.ts +1 -1
  144. package/lib/documents/widgets/nestable/ImageContent.js +2 -2
  145. package/lib/utils/Objects.d.ts +1 -0
  146. package/lib/utils/Objects.js +10 -1
  147. package/package.json +1 -1
  148. package/src/common/WidgetKey.ts +13 -0
  149. package/src/common/index.ts +1 -0
  150. package/src/content/Document.ts +129 -16
  151. package/src/content/LegacyContentCtx.ts +57 -0
  152. package/src/content/fields/EmptyContent.ts +45 -0
  153. package/src/content/fields/GroupContent.ts +103 -8
  154. package/src/content/fields/UIDContent.ts +33 -3
  155. package/src/content/fields/WidgetContent.ts +76 -0
  156. package/src/content/fields/index.ts +1 -23
  157. package/src/content/fields/nestable/BooleanContent.ts +32 -3
  158. package/src/content/fields/nestable/EmbedContent.ts +79 -8
  159. package/src/content/fields/nestable/FieldContent/ColorContent.ts +48 -0
  160. package/src/content/fields/nestable/FieldContent/DateContent.ts +48 -0
  161. package/src/content/fields/nestable/FieldContent/NumberContent.ts +48 -0
  162. package/src/content/fields/nestable/FieldContent/RangeContent.ts +48 -0
  163. package/src/content/fields/nestable/FieldContent/SelectContent.ts +48 -0
  164. package/src/content/fields/nestable/FieldContent/TextContent.ts +48 -0
  165. package/src/content/fields/nestable/FieldContent/TimestampContent.ts +48 -0
  166. package/src/content/fields/nestable/FieldContent/common.ts +1 -0
  167. package/src/content/fields/nestable/FieldContent/index.ts +40 -0
  168. package/src/content/fields/nestable/GeoPointContent.ts +38 -7
  169. package/src/content/fields/nestable/ImageContent.ts +91 -11
  170. package/src/content/fields/nestable/IntegrationFieldContent.ts +42 -3
  171. package/src/content/fields/nestable/LinkContent.ts +208 -47
  172. package/src/content/fields/nestable/NestableContent.ts +180 -24
  173. package/src/content/fields/nestable/RichTextContent/Blocks.ts +205 -0
  174. package/src/content/fields/nestable/RichTextContent/index.ts +43 -0
  175. package/src/content/fields/nestable/SeparatorContent.ts +26 -3
  176. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +118 -0
  177. package/src/content/fields/slices/{RepeatableContent.ts → Slice/RepeatableContent.ts} +7 -4
  178. package/src/content/fields/slices/Slice/SharedSliceContent.ts +129 -0
  179. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +30 -0
  180. package/src/content/fields/slices/Slice/index.ts +47 -0
  181. package/src/content/fields/slices/SliceItem.ts +83 -0
  182. package/src/content/fields/slices/SlicesContent.ts +47 -19
  183. package/src/content/fields/slices/index.ts +4 -3
  184. package/src/content/index.ts +1 -0
  185. package/src/content/utils.ts +20 -0
  186. package/src/customtypes/CustomType.ts +4 -10
  187. package/src/customtypes/Section.ts +1 -1
  188. package/src/customtypes/widgets/Group.ts +4 -4
  189. package/src/customtypes/widgets/UID.ts +3 -2
  190. package/src/customtypes/widgets/Widget.ts +53 -7
  191. package/src/customtypes/widgets/index.ts +6 -7
  192. package/src/customtypes/widgets/nestable/BooleanField.ts +7 -8
  193. package/src/customtypes/widgets/nestable/Color.ts +6 -8
  194. package/src/customtypes/widgets/nestable/Date.ts +7 -8
  195. package/src/customtypes/widgets/nestable/Embed.ts +7 -8
  196. package/src/customtypes/widgets/nestable/GeoPoint.ts +7 -8
  197. package/src/customtypes/widgets/nestable/Image.ts +9 -10
  198. package/src/customtypes/widgets/nestable/IntegrationField.ts +6 -8
  199. package/src/customtypes/widgets/nestable/Link.ts +7 -6
  200. package/src/customtypes/widgets/nestable/NestableWidget.ts +17 -18
  201. package/src/customtypes/widgets/nestable/Number.ts +7 -8
  202. package/src/customtypes/widgets/nestable/Range.ts +7 -8
  203. package/src/customtypes/widgets/nestable/RichText.ts +3 -2
  204. package/src/customtypes/widgets/nestable/Select.ts +7 -8
  205. package/src/customtypes/widgets/nestable/Separator.ts +7 -8
  206. package/src/customtypes/widgets/nestable/Text.ts +7 -6
  207. package/src/customtypes/widgets/nestable/Timestamp.ts +7 -8
  208. package/src/customtypes/widgets/nestable/index.ts +15 -15
  209. package/src/customtypes/widgets/slices/CompositeSlice.ts +5 -4
  210. package/src/customtypes/widgets/slices/LegacySlice.ts +1 -1
  211. package/src/customtypes/widgets/slices/SharedSlice.ts +5 -4
  212. package/src/customtypes/widgets/slices/SharedSliceRef.ts +2 -2
  213. package/src/customtypes/widgets/slices/Slices.ts +7 -6
  214. package/src/customtypes/widgets/slices/SlicesTypes.ts +10 -5
  215. package/src/utils/Objects.ts +12 -0
  216. package/src/content/fields/nestable/FieldContent.ts +0 -25
  217. package/src/content/fields/nestable/RichTextContent.ts +0 -32
  218. package/src/content/fields/slices/CompositeSliceContent.ts +0 -14
  219. package/src/content/fields/slices/SharedSliceContent.ts +0 -14
  220. package/src/content/fields/slices/SimpleSliceContent.ts +0 -7
  221. package/src/customtypes/widgets/WidgetTypes.ts +0 -24
  222. package/src/documents/DocumentData.ts +0 -112
  223. package/src/documents/index.ts +0 -2
  224. package/src/documents/widgets/EmptyContent.ts +0 -8
  225. package/src/documents/widgets/GroupContent.ts +0 -91
  226. package/src/documents/widgets/SimpleWidgetContent.ts +0 -96
  227. package/src/documents/widgets/StaticWidgetContent.ts +0 -46
  228. package/src/documents/widgets/UIDContent.ts +0 -18
  229. package/src/documents/widgets/index.ts +0 -70
  230. package/src/documents/widgets/nestable/BooleanContent.ts +0 -21
  231. package/src/documents/widgets/nestable/EmbedContent.ts +0 -56
  232. package/src/documents/widgets/nestable/FieldContent.ts +0 -53
  233. package/src/documents/widgets/nestable/GeoPointContent.ts +0 -18
  234. package/src/documents/widgets/nestable/ImageContent.ts +0 -51
  235. package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +0 -26
  236. package/src/documents/widgets/nestable/Link/DocumentLink.ts +0 -18
  237. package/src/documents/widgets/nestable/Link/ExternalLink.ts +0 -31
  238. package/src/documents/widgets/nestable/Link/FileLink.ts +0 -30
  239. package/src/documents/widgets/nestable/Link/ImageLink.ts +0 -31
  240. package/src/documents/widgets/nestable/Link/LinkContent.ts +0 -25
  241. package/src/documents/widgets/nestable/Link/index.ts +0 -35
  242. package/src/documents/widgets/nestable/SeparatorContent.ts +0 -13
  243. package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +0 -126
  244. package/src/documents/widgets/nestable/StructuredTextContent/index.ts +0 -25
  245. package/src/documents/widgets/nestable/index.ts +0 -35
  246. package/src/documents/widgets/slices/CompositeSliceContent.ts +0 -77
  247. package/src/documents/widgets/slices/SharedSliceContent.ts +0 -94
  248. package/src/documents/widgets/slices/SimpleSliceContent.ts +0 -4
  249. package/src/documents/widgets/slices/SliceWidgetContent.ts +0 -51
  250. package/src/documents/widgets/slices/SlicesContent.ts +0 -91
  251. package/src/documents/widgets/slices/index.ts +0 -5
  252. package/src/index.ts +0 -3
@@ -1,53 +0,0 @@
1
- import { pipe } from "fp-ts/function"
2
- import * as O from "fp-ts/Option"
3
- import * as t from "io-ts"
4
-
5
- export type FieldType =
6
- | "Text"
7
- | "Date"
8
- | "Timestamp"
9
- | "Color"
10
- | "Number"
11
- | "Range"
12
- | "Select"
13
- export const FieldContentType = "FieldContent"
14
- type FieldContent = {
15
- value: string
16
- type: FieldType
17
- __TYPE__: typeof FieldContentType
18
- }
19
-
20
- //we do that instead of idiomatic .trim()
21
- //because we need to have the exact same behaviour than scala/java .trim()
22
- //in other world only trim space and not non-breaking space or tab
23
- function trimScalaStyle(s: string): string {
24
- let startAt = 0
25
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
26
- while (startAt < s.length && s[startAt]! <= " ") {
27
- startAt++
28
- }
29
- let endAt = s.length
30
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
31
- while (startAt < endAt && s[endAt - 1]! <= " ") {
32
- endAt--
33
- }
34
- return s.substring(startAt, endAt)
35
- }
36
-
37
- const FieldContent = {
38
- types: ["Text", "Date", "Timestamp", "Color", "Number", "Range", "Select"],
39
- forType: (type: FieldType, value: unknown): O.Option<FieldContent> => {
40
- return pipe(
41
- O.fromEither(t.string.decode(value)),
42
- O.map((r) => {
43
- return {
44
- value: trimScalaStyle(r),
45
- type,
46
- __TYPE__: "FieldContent",
47
- }
48
- }),
49
- )
50
- },
51
- }
52
-
53
- export default FieldContent
@@ -1,18 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { addType } from "../../../validators/function"
4
-
5
- export const GeoPointContentType = "GeoPointContent"
6
-
7
- export const GeoPointContent = addType(
8
- t.strict({
9
- position: t.strict({
10
- lat: t.number,
11
- lng: t.number,
12
- }),
13
- }),
14
- GeoPointContentType,
15
- )
16
-
17
- export type GeoPointContent = t.TypeOf<typeof GeoPointContent>
18
- export type GeoPointContentO = t.OutputOf<typeof GeoPointContent>
@@ -1,51 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { NonEmptyStringOrNull, StringOrNull } from "../../../validators"
4
- import { addType } from "../../../validators/function"
5
-
6
- const Origin = t.exact(
7
- t.type({
8
- id: t.string,
9
- url: t.string,
10
- width: t.number,
11
- height: t.number,
12
- }),
13
- )
14
-
15
- export const ImageContentView = t.exact(
16
- t.intersection([
17
- t.type({
18
- origin: Origin,
19
- width: t.number,
20
- height: t.number,
21
- edit: t.type({
22
- zoom: t.number,
23
- crop: t.type({
24
- x: t.number,
25
- y: t.number,
26
- }),
27
- background: t.string,
28
- }),
29
- }),
30
- t.partial({
31
- url: t.string,
32
- credits: NonEmptyStringOrNull,
33
- alt: NonEmptyStringOrNull,
34
- provider: StringOrNull,
35
- }),
36
- ]),
37
- )
38
- export type ImageContentView = t.TypeOf<typeof ImageContentView>
39
-
40
- export const ImageContentType = "ImageContent"
41
- export const ImageContent = addType(
42
- t.intersection([
43
- ImageContentView,
44
- t.partial({
45
- thumbnails: t.record(t.string, ImageContentView),
46
- }),
47
- ]),
48
- ImageContentType,
49
- )
50
- export type ImageContent = t.TypeOf<typeof ImageContent>
51
- export type ImageContentO = t.OutputOf<typeof ImageContent>
@@ -1,26 +0,0 @@
1
- import { Chain } from "fp-ts/Either"
2
- import * as t from "io-ts"
3
-
4
- type IntegrationFieldsContent = {
5
- __TYPE__: "IntegrationFieldsContent"
6
- value: string
7
- }
8
-
9
- export const IntegrationFieldsContentType = "IntegrationFieldsContent"
10
- const IntegrationFieldsContent = new t.Type<IntegrationFieldsContent>(
11
- "IntegrationFieldsContent",
12
- (u): u is IntegrationFieldsContent =>
13
- (u as IntegrationFieldsContent)?.__TYPE__ === IntegrationFieldsContentType,
14
- (u, c) =>
15
- Chain.chain(t.string.validate(u, c), (u) => {
16
- return t.success({
17
- value: u,
18
- __TYPE__: IntegrationFieldsContentType,
19
- } as const)
20
- }),
21
- () => {
22
- throw new Error("Not implemented - Not used - Not relevant")
23
- },
24
- )
25
-
26
- export default IntegrationFieldsContent
@@ -1,18 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { NonEmptyString } from "../../../../validators"
4
- import { addType } from "../../../../validators/function"
5
-
6
- export const DocumentLinkType = "DocumentLink"
7
-
8
- export const DocumentLink = addType(
9
- t.strict({ id: NonEmptyString }),
10
- DocumentLinkType,
11
- )
12
-
13
- export type DocumentLink = t.TypeOf<typeof DocumentLink>
14
- export type DocumentLinkO = t.OutputOf<typeof DocumentLink>
15
-
16
- export function isDocumentLink(u: unknown): u is DocumentLinkO {
17
- return (u as DocumentLinkO).__TYPE__ === DocumentLinkType
18
- }
@@ -1,31 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { StringOrNull } from "../../../../validators"
4
- import { addType, nullable } from "../../../../validators/function"
5
-
6
- export const ExternalLinkType = "ExternalLink"
7
- export const ExternalLink = addType(
8
- t.exact(
9
- t.intersection([
10
- t.type({
11
- url: t.string,
12
- }),
13
- t.partial({
14
- kind: t.literal("web"),
15
- target: StringOrNull,
16
- preview: nullable(
17
- t.partial({
18
- title: t.string,
19
- }),
20
- ),
21
- }),
22
- ]),
23
- ),
24
- ExternalLinkType,
25
- )
26
-
27
- export type ExternalLink = t.TypeOf<typeof ExternalLink>
28
- export type ExternalLinkO = t.OutputOf<typeof ExternalLink>
29
- export function isExternalLink(u: unknown): u is ExternalLinkO {
30
- return (u as ExternalLinkO).__TYPE__ === ExternalLinkType
31
- }
@@ -1,30 +0,0 @@
1
- import * as t from "io-ts"
2
- import { withFallback } from "io-ts-types"
3
- import { mapOutput } from "io-ts-types/lib/mapOutput"
4
-
5
- import { nullable } from "../../../../validators/function"
6
-
7
- export const FileLinkType = "FileLink"
8
- export const FileLink = mapOutput(
9
- t.exact(
10
- t.intersection([
11
- t.type({
12
- id: t.string,
13
- url: t.string,
14
- name: t.string,
15
- kind: t.string,
16
- }),
17
- t.partial({
18
- date: nullable(t.string),
19
- size: withFallback(t.string, "0"),
20
- }),
21
- ]),
22
- ),
23
- (o) => ({ ...o, size: o.size || "0", __TYPE__: FileLinkType } as const),
24
- )
25
-
26
- export type FileLink = t.TypeOf<typeof FileLink>
27
- export type FileLinkO = t.OutputOf<typeof FileLink>
28
- export function isFileLink(u: unknown): u is FileLinkO {
29
- return (u as FileLinkO).__TYPE__ === FileLinkType
30
- }
@@ -1,31 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { StringOrNull } from "../../../../validators"
4
- import { addType } from "../../../../validators/function"
5
-
6
- export const ImageLinkType = "ImageLink"
7
- export const ImageLink = addType(
8
- t.exact(
9
- t.intersection([
10
- t.type({
11
- id: t.string,
12
- url: t.string,
13
- height: t.string,
14
- width: t.string,
15
- size: t.string,
16
- name: t.string,
17
- kind: t.string,
18
- }),
19
- t.partial({
20
- date: StringOrNull,
21
- }),
22
- ]),
23
- ),
24
- ImageLinkType,
25
- )
26
-
27
- export type ImageLink = t.TypeOf<typeof ImageLink>
28
- export type ImageLinkO = t.OutputOf<typeof ImageLink>
29
- export function isImageLink(u: unknown): u is ImageLinkO {
30
- return (u as ImageLinkO).__TYPE__ === ImageLinkType
31
- }
@@ -1,25 +0,0 @@
1
- import { Chain } from "fp-ts/Either"
2
- import * as t from "io-ts"
3
-
4
- import { Link, LinkO } from "./index"
5
-
6
- export type LinkContent = {
7
- __TYPE__: "LinkContent"
8
- value: LinkO
9
- }
10
-
11
- export const LinkContentType = "LinkContent"
12
- export const LinkContent = new t.Type<LinkContent, LinkO>(
13
- "LinkContent",
14
- (u): u is LinkContent => {
15
- return Link.is((u as LinkContent)?.value)
16
- },
17
- (u, c) =>
18
- Chain.chain(Link.validate(u, c), (u) => {
19
- return t.success({
20
- value: Link.encode(u),
21
- __TYPE__: LinkContentType,
22
- } as const)
23
- }),
24
- (linkContent) => Link.encode(linkContent.value),
25
- )
@@ -1,35 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- import { DocumentLink, DocumentLinkType, isDocumentLink } from "./DocumentLink"
4
- import { ExternalLink, ExternalLinkType, isExternalLink } from "./ExternalLink"
5
- import { FileLink, FileLinkType, isFileLink } from "./FileLink"
6
- import { ImageLink, ImageLinkType, isImageLink } from "./ImageLink"
7
- import { LinkContentType } from "./LinkContent"
8
-
9
- export const Link = t.union([ImageLink, FileLink, DocumentLink, ExternalLink])
10
- export type Link = t.TypeOf<typeof Link>
11
- export type LinkO = t.OutputOf<typeof Link>
12
-
13
- export { type DocumentLinkO, DocumentLink } from "./DocumentLink"
14
- export { type ExternalLinkO, ExternalLink } from "./ExternalLink"
15
- export { type FileLinkO, FileLink } from "./FileLink"
16
- export { type ImageLinkO, ImageLink } from "./ImageLink"
17
- export { LinkContent } from "./LinkContent"
18
-
19
- export const BROKEN_CUSTOM_TYPE = "broken_type"
20
-
21
- export const is = {
22
- documentLink: isDocumentLink,
23
- fileLink: isFileLink,
24
- externalLink: isExternalLink,
25
- imageLink: isImageLink,
26
- }
27
- export const LinksTypes = {
28
- DocumentLink: DocumentLinkType,
29
- FileLink: FileLinkType,
30
- ExternalLink: ExternalLinkType,
31
- ImageLink: ImageLinkType,
32
- LinkContent: LinkContentType,
33
- } as const
34
-
35
- export type LinksTypes = typeof LinksTypes[keyof typeof LinksTypes]
@@ -1,13 +0,0 @@
1
- import * as t from "io-ts"
2
-
3
- export const SeparatorContentType = "SeparatorContent"
4
- export type SeparatorContent = { __TYPE__: typeof SeparatorContentType }
5
- export const SeparatorContent = {
6
- codec: t.strict({
7
- __TYPE__: t.literal(SeparatorContentType),
8
- }),
9
- is(value: unknown): value is SeparatorContent {
10
- const asFieldContent = value as SeparatorContent
11
- return asFieldContent.__TYPE__ === "SeparatorContent"
12
- },
13
- }
@@ -1,126 +0,0 @@
1
- import * as E from "fp-ts/lib/Either"
2
- import * as t from "io-ts"
3
-
4
- import {
5
- RichTextNodeType,
6
- RichTextNodeTypeCodec,
7
- } from "../../../../customtypes/widgets/nestable"
8
- import { StringOrNull } from "../../../../validators"
9
- import { nullable, refineType } from "../../../../validators/function"
10
- import { EmbedContent } from "../EmbedContent"
11
- import { ImageContentView } from "../ImageContent"
12
- import { Link } from "../Link"
13
-
14
- export const Meta = t.exact(
15
- t.intersection([
16
- t.partial({
17
- data: t.unknown,
18
- }),
19
- t.type({
20
- start: t.number,
21
- end: t.number,
22
- type: t.union([RichTextNodeTypeCodec, t.literal("label")]),
23
- }),
24
- ]),
25
- )
26
- export type Meta = t.TypeOf<typeof Meta>
27
-
28
- // export alias for code clarity
29
- export const Span = Meta
30
- export type Span = Meta
31
-
32
- export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
33
- "ValidatedMetas",
34
- (metas): metas is Meta[] => Array.isArray(metas) && metas.every(Meta.is),
35
- (metas: unknown, c) => {
36
- if (Array.isArray(metas)) {
37
- const res = metas
38
- .reduce<Array<Meta>>((acc, maybeMeta) => {
39
- const maybeDecodedMeta = Meta.decode(maybeMeta)
40
- if (E.isRight(maybeDecodedMeta)) {
41
- const meta = maybeDecodedMeta.right
42
- // if it's an hyperlink it should have data validated as link otherwise we don't care and keep the meta
43
- if (
44
- (meta.data &&
45
- meta.type === "hyperlink" &&
46
- E.isRight(Link.validate(meta.data, c))) ||
47
- meta.type !== "hyperlink"
48
- ) {
49
- return [...acc, meta]
50
- }
51
- }
52
- return acc
53
- }, [])
54
- .sort((m1: Meta, m2: Meta) => m1.start - m2.start)
55
- return t.success(res)
56
- } else return t.failure(metas, c)
57
- },
58
- (m) => t.array(Meta).encode(m),
59
- )
60
-
61
- export const ImageBlock = t.exact(
62
- t.intersection([
63
- t.type({
64
- type: t.literal(RichTextNodeType.image),
65
- data: t.intersection([
66
- ImageContentView,
67
- t.partial({
68
- linkTo: nullable(Link),
69
- }),
70
- ]),
71
- }),
72
- t.partial({
73
- label: StringOrNull,
74
- direction: StringOrNull,
75
- }),
76
- ]),
77
- )
78
- export type ImageBlock = t.TypeOf<typeof ImageBlock>
79
- export function checkImageBlock(block: Block): block is ImageBlock {
80
- return block.type === RichTextNodeType.image
81
- }
82
-
83
- export const EmbedBlock = t.exact(
84
- t.intersection([
85
- t.type({
86
- type: t.literal(RichTextNodeType.embed),
87
- data: EmbedContent,
88
- }),
89
- t.partial({
90
- label: StringOrNull,
91
- direction: StringOrNull,
92
- }),
93
- ]),
94
- )
95
- export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
96
- export function checkEmbedBlock(block: Block): block is EmbedBlock {
97
- return block.type === RichTextNodeType.embed
98
- }
99
-
100
- export const TextBlock = t.exact(
101
- t.intersection([
102
- t.type({
103
- type: refineType(
104
- RichTextNodeTypeCodec,
105
- `string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
106
- (s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
107
- ),
108
- content: t.intersection([
109
- t.type({
110
- text: t.string,
111
- }),
112
- t.partial({
113
- spans: ValidatedMetas,
114
- }),
115
- ]),
116
- }),
117
- t.partial({
118
- label: t.string,
119
- direction: t.string,
120
- }),
121
- ]),
122
- )
123
- export type TextBlock = t.TypeOf<typeof TextBlock>
124
-
125
- export const Block = t.union([ImageBlock, EmbedBlock, TextBlock])
126
- export type Block = t.TypeOf<typeof Block>
@@ -1,25 +0,0 @@
1
- import { Chain } from "fp-ts/Either"
2
- import * as t from "io-ts"
3
-
4
- import { Block } from "./Block"
5
-
6
- export const StructuredTextContentType = "StructuredTextContent"
7
- export type StructuredTextContent = {
8
- value: Block[]
9
- __TYPE__: typeof StructuredTextContentType
10
- }
11
-
12
- export const StructuredTextContent = new t.Type<StructuredTextContent, string>(
13
- StructuredTextContentType,
14
- (u): u is StructuredTextContent =>
15
- (u as StructuredTextContent)?.__TYPE__ === StructuredTextContentType,
16
- (u, c) =>
17
- Chain.chain(t.array(Block).validate(u, c), (u) => {
18
- return t.success({ value: u, __TYPE__: StructuredTextContentType })
19
- }),
20
- () => {
21
- throw new Error("NotImplementedError: Not relevant method")
22
- },
23
- )
24
-
25
- export * as Blocks from "./Block"
@@ -1,35 +0,0 @@
1
- import { BooleanContentType } from "./BooleanContent"
2
- import { EmbedContentType } from "./EmbedContent"
3
- import { FieldContentType } from "./FieldContent"
4
- import { GeoPointContentType } from "./GeoPointContent"
5
- import { ImageContentType } from "./ImageContent"
6
- import { IntegrationFieldsContentType } from "./IntegrationFieldsContent"
7
- import { LinksTypes } from "./Link"
8
- import { SeparatorContentType } from "./SeparatorContent"
9
- import { StructuredTextContentType } from "./StructuredTextContent"
10
-
11
- export { default as BooleanContent } from "./BooleanContent"
12
- export * from "./EmbedContent"
13
- export { default as FieldContent } from "./FieldContent"
14
- export { type GeoPointContentO, GeoPointContent } from "./GeoPointContent"
15
- export {
16
- type ImageContentO,
17
- ImageContent,
18
- ImageContentView,
19
- } from "./ImageContent"
20
- export { default as IntegrationFieldsContent } from "./IntegrationFieldsContent"
21
- export * as Links from "./Link"
22
- export * from "./SeparatorContent"
23
- export * from "./StructuredTextContent"
24
-
25
- export const NestableTypes = {
26
- Links: LinksTypes,
27
- StructuredText: StructuredTextContentType,
28
- Boolean: BooleanContentType,
29
- Embed: EmbedContentType,
30
- Field: FieldContentType,
31
- GeoPoint: GeoPointContentType,
32
- Image: ImageContentType,
33
- IntegrationFields: IntegrationFieldsContentType,
34
- Separator: SeparatorContentType,
35
- } as const
@@ -1,77 +0,0 @@
1
- import { isRight } from "fp-ts/Either"
2
- import * as O from "fp-ts/Option"
3
- import * as t from "io-ts"
4
-
5
- import type { GroupItemContent } from "../GroupContent"
6
- import { GroupContent, SimpleWidgetContent } from "../index"
7
-
8
- export const CompositeSliceContentType = "CompositeSliceContent"
9
- export type CompositeSliceContent = {
10
- repeat: GroupItemContent[]
11
- nonRepeat: { [key: string]: SimpleWidgetContent }
12
- __TYPE__: typeof CompositeSliceContentType
13
- }
14
-
15
- const codec = t.exact(
16
- t.partial({
17
- repeat: t.array(t.unknown),
18
- "non-repeat": t.UnknownRecord,
19
- }),
20
- )
21
-
22
- export const CompositeSliceContent = {
23
- fromJson: (
24
- prefixes: Array<string>,
25
- key: string,
26
- value: unknown,
27
- fieldTypes: Map<string, string>,
28
- fieldPositions: Map<string, number>,
29
- ): O.Option<CompositeSliceContent> => {
30
- const prefixedRepeatKey = Array.of(prefixes, [key, "repeat"])
31
- .flat()
32
- .join(".")
33
-
34
- const decodedValue = codec.decode(value)
35
- if (isRight(decodedValue)) {
36
- const repeatObj = decodedValue.right.repeat
37
- const nonRepeatObj = decodedValue.right["non-repeat"] ?? {}
38
- const groupItemsContentsRepeat = GroupContent.itemsContentsFromJson(
39
- prefixedRepeatKey,
40
- repeatObj,
41
- fieldTypes,
42
- fieldPositions,
43
- )
44
- const sortedFields = Object.entries(nonRepeatObj).sort(([k1], [k2]) => {
45
- const p1 =
46
- fieldPositions.get(
47
- `${Array.of(prefixes, [key]).flat().join(".")}.${k1}`,
48
- ) ?? 10000
49
- const p2 =
50
- fieldPositions.get(
51
- `${Array.of(prefixes, [key]).flat().join(".")}.${k2}`,
52
- ) ?? 10000
53
- return p1 - p2
54
- })
55
-
56
- const nonRepeat = sortedFields.reduce((acc, [k, v]) => {
57
- const kp = Array.of(prefixes, [key, "non-repeat", k]).flat().join(".")
58
- const kind = fieldTypes.get(kp)
59
- if (kind) {
60
- const mWidgetContent = SimpleWidgetContent.from(kind, v)
61
- if (O.isSome(mWidgetContent)) {
62
- acc[k] = mWidgetContent.value
63
- }
64
- }
65
- return acc
66
- }, {} as Record<string, SimpleWidgetContent>)
67
-
68
- return O.some({
69
- repeat: groupItemsContentsRepeat,
70
- nonRepeat,
71
- __TYPE__: "CompositeSliceContent",
72
- })
73
- } else {
74
- return O.none
75
- }
76
- },
77
- }