@prismicio/types-internal 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/content/fields/RepeatableContent.d.ts +162 -0
- package/lib/content/fields/RepeatableContent.js +93 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +727 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
- package/lib/customtypes/widgets/nestable/Link.js +6 -0
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +327 -0
- package/lib/customtypes/widgets/slices/SliceWidget.js +8 -0
- package/package.json +1 -1
- package/src/customtypes/widgets/nestable/Link.ts +17 -0
- package/CHANGELOG.md +0 -836
- package/lib/customtypes/widgets/nestable/NestableWidgetZ.d.ts +0 -3
- package/lib/customtypes/widgets/nestable/NestableWidgetZ.js +0 -29
- package/lib/customtypes/widgets/slices/SharedSliceZ.d.ts +0 -16
- package/lib/customtypes/widgets/slices/SharedSliceZ.js +0 -39
- package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.d.ts +0 -3
- package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.js +0 -6
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
|
|
3
|
+
import type { Link, NestableWidget } from "../../customtypes";
|
|
4
|
+
import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
|
|
5
|
+
export declare const RepeatableContent: t.ExactC<t.TypeC<{
|
|
6
|
+
__TYPE__: t.LiteralC<"RepeatableContent">;
|
|
7
|
+
type: t.LiteralC<"Link">;
|
|
8
|
+
value: t.ArrayC<t.ExactC<t.TypeC<{
|
|
9
|
+
__TYPE__: t.LiteralC<"LinkContent">;
|
|
10
|
+
value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
11
|
+
__TYPE__: t.LiteralC<"ImageLink">;
|
|
12
|
+
}>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
13
|
+
kind: t.StringC;
|
|
14
|
+
id: t.StringC;
|
|
15
|
+
url: t.StringC;
|
|
16
|
+
height: t.StringC;
|
|
17
|
+
width: t.StringC;
|
|
18
|
+
size: t.StringC;
|
|
19
|
+
name: t.StringC;
|
|
20
|
+
}>>, t.ExactC<t.PartialC<{
|
|
21
|
+
date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
22
|
+
}>>]>, t.ExactC<t.PartialC<{
|
|
23
|
+
text: t.StringC;
|
|
24
|
+
}>>]>, t.ExactC<t.TypeC<{
|
|
25
|
+
kind: t.LiteralC<"image">;
|
|
26
|
+
text: t.StringC;
|
|
27
|
+
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
28
|
+
__TYPE__: t.LiteralC<"FileLink">;
|
|
29
|
+
}>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
30
|
+
kind: t.StringC;
|
|
31
|
+
id: t.StringC;
|
|
32
|
+
url: t.StringC;
|
|
33
|
+
name: t.StringC;
|
|
34
|
+
size: t.StringC;
|
|
35
|
+
}>, t.PartialC<{
|
|
36
|
+
date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
37
|
+
}>]>>, t.ExactC<t.PartialC<{
|
|
38
|
+
text: t.StringC;
|
|
39
|
+
}>>]>, t.ExactC<t.TypeC<{
|
|
40
|
+
kind: t.LiteralC<"file">;
|
|
41
|
+
text: t.StringC;
|
|
42
|
+
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
43
|
+
__TYPE__: t.LiteralC<"DocumentLink">;
|
|
44
|
+
}>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
45
|
+
id: t.Type<string, string, unknown>;
|
|
46
|
+
}>>, t.ExactC<t.PartialC<{
|
|
47
|
+
text: t.StringC;
|
|
48
|
+
}>>]>, t.ExactC<t.TypeC<{
|
|
49
|
+
kind: t.LiteralC<"document">;
|
|
50
|
+
text: t.StringC;
|
|
51
|
+
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
52
|
+
__TYPE__: t.LiteralC<"ExternalLink">;
|
|
53
|
+
}>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
54
|
+
url: t.StringC;
|
|
55
|
+
}>, t.PartialC<{
|
|
56
|
+
kind: t.LiteralC<"web">;
|
|
57
|
+
target: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
58
|
+
preview: t.UnionC<[t.Type<{
|
|
59
|
+
title?: string;
|
|
60
|
+
}, {
|
|
61
|
+
title?: string;
|
|
62
|
+
}, unknown>, t.NullC, t.UndefinedC]>;
|
|
63
|
+
}>]>>, t.ExactC<t.PartialC<{
|
|
64
|
+
text: t.StringC;
|
|
65
|
+
}>>]>, t.ExactC<t.TypeC<{
|
|
66
|
+
kind: t.LiteralC<"web">;
|
|
67
|
+
text: t.StringC;
|
|
68
|
+
}>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
69
|
+
__TYPE__: t.LiteralC<"MediaLink">;
|
|
70
|
+
}>>, t.ExactC<t.TypeC<{
|
|
71
|
+
kind: t.LiteralC<"media">;
|
|
72
|
+
text: t.StringC;
|
|
73
|
+
}>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
74
|
+
__TYPE__: t.LiteralC<"AnyLink">;
|
|
75
|
+
}>>, t.ExactC<t.TypeC<{
|
|
76
|
+
text: t.StringC;
|
|
77
|
+
}>>]>]>;
|
|
78
|
+
}>>>;
|
|
79
|
+
}>>;
|
|
80
|
+
export declare type RepeatableContent = t.TypeOf<typeof RepeatableContent>;
|
|
81
|
+
export declare const isRepeatableContent: t.Is<{
|
|
82
|
+
__TYPE__: "RepeatableContent";
|
|
83
|
+
type: "Link";
|
|
84
|
+
value: {
|
|
85
|
+
__TYPE__: "LinkContent";
|
|
86
|
+
value: ({
|
|
87
|
+
__TYPE__: "ImageLink";
|
|
88
|
+
} & (({
|
|
89
|
+
kind: string;
|
|
90
|
+
id: string;
|
|
91
|
+
url: string;
|
|
92
|
+
height: string;
|
|
93
|
+
width: string;
|
|
94
|
+
size: string;
|
|
95
|
+
name: string;
|
|
96
|
+
} & {
|
|
97
|
+
date?: string | null | undefined;
|
|
98
|
+
} & {
|
|
99
|
+
text?: string;
|
|
100
|
+
}) | {
|
|
101
|
+
kind: "image";
|
|
102
|
+
text: string;
|
|
103
|
+
})) | ({
|
|
104
|
+
__TYPE__: "FileLink";
|
|
105
|
+
} & (({
|
|
106
|
+
kind: string;
|
|
107
|
+
id: string;
|
|
108
|
+
url: string;
|
|
109
|
+
name: string;
|
|
110
|
+
size: string;
|
|
111
|
+
} & {
|
|
112
|
+
date?: string | null | undefined;
|
|
113
|
+
} & {
|
|
114
|
+
text?: string;
|
|
115
|
+
}) | {
|
|
116
|
+
kind: "file";
|
|
117
|
+
text: string;
|
|
118
|
+
})) | ({
|
|
119
|
+
__TYPE__: "MediaLink";
|
|
120
|
+
} & {
|
|
121
|
+
kind: "media";
|
|
122
|
+
text: string;
|
|
123
|
+
}) | ({
|
|
124
|
+
__TYPE__: "DocumentLink";
|
|
125
|
+
} & (({
|
|
126
|
+
id: string;
|
|
127
|
+
} & {
|
|
128
|
+
text?: string;
|
|
129
|
+
}) | {
|
|
130
|
+
kind: "document";
|
|
131
|
+
text: string;
|
|
132
|
+
})) | ({
|
|
133
|
+
__TYPE__: "ExternalLink";
|
|
134
|
+
} & (({
|
|
135
|
+
url: string;
|
|
136
|
+
} & {
|
|
137
|
+
kind?: "web";
|
|
138
|
+
target?: string | null | undefined;
|
|
139
|
+
preview?: {
|
|
140
|
+
title?: string;
|
|
141
|
+
} | null | undefined;
|
|
142
|
+
} & {
|
|
143
|
+
text?: string;
|
|
144
|
+
}) | {
|
|
145
|
+
kind: "web";
|
|
146
|
+
text: string;
|
|
147
|
+
})) | ({
|
|
148
|
+
__TYPE__: "AnyLink";
|
|
149
|
+
} & {
|
|
150
|
+
text: string;
|
|
151
|
+
});
|
|
152
|
+
}[];
|
|
153
|
+
}>;
|
|
154
|
+
export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: "Link") => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
|
|
155
|
+
export declare type RepeatableCustomType = Link;
|
|
156
|
+
export declare function traverseRepeatableContent({ path, key, apiId, model, content, }: {
|
|
157
|
+
path: ContentPath;
|
|
158
|
+
key: string;
|
|
159
|
+
apiId: string;
|
|
160
|
+
content: RepeatableContent;
|
|
161
|
+
model?: NestableWidget | undefined;
|
|
162
|
+
}): (transform: TraverseWidgetContentFn) => RepeatableContent | undefined;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fp_ts_1 = require("fp-ts");
|
|
6
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
7
|
+
const function_1 = require("fp-ts/lib/function");
|
|
8
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
|
+
const nestable_1 = require("./nestable");
|
|
10
|
+
exports.RepeatableContent = t.strict({
|
|
11
|
+
__TYPE__: t.literal("RepeatableContent"),
|
|
12
|
+
type: t.literal("Link"),
|
|
13
|
+
value: t.array(nestable_1.LinkContent),
|
|
14
|
+
});
|
|
15
|
+
exports.isRepeatableContent = exports.RepeatableContent.is;
|
|
16
|
+
const RepeatableLegacy = (ctx, fieldType) => {
|
|
17
|
+
return new t.Type("RepeatableLegacy", exports.isRepeatableContent, (items) => {
|
|
18
|
+
const parsed = (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.map((items) => {
|
|
19
|
+
const parsedItems = items.reduce((acc, item) => {
|
|
20
|
+
let result;
|
|
21
|
+
switch (fieldType) {
|
|
22
|
+
case "Link":
|
|
23
|
+
result = (0, nestable_1.LinkContentLegacy)(ctx).decode(item);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
if (!result)
|
|
27
|
+
return acc;
|
|
28
|
+
if ((0, Either_1.isLeft)(result))
|
|
29
|
+
return acc;
|
|
30
|
+
return [...acc, result.right];
|
|
31
|
+
}, []);
|
|
32
|
+
return {
|
|
33
|
+
value: parsedItems,
|
|
34
|
+
type: fieldType,
|
|
35
|
+
__TYPE__: "RepeatableContent",
|
|
36
|
+
};
|
|
37
|
+
}));
|
|
38
|
+
return parsed;
|
|
39
|
+
}, (r) => {
|
|
40
|
+
const res = t.array(nestable_1.LinkContent).encode(r.value);
|
|
41
|
+
const encodedItems = res.reduce((acc, item) => {
|
|
42
|
+
let encoded;
|
|
43
|
+
switch (item.__TYPE__) {
|
|
44
|
+
case nestable_1.LinkContentType:
|
|
45
|
+
encoded = (0, nestable_1.LinkContentLegacy)(ctx).encode(item);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
if (!encoded)
|
|
49
|
+
return acc;
|
|
50
|
+
return [...acc, encoded];
|
|
51
|
+
}, []);
|
|
52
|
+
return {
|
|
53
|
+
content: encodedItems.map((encodedItem) => encodedItem.content),
|
|
54
|
+
types: { [ctx.keyOfType]: `Repeatable.${fieldType}` },
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.RepeatableLegacy = RepeatableLegacy;
|
|
59
|
+
function traverseRepeatableContent({ path, key, apiId, model, content, }) {
|
|
60
|
+
return (transform) => {
|
|
61
|
+
const items = content.value.reduce((acc, fieldContent, index) => {
|
|
62
|
+
const itemPath = path.concat([
|
|
63
|
+
{ key: index.toString(), type: "Widget" },
|
|
64
|
+
]);
|
|
65
|
+
const transformedField = transform({
|
|
66
|
+
path: itemPath,
|
|
67
|
+
key: key,
|
|
68
|
+
apiId: apiId,
|
|
69
|
+
model: model,
|
|
70
|
+
content: fieldContent,
|
|
71
|
+
});
|
|
72
|
+
// Can happen if the transform function returns undefined to filter out a field
|
|
73
|
+
if (!transformedField)
|
|
74
|
+
return acc;
|
|
75
|
+
// If the transformed field is not a link content, we don't include it
|
|
76
|
+
if (!(0, nestable_1.isLinkContent)(transformedField))
|
|
77
|
+
return acc;
|
|
78
|
+
return acc.concat(transformedField);
|
|
79
|
+
}, []);
|
|
80
|
+
return transform({
|
|
81
|
+
path,
|
|
82
|
+
key,
|
|
83
|
+
apiId,
|
|
84
|
+
model,
|
|
85
|
+
content: {
|
|
86
|
+
__TYPE__: content.__TYPE__,
|
|
87
|
+
type: content.type,
|
|
88
|
+
value: items,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
exports.traverseRepeatableContent = traverseRepeatableContent;
|