@prismicio/types-internal 2.2.1 → 2.3.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/Document.d.ts +10 -4
- package/lib/content/Document.js +45 -11
- package/lib/content/fields/GroupContent.d.ts +1 -0
- package/lib/content/fields/GroupContent.js +13 -1
- package/lib/content/fields/nestable/BooleanContent.d.ts +2 -0
- package/lib/content/fields/nestable/BooleanContent.js +11 -1
- package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +2 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +12 -1
- package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
- package/lib/content/fields/nestable/NestableContent.js +12 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +13 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +2 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +16 -1
- package/lib/content/fields/slices/SliceItem.d.ts +3 -0
- package/lib/content/fields/slices/SliceItem.js +24 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +1 -0
- package/lib/content/fields/slices/SlicesContent.js +23 -1
- package/lib/content/fields/withDefaultValues.d.ts +6 -0
- package/lib/content/fields/withDefaultValues.js +38 -0
- package/lib/import/converters/Document.d.ts +4 -0
- package/lib/import/converters/Document.js +21 -0
- package/lib/import/converters/fields/Group.d.ts +4 -0
- package/lib/import/converters/fields/Group.js +14 -0
- package/lib/import/converters/fields/RepeatableZone.d.ts +317 -0
- package/lib/import/converters/fields/RepeatableZone.js +15 -0
- package/lib/import/converters/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/converters/fields/RepeatableZoneItem.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +23 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/UID.d.ts +3 -0
- package/lib/import/converters/fields/UID.js +10 -0
- package/lib/import/converters/fields/index.d.ts +4 -0
- package/lib/import/converters/fields/index.js +7 -0
- package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Boolean.js +12 -0
- package/lib/import/converters/fields/nestable/Color.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Color.js +13 -0
- package/lib/import/converters/fields/nestable/Date.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Date.js +15 -0
- package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Embed.js +32 -0
- package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +28 -0
- package/lib/import/converters/fields/nestable/Image.js +67 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Link.js +70 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +5 -0
- package/lib/import/converters/fields/nestable/Nestable.js +35 -0
- package/lib/import/converters/fields/nestable/Number.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Number.js +13 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
- package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +54 -0
- package/lib/import/converters/fields/nestable/Select.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Select.js +13 -0
- package/lib/import/converters/fields/nestable/Text.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Text.js +13 -0
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Timestamp.js +13 -0
- package/lib/import/converters/fields/nestable/index.d.ts +13 -0
- package/lib/import/converters/fields/nestable/index.js +16 -0
- package/lib/import/converters/index.d.ts +2 -0
- package/lib/import/converters/index.js +5 -0
- package/lib/import/index.d.ts +2 -0
- package/lib/import/index.js +5 -0
- package/lib/import/validators/Document.d.ts +6 -0
- package/lib/import/validators/Document.js +64 -0
- package/lib/import/validators/fields/ImportContent.d.ts +5 -0
- package/lib/import/validators/fields/ImportContent.js +21 -0
- package/lib/import/validators/fields/ImportField.d.ts +141 -0
- package/lib/import/validators/fields/ImportField.js +33 -0
- package/lib/import/validators/fields/ImportGroup.d.ts +345 -0
- package/lib/import/validators/fields/ImportGroup.js +27 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +16 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +342 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/RepeatableZone.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZone.js +14 -0
- package/lib/import/validators/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZoneItem.js +39 -0
- package/lib/import/validators/fields/UID.d.ts +6 -0
- package/lib/import/validators/fields/UID.js +15 -0
- package/lib/import/validators/fields/index.d.ts +4 -0
- package/lib/import/validators/fields/index.js +7 -0
- package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Boolean.js +6 -0
- package/lib/import/validators/fields/nestable/Color.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Color.js +15 -0
- package/lib/import/validators/fields/nestable/Date.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Date.js +19 -0
- package/lib/import/validators/fields/nestable/Embed.d.ts +13 -0
- package/lib/import/validators/fields/nestable/Embed.js +31 -0
- package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
- package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
- package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
- package/lib/import/validators/fields/nestable/Image/default.js +19 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +32 -0
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Image/validators.d.ts +132 -0
- package/lib/import/validators/fields/nestable/Image/validators.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +32 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +22 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +13 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +78 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +79 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +27 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +12 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +16 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +15 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +20 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +53 -0
- package/lib/import/validators/fields/nestable/Link.js +35 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +192 -0
- package/lib/import/validators/fields/nestable/Nestable.js +71 -0
- package/lib/import/validators/fields/nestable/Number.d.ts +17 -0
- package/lib/import/validators/fields/nestable/Number.js +17 -0
- package/lib/import/validators/fields/nestable/Select.d.ts +16 -0
- package/lib/import/validators/fields/nestable/Select.js +19 -0
- package/lib/import/validators/fields/nestable/Text.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Text.js +6 -0
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +7 -0
- package/lib/import/validators/fields/nestable/Timestamp.js +19 -0
- package/lib/import/validators/fields/nestable/index.d.ts +14 -0
- package/lib/import/validators/fields/nestable/index.js +19 -0
- package/lib/import/validators/index.d.ts +2 -0
- package/lib/import/validators/index.js +5 -0
- package/package.json +1 -1
- package/src/content/Document.ts +68 -14
- package/src/content/fields/GroupContent.ts +16 -0
- package/src/content/fields/nestable/BooleanContent.ts +11 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +12 -1
- package/src/content/fields/nestable/NestableContent.ts +16 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +25 -0
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +32 -1
- package/src/content/fields/slices/SliceItem.ts +43 -1
- package/src/content/fields/slices/SlicesContent.ts +30 -0
- package/src/content/fields/withDefaultValues.ts +48 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportUID = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../validators");
|
|
7
|
+
const ImportContent_1 = require("./ImportContent");
|
|
8
|
+
const regex = /^[a-z0-9-_.]+$/;
|
|
9
|
+
const uidValue = validators_1.String.pipe(new t.Type("ImportUIDField", (u) => validators_1.String.is(u), (n, c) => {
|
|
10
|
+
if (regex.test(n)) {
|
|
11
|
+
return t.success(n);
|
|
12
|
+
}
|
|
13
|
+
return t.failure(n, c, "UID can only contain alphanumeric characters, dashes, underscores, and dots");
|
|
14
|
+
}, t.identity));
|
|
15
|
+
exports.ImportUID = (0, ImportContent_1.ImportContent)("UID", uidValue);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./nestable"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./RepeatableZone"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./RepeatableZoneItem"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./UID"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportBoolean = void 0;
|
|
4
|
+
const validators_1 = require("../../../../validators");
|
|
5
|
+
const ImportContent_1 = require("../ImportContent");
|
|
6
|
+
exports.ImportBoolean = (0, ImportContent_1.ImportContent)("Boolean", (0, validators_1.NullOrElse)(validators_1.Boolean));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportColor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const HexaColorCode_1 = require("../../../../common/HexaColorCode");
|
|
7
|
+
const validators_1 = require("../../../../validators");
|
|
8
|
+
const ImportContent_1 = require("../ImportContent");
|
|
9
|
+
const colorValue = new t.Type("ImportColorValue", (u) => validators_1.String.is(u) && HexaColorCode_1.HexaColor.is(u), (s, c) => {
|
|
10
|
+
if (!HexaColorCode_1.HexaColor.is(s)) {
|
|
11
|
+
return t.failure(s, c, "The color value must be an hexadecimal color code");
|
|
12
|
+
}
|
|
13
|
+
return t.success(s);
|
|
14
|
+
}, t.identity);
|
|
15
|
+
exports.ImportColor = (0, ImportContent_1.ImportContent)("Color", (0, validators_1.NullOrElse)(validators_1.String.pipe(colorValue)));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportDate = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/Either");
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../ImportContent");
|
|
10
|
+
const DATE_INPUT_REGEX = /^(\d{1,4})-(\d{1,2})-(\d{1,2})$/;
|
|
11
|
+
const dateValue = new t.Type("ImportNumberValue", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(validators_1.String.validate(u, c), (0, Either_1.chain)((s) => {
|
|
12
|
+
const date = new Date(s);
|
|
13
|
+
const isInvalidDate = isNaN(date.getTime());
|
|
14
|
+
if (isInvalidDate || !DATE_INPUT_REGEX.test(s)) {
|
|
15
|
+
return t.failure(u, c, "The value must be a Date in the format YYYY-MM-DD");
|
|
16
|
+
}
|
|
17
|
+
return t.success(date);
|
|
18
|
+
})), t.identity);
|
|
19
|
+
exports.ImportDate = (0, ImportContent_1.ImportContent)("Date", (0, validators_1.NullOrElse)(dateValue));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const ImportEmbedValue: t.ExactC<t.TypeC<{
|
|
3
|
+
embed_url: t.Type<string, string, unknown>;
|
|
4
|
+
}>>;
|
|
5
|
+
export declare const ImportEmbed: t.Type<{
|
|
6
|
+
type: "Embed";
|
|
7
|
+
value: {
|
|
8
|
+
embed_url: string;
|
|
9
|
+
} | null;
|
|
10
|
+
}, {
|
|
11
|
+
embed_url: string;
|
|
12
|
+
} | undefined, unknown>;
|
|
13
|
+
export declare type ImportEmbed = t.TypeOf<typeof ImportEmbed>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportEmbed = exports.ImportEmbedValue = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../validators");
|
|
7
|
+
const ImportContent_1 = require("../ImportContent");
|
|
8
|
+
function isValidHttpUrl(param) {
|
|
9
|
+
try {
|
|
10
|
+
if (typeof param !== "string") {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const url = new URL(param);
|
|
14
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const EmbedUrl = new t.Type("EmbedUrl", (u) => isValidHttpUrl(u), (u, c) => {
|
|
21
|
+
if (isValidHttpUrl(u)) {
|
|
22
|
+
return t.success(u);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return t.failure(u, c, "The value must be a valid http/https url");
|
|
26
|
+
}
|
|
27
|
+
}, t.identity);
|
|
28
|
+
exports.ImportEmbedValue = t.strict({
|
|
29
|
+
embed_url: EmbedUrl,
|
|
30
|
+
});
|
|
31
|
+
exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(exports.ImportEmbedValue));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TypeOf } from "io-ts";
|
|
2
|
+
import * as t from "io-ts";
|
|
3
|
+
export declare const ImportGeoPoint: t.Type<{
|
|
4
|
+
type: "GeoPoint";
|
|
5
|
+
value: {
|
|
6
|
+
latitude: number;
|
|
7
|
+
longitude: number;
|
|
8
|
+
} | null;
|
|
9
|
+
}, {
|
|
10
|
+
latitude: number;
|
|
11
|
+
longitude: number;
|
|
12
|
+
} | undefined, unknown>;
|
|
13
|
+
export declare type ImportGeoPoint = TypeOf<typeof ImportGeoPoint>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportGeoPoint = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../validators");
|
|
7
|
+
const function_1 = require("../../../../validators/function");
|
|
8
|
+
const ImportContent_1 = require("../ImportContent");
|
|
9
|
+
const GeoPoint = (0, function_1.withCustomError)(t.strict({
|
|
10
|
+
latitude: (0, validators_1.NumberRange)(-90, 90, "latitude"),
|
|
11
|
+
longitude: (0, validators_1.NumberRange)(-180, 180, "longitude"),
|
|
12
|
+
}), () => "GeoPoint must be an object with the properties `latitude` and `longitude` between the given ranges");
|
|
13
|
+
exports.ImportGeoPoint = (0, ImportContent_1.ImportContent)("GeoPoint", (0, validators_1.EmptyObjectOrElse)(GeoPoint));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const defaultImportImage: (field?: ({
|
|
3
|
+
type: "Image";
|
|
4
|
+
} & {
|
|
5
|
+
fieldset?: string | null | undefined;
|
|
6
|
+
config?: {
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
constraint?: {
|
|
10
|
+
width?: number | null;
|
|
11
|
+
height?: number | null;
|
|
12
|
+
};
|
|
13
|
+
thumbnails?: readonly ({
|
|
14
|
+
name: string;
|
|
15
|
+
} & {
|
|
16
|
+
width?: number | null;
|
|
17
|
+
height?: number | null;
|
|
18
|
+
})[];
|
|
19
|
+
};
|
|
20
|
+
}) | undefined) => t.Type<Record<never, never>, {
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}, unknown>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultImportImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../../validators");
|
|
7
|
+
const defaultImportImage = (field) => {
|
|
8
|
+
var _a;
|
|
9
|
+
// If there is not thumbnails we expect an empty object
|
|
10
|
+
if (!((_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) || !field.config.thumbnails.length)
|
|
11
|
+
return validators_1.EmptyObject;
|
|
12
|
+
// If there are thumbnails, we can expect an object with thumbnails as empty objects,
|
|
13
|
+
// however we don't accept any other properties for the empty state
|
|
14
|
+
return t.strict(field.config.thumbnails.reduce((acc, thumbnail) => ({
|
|
15
|
+
...acc,
|
|
16
|
+
[thumbnail.name]: validators_1.EmptyObject,
|
|
17
|
+
}), {}));
|
|
18
|
+
};
|
|
19
|
+
exports.defaultImportImage = defaultImportImage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import type { ImageFieldWithThumbnails } from "./model";
|
|
3
|
+
export declare const ImportImage: (field?: ({
|
|
4
|
+
type: "Image";
|
|
5
|
+
} & {
|
|
6
|
+
fieldset?: string | null | undefined;
|
|
7
|
+
config?: {
|
|
8
|
+
label?: string | null | undefined;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
constraint?: {
|
|
11
|
+
width?: number | null;
|
|
12
|
+
height?: number | null;
|
|
13
|
+
};
|
|
14
|
+
thumbnails?: readonly ({
|
|
15
|
+
name: string;
|
|
16
|
+
} & {
|
|
17
|
+
width?: number | null;
|
|
18
|
+
height?: number | null;
|
|
19
|
+
})[];
|
|
20
|
+
};
|
|
21
|
+
}) | undefined) => t.Type<{
|
|
22
|
+
type: "Image";
|
|
23
|
+
value: ImageFieldWithThumbnails | null;
|
|
24
|
+
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
25
|
+
export declare type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>;
|
|
26
|
+
export * from "./model";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/Either");
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../../validators");
|
|
9
|
+
const function_2 = require("../../../../../validators/function");
|
|
10
|
+
const ImportContent_1 = require("../../ImportContent");
|
|
11
|
+
const default_1 = require("./default");
|
|
12
|
+
const merge_1 = require("./merge");
|
|
13
|
+
const validators_2 = require("./validators");
|
|
14
|
+
/* For code clarity, the output of this validator will be simplified
|
|
15
|
+
*
|
|
16
|
+
* Input -> type ImageAPIV2 = ImportImageView & ImportThumbnails
|
|
17
|
+
* Output -> type ImageWithThumbnails 👇
|
|
18
|
+
*/
|
|
19
|
+
const ImageFieldCodec = (field) => {
|
|
20
|
+
const ImageCodec = (0, validators_2.ImportImageWithThumbnails)(field);
|
|
21
|
+
return new t.Type("ImageField", (u) => ImageCodec.is(u), (u, ctx) => (0, function_1.pipe)(ImageCodec.validate(u, ctx), (0, Either_1.map)((imageApiV2) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const { id, dimensions, edit, copyright, alt, ...thumbnails } = imageApiV2;
|
|
24
|
+
return {
|
|
25
|
+
...(0, merge_1.mergeImageViewWithCtConstraints)(imageApiV2, imageApiV2, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
26
|
+
thumbnails: (0, merge_1.mergeThumbnailsWithCtConstraints)(thumbnails, imageApiV2, field),
|
|
27
|
+
};
|
|
28
|
+
})), t.identity);
|
|
29
|
+
};
|
|
30
|
+
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", (0, function_2.withCustomError)((0, validators_1.DefaultOrElse)((0, default_1.defaultImportImage)(field))(ImageFieldCodec(field)), () => "An image field must be an object"));
|
|
31
|
+
exports.ImportImage = ImportImage;
|
|
32
|
+
(0, tslib_1.__exportStar)(require("./model"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type ImageConstraint from "../../../../../customtypes/widgets/shared/ImageConstraint";
|
|
2
|
+
import type { ImageField } from "./model";
|
|
3
|
+
import type { ImportImageView, ImportThumbnails } from "./validators";
|
|
4
|
+
export declare const mergeImageViewWithCtConstraints: (image: ImportImageView | undefined, defaultImage: ImportImageView, constraints: ImageConstraint | undefined) => ImageField;
|
|
5
|
+
export declare const mergeThumbnailsWithCtConstraints: (thumbnails: ImportThumbnails, defaultImage: ImportImageView, field?: ({
|
|
6
|
+
type: "Image";
|
|
7
|
+
} & {
|
|
8
|
+
fieldset?: string | null | undefined;
|
|
9
|
+
config?: {
|
|
10
|
+
label?: string | null | undefined;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
constraint?: {
|
|
13
|
+
width?: number | null;
|
|
14
|
+
height?: number | null;
|
|
15
|
+
};
|
|
16
|
+
thumbnails?: readonly ({
|
|
17
|
+
name: string;
|
|
18
|
+
} & {
|
|
19
|
+
width?: number | null;
|
|
20
|
+
height?: number | null;
|
|
21
|
+
})[];
|
|
22
|
+
};
|
|
23
|
+
}) | undefined) => {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeThumbnailsWithCtConstraints = exports.mergeImageViewWithCtConstraints = void 0;
|
|
4
|
+
/* This function merges user input with custom type constraints.
|
|
5
|
+
* If a thumbnails' data are missing (`image`) then the default is used (`defaultImage`)
|
|
6
|
+
*/
|
|
7
|
+
const mergeImageViewWithCtConstraints = (image, defaultImage, constraints) => {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
9
|
+
const background = (_a = image === null || image === void 0 ? void 0 : image.edit) === null || _a === void 0 ? void 0 : _a.background;
|
|
10
|
+
const width = (_d = (_b = constraints === null || constraints === void 0 ? void 0 : constraints.width) !== null && _b !== void 0 ? _b : (_c = image === null || image === void 0 ? void 0 : image.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : (_e = defaultImage === null || defaultImage === void 0 ? void 0 : defaultImage.dimensions) === null || _e === void 0 ? void 0 : _e.width;
|
|
11
|
+
const height = (_h = (_f = constraints === null || constraints === void 0 ? void 0 : constraints.height) !== null && _f !== void 0 ? _f : (_g = image === null || image === void 0 ? void 0 : image.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : (_j = defaultImage === null || defaultImage === void 0 ? void 0 : defaultImage.dimensions) === null || _j === void 0 ? void 0 : _j.height;
|
|
12
|
+
const alt = image === null || image === void 0 ? void 0 : image.alt;
|
|
13
|
+
const copyright = image === null || image === void 0 ? void 0 : image.copyright;
|
|
14
|
+
return {
|
|
15
|
+
id: (_k = image === null || image === void 0 ? void 0 : image.id) !== null && _k !== void 0 ? _k : defaultImage === null || defaultImage === void 0 ? void 0 : defaultImage.id,
|
|
16
|
+
edit: {
|
|
17
|
+
x: (_m = (_l = image === null || image === void 0 ? void 0 : image.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
18
|
+
y: (_p = (_o = image === null || image === void 0 ? void 0 : image.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
|
|
19
|
+
zoom: (_r = (_q = image === null || image === void 0 ? void 0 : image.edit) === null || _q === void 0 ? void 0 : _q.zoom) !== null && _r !== void 0 ? _r : 1,
|
|
20
|
+
...(background !== undefined ? { background } : {}),
|
|
21
|
+
},
|
|
22
|
+
dimensions: {
|
|
23
|
+
...(width !== undefined ? { width } : {}),
|
|
24
|
+
...(height !== undefined ? { height } : {}),
|
|
25
|
+
},
|
|
26
|
+
...(alt !== undefined ? { alt } : {}),
|
|
27
|
+
...(copyright !== undefined ? { copyright } : {}),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.mergeImageViewWithCtConstraints = mergeImageViewWithCtConstraints;
|
|
31
|
+
/* This function handles each thumbnail defined in the custom type.
|
|
32
|
+
*
|
|
33
|
+
* For each of them it merges the user input with custom type constraints.
|
|
34
|
+
*
|
|
35
|
+
* If a thumbnail is missing, the data from the default image is used.
|
|
36
|
+
*/
|
|
37
|
+
const mergeThumbnailsWithCtConstraints = (thumbnails, defaultImage, field) => {
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
return (_c = (_b = (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) === null || _b === void 0 ? void 0 : _b.reduce((acc, thumbnail) => ({
|
|
40
|
+
...acc,
|
|
41
|
+
[thumbnail.name]: (0, exports.mergeImageViewWithCtConstraints)(thumbnails[thumbnail.name], defaultImage, thumbnail),
|
|
42
|
+
}), {})) !== null && _c !== void 0 ? _c : {};
|
|
43
|
+
};
|
|
44
|
+
exports.mergeThumbnailsWithCtConstraints = mergeThumbnailsWithCtConstraints;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare type ImageField = {
|
|
2
|
+
id: string;
|
|
3
|
+
edit: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
zoom: number;
|
|
7
|
+
background?: string;
|
|
8
|
+
};
|
|
9
|
+
dimensions: {
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
};
|
|
13
|
+
copyright?: string | null;
|
|
14
|
+
alt?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export declare type ImageFieldWithThumbnails = ImageField & {
|
|
17
|
+
thumbnails: Record<string, ImageField>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import type { Thumbnail } from "../../../../../customtypes";
|
|
3
|
+
export declare const ImportImageViewShape: t.IntersectionC<[t.TypeC<{
|
|
4
|
+
id: t.StringC;
|
|
5
|
+
}>, t.PartialC<{
|
|
6
|
+
dimensions: t.PartialC<{
|
|
7
|
+
width: t.NumberC;
|
|
8
|
+
height: t.NumberC;
|
|
9
|
+
}>;
|
|
10
|
+
edit: t.PartialC<{
|
|
11
|
+
x: t.NumberC;
|
|
12
|
+
y: t.NumberC;
|
|
13
|
+
zoom: t.NumberC;
|
|
14
|
+
background: t.StringC;
|
|
15
|
+
}>;
|
|
16
|
+
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
17
|
+
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
18
|
+
}>]>;
|
|
19
|
+
export declare const ImportImageView: t.IntersectionC<[t.TypeC<{
|
|
20
|
+
id: t.StringC;
|
|
21
|
+
}>, t.PartialC<{
|
|
22
|
+
dimensions: t.PartialC<{
|
|
23
|
+
width: t.NumberC;
|
|
24
|
+
height: t.NumberC;
|
|
25
|
+
}>;
|
|
26
|
+
edit: t.PartialC<{
|
|
27
|
+
x: t.NumberC;
|
|
28
|
+
y: t.NumberC;
|
|
29
|
+
zoom: t.NumberC;
|
|
30
|
+
background: t.StringC;
|
|
31
|
+
}>;
|
|
32
|
+
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
33
|
+
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
34
|
+
}>]>;
|
|
35
|
+
export declare type ImportImageView = t.TypeOf<typeof ImportImageView>;
|
|
36
|
+
declare const ImportThumbnails: (thumbnails: readonly Thumbnail[]) => t.Type<Record<string, {
|
|
37
|
+
id: string;
|
|
38
|
+
} & {
|
|
39
|
+
dimensions?: {
|
|
40
|
+
width?: number;
|
|
41
|
+
height?: number;
|
|
42
|
+
};
|
|
43
|
+
edit?: {
|
|
44
|
+
x?: number;
|
|
45
|
+
y?: number;
|
|
46
|
+
zoom?: number;
|
|
47
|
+
background?: string;
|
|
48
|
+
};
|
|
49
|
+
copyright?: string | null;
|
|
50
|
+
alt?: string | null;
|
|
51
|
+
}>, Record<string, {
|
|
52
|
+
id: string;
|
|
53
|
+
} & {
|
|
54
|
+
dimensions?: {
|
|
55
|
+
width?: number;
|
|
56
|
+
height?: number;
|
|
57
|
+
};
|
|
58
|
+
edit?: {
|
|
59
|
+
x?: number;
|
|
60
|
+
y?: number;
|
|
61
|
+
zoom?: number;
|
|
62
|
+
background?: string;
|
|
63
|
+
};
|
|
64
|
+
copyright?: string | null;
|
|
65
|
+
alt?: string | null;
|
|
66
|
+
}>, unknown>;
|
|
67
|
+
export declare type ImportThumbnails = t.TypeOf<ReturnType<typeof ImportThumbnails>>;
|
|
68
|
+
export declare const ImportImageWithThumbnails: (def?: ({
|
|
69
|
+
type: "Image";
|
|
70
|
+
} & {
|
|
71
|
+
fieldset?: string | null | undefined;
|
|
72
|
+
config?: {
|
|
73
|
+
label?: string | null | undefined;
|
|
74
|
+
placeholder?: string;
|
|
75
|
+
constraint?: {
|
|
76
|
+
width?: number | null;
|
|
77
|
+
height?: number | null;
|
|
78
|
+
};
|
|
79
|
+
thumbnails?: readonly ({
|
|
80
|
+
name: string;
|
|
81
|
+
} & {
|
|
82
|
+
width?: number | null;
|
|
83
|
+
height?: number | null;
|
|
84
|
+
})[];
|
|
85
|
+
};
|
|
86
|
+
}) | undefined) => t.IntersectionC<[t.IntersectionC<[t.TypeC<{
|
|
87
|
+
id: t.StringC;
|
|
88
|
+
}>, t.PartialC<{
|
|
89
|
+
dimensions: t.PartialC<{
|
|
90
|
+
width: t.NumberC;
|
|
91
|
+
height: t.NumberC;
|
|
92
|
+
}>;
|
|
93
|
+
edit: t.PartialC<{
|
|
94
|
+
x: t.NumberC;
|
|
95
|
+
y: t.NumberC;
|
|
96
|
+
zoom: t.NumberC;
|
|
97
|
+
background: t.StringC;
|
|
98
|
+
}>;
|
|
99
|
+
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
100
|
+
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
101
|
+
}>]>, t.Type<Record<string, {
|
|
102
|
+
id: string;
|
|
103
|
+
} & {
|
|
104
|
+
dimensions?: {
|
|
105
|
+
width?: number;
|
|
106
|
+
height?: number;
|
|
107
|
+
};
|
|
108
|
+
edit?: {
|
|
109
|
+
x?: number;
|
|
110
|
+
y?: number;
|
|
111
|
+
zoom?: number;
|
|
112
|
+
background?: string;
|
|
113
|
+
};
|
|
114
|
+
copyright?: string | null;
|
|
115
|
+
alt?: string | null;
|
|
116
|
+
}>, Record<string, {
|
|
117
|
+
id: string;
|
|
118
|
+
} & {
|
|
119
|
+
dimensions?: {
|
|
120
|
+
width?: number;
|
|
121
|
+
height?: number;
|
|
122
|
+
};
|
|
123
|
+
edit?: {
|
|
124
|
+
x?: number;
|
|
125
|
+
y?: number;
|
|
126
|
+
zoom?: number;
|
|
127
|
+
background?: string;
|
|
128
|
+
};
|
|
129
|
+
copyright?: string | null;
|
|
130
|
+
alt?: string | null;
|
|
131
|
+
}>, unknown>]>;
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportImageWithThumbnails = exports.ImportImageView = exports.ImportImageViewShape = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const BasicTypes_1 = require("../../../../../validators/BasicTypes");
|
|
7
|
+
const function_1 = require("../../../../../validators/function");
|
|
8
|
+
exports.ImportImageViewShape = t.intersection([
|
|
9
|
+
t.type({
|
|
10
|
+
// Image Id
|
|
11
|
+
id: BasicTypes_1.String,
|
|
12
|
+
}),
|
|
13
|
+
t.partial({
|
|
14
|
+
// Dimensions here will be used if they are not defined in the custom type
|
|
15
|
+
dimensions: (0, function_1.withCustomError)(t.partial({
|
|
16
|
+
width: BasicTypes_1.Number,
|
|
17
|
+
height: BasicTypes_1.Number,
|
|
18
|
+
}), () => "The value must be an object"),
|
|
19
|
+
// Crop information
|
|
20
|
+
edit: (0, function_1.withCustomError)(t.partial({
|
|
21
|
+
x: BasicTypes_1.Number,
|
|
22
|
+
y: BasicTypes_1.Number,
|
|
23
|
+
zoom: BasicTypes_1.Number,
|
|
24
|
+
background: BasicTypes_1.String,
|
|
25
|
+
}), () => "The value must be an object"),
|
|
26
|
+
// Copyrights and alt are set in the Asset by default but they can be overrided
|
|
27
|
+
copyright: BasicTypes_1.StringOrNull,
|
|
28
|
+
alt: BasicTypes_1.StringOrNull,
|
|
29
|
+
}),
|
|
30
|
+
]);
|
|
31
|
+
exports.ImportImageView = (0, function_1.withCustomError)(exports.ImportImageViewShape, () => "The value must be an object");
|
|
32
|
+
const ImportThumbnails = (thumbnails) => t.partial(thumbnails.reduce((acc, thumbnail) => ({
|
|
33
|
+
...acc,
|
|
34
|
+
[thumbnail.name]: exports.ImportImageView,
|
|
35
|
+
}), {}));
|
|
36
|
+
const ImportImageWithThumbnails = (def) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return (0, function_1.withCustomError)(t.intersection([
|
|
39
|
+
exports.ImportImageViewShape,
|
|
40
|
+
ImportThumbnails((_b = (_a = def === null || def === void 0 ? void 0 : def.config) === null || _a === void 0 ? void 0 : _a.thumbnails) !== null && _b !== void 0 ? _b : []),
|
|
41
|
+
]), () => "The value must be an object");
|
|
42
|
+
};
|
|
43
|
+
exports.ImportImageWithThumbnails = ImportImageWithThumbnails;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { ImportBlockType, ImportEmbedBlock, ImportImageBlock, ImportTextBlock } from "./blocks";
|
|
3
|
+
export declare type ImportBlock = ImportTextBlock | ImportImageBlock | ImportEmbedBlock;
|
|
4
|
+
export declare const ImportBlock: (allowedBlockTypes: string[]) => t.Type<ImportBlock, {
|
|
5
|
+
type: ImportBlockType;
|
|
6
|
+
}, unknown>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportBlock = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const function_1 = require("../../../../../validators/function");
|
|
7
|
+
const blocks_1 = require("./blocks");
|
|
8
|
+
const ImportBlock = (allowedBlockTypes) => (0, function_1.withCustomError)(t
|
|
9
|
+
.type({
|
|
10
|
+
type: (0, blocks_1.ImportBlockType)(allowedBlockTypes),
|
|
11
|
+
})
|
|
12
|
+
.pipe(new t.Type("ImportBlock", (u) => t
|
|
13
|
+
.union([blocks_1.ImportTextBlock, blocks_1.ImportImageBlock, blocks_1.ImportEmbedBlock])
|
|
14
|
+
.is(u), (u, c) => {
|
|
15
|
+
if (u.type === "image") {
|
|
16
|
+
return blocks_1.ImportImageBlock.validate(u, c);
|
|
17
|
+
}
|
|
18
|
+
else if (u.type === "embed") {
|
|
19
|
+
return blocks_1.ImportEmbedBlock.validate(u, c);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return blocks_1.ImportTextBlock.validate(u, c);
|
|
23
|
+
}
|
|
24
|
+
}, t.identity)), () => "Rich text block must be an object");
|
|
25
|
+
exports.ImportBlock = ImportBlock;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { ImportBlock } from "./ImportBlock";
|
|
3
|
+
export declare const ImportRichText: (customType?: ({
|
|
4
|
+
type: "StructuredText";
|
|
5
|
+
} & {
|
|
6
|
+
fieldset?: string | null | undefined;
|
|
7
|
+
config?: {
|
|
8
|
+
label?: string | null | undefined;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
useAsTitle?: boolean;
|
|
11
|
+
single?: string;
|
|
12
|
+
multi?: string;
|
|
13
|
+
imageConstraint?: {
|
|
14
|
+
width?: number | null;
|
|
15
|
+
height?: number | null;
|
|
16
|
+
};
|
|
17
|
+
labels?: readonly string[];
|
|
18
|
+
allowTargetBlank?: boolean;
|
|
19
|
+
};
|
|
20
|
+
}) | undefined) => t.Type<{
|
|
21
|
+
type: "StructuredText";
|
|
22
|
+
value: ImportBlock[] | null;
|
|
23
|
+
}, ImportBlock[] | undefined, unknown>;
|
|
24
|
+
export declare type ImportRichText = t.TypeOf<ReturnType<typeof ImportRichText>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportRichText = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../../validators");
|
|
9
|
+
const function_2 = require("../../../../../validators/function");
|
|
10
|
+
const ImportContent_1 = require("../../ImportContent");
|
|
11
|
+
const ImportBlock_1 = require("./ImportBlock");
|
|
12
|
+
const ImportRichText = (customType) => {
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
|
+
const single = (_b = (_a = customType === null || customType === void 0 ? void 0 : customType.config) === null || _a === void 0 ? void 0 : _a.single) === null || _b === void 0 ? void 0 : _b.split(",");
|
|
15
|
+
const multi = (_d = (_c = customType === null || customType === void 0 ? void 0 : customType.config) === null || _c === void 0 ? void 0 : _c.multi) === null || _d === void 0 ? void 0 : _d.split(",");
|
|
16
|
+
const allowedBlockTypes = multi || single;
|
|
17
|
+
const isSingleBlockAllowed = multi === undefined && single !== undefined;
|
|
18
|
+
const BlockCodec = (0, ImportBlock_1.ImportBlock)(allowedBlockTypes !== null && allowedBlockTypes !== void 0 ? allowedBlockTypes : []);
|
|
19
|
+
const RichTextArrayCodec = (0, function_2.withCustomError)(t.array(BlockCodec), () => "Rich text field must be an array");
|
|
20
|
+
return (0, ImportContent_1.ImportContent)("StructuredText", (0, validators_1.EmptyArrayOrElse)(new t.ArrayType(RichTextArrayCodec.name, (u) => RichTextArrayCodec.is(u), (u, c) => {
|
|
21
|
+
if (allowedBlockTypes === undefined) {
|
|
22
|
+
throw new Error("Invalid custom type for the rich text field: the model is missing a 'single' or 'multi' field defining a list of allowed block types");
|
|
23
|
+
}
|
|
24
|
+
return (0, function_1.pipe)(RichTextArrayCodec.validate(u, c), E.chain((blocks) => {
|
|
25
|
+
if (isSingleBlockAllowed && blocks.length > 1) {
|
|
26
|
+
return t.failure(blocks, c, "This field only allows one block");
|
|
27
|
+
}
|
|
28
|
+
return t.success(blocks);
|
|
29
|
+
}));
|
|
30
|
+
}, t.identity, BlockCodec)));
|
|
31
|
+
};
|
|
32
|
+
exports.ImportRichText = ImportRichText;
|