@squiz/dx-page-contents-lib 1.40.1-alpha.18
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/README.md +5 -0
- package/lib/formatted-text.d.ts +177 -0
- package/lib/formatted-text.js +57 -0
- package/lib/formatted-text.js.map +1 -0
- package/lib/layout-content.d.ts +210 -0
- package/lib/layout-content.js +60 -0
- package/lib/layout-content.js.map +1 -0
- package/lib/layouts/index.d.ts +455 -0
- package/lib/layouts/index.js +12 -0
- package/lib/layouts/index.js.map +1 -0
- package/lib/layouts/single-column.layout.d.ts +158 -0
- package/lib/layouts/single-column.layout.js +15 -0
- package/lib/layouts/single-column.layout.js.map +1 -0
- package/lib/layouts/two-column.layout.d.ts +298 -0
- package/lib/layouts/two-column.layout.js +16 -0
- package/lib/layouts/two-column.layout.js.map +1 -0
- package/lib/page-contents-lib.d.ts +11 -0
- package/lib/page-contents-lib.js +54 -0
- package/lib/page-contents-lib.js.map +1 -0
- package/lib/page-contents-lib.spec.d.ts +1 -0
- package/lib/page-contents-lib.spec.js +198 -0
- package/lib/page-contents-lib.spec.js.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TextNode: z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"text">;
|
|
4
|
+
value: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
value: string;
|
|
7
|
+
type: "text";
|
|
8
|
+
}, {
|
|
9
|
+
value: string;
|
|
10
|
+
type: "text";
|
|
11
|
+
}>;
|
|
12
|
+
export declare const TagNode: z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"tag">;
|
|
14
|
+
tag: z.ZodString;
|
|
15
|
+
attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
16
|
+
font: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
bold: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
italics: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
underline: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
color: z.ZodOptional<z.ZodString>;
|
|
21
|
+
size: z.ZodOptional<z.ZodString>;
|
|
22
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
bold?: boolean | undefined;
|
|
25
|
+
italics?: boolean | undefined;
|
|
26
|
+
underline?: boolean | undefined;
|
|
27
|
+
color?: string | undefined;
|
|
28
|
+
size?: string | undefined;
|
|
29
|
+
fontFamily?: string | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
bold?: boolean | undefined;
|
|
32
|
+
italics?: boolean | undefined;
|
|
33
|
+
underline?: boolean | undefined;
|
|
34
|
+
color?: string | undefined;
|
|
35
|
+
size?: string | undefined;
|
|
36
|
+
fontFamily?: string | undefined;
|
|
37
|
+
}>>;
|
|
38
|
+
formattingOptions: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
alignment: z.ZodEnum<["left", "center", "right", "justify"]>;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
42
|
+
}, {
|
|
43
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
44
|
+
}>>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
type: "tag";
|
|
47
|
+
tag: string;
|
|
48
|
+
attributes?: Record<string, string> | undefined;
|
|
49
|
+
font?: {
|
|
50
|
+
bold?: boolean | undefined;
|
|
51
|
+
italics?: boolean | undefined;
|
|
52
|
+
underline?: boolean | undefined;
|
|
53
|
+
color?: string | undefined;
|
|
54
|
+
size?: string | undefined;
|
|
55
|
+
fontFamily?: string | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
formattingOptions?: {
|
|
58
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
59
|
+
} | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
type: "tag";
|
|
62
|
+
tag: string;
|
|
63
|
+
attributes?: Record<string, string> | undefined;
|
|
64
|
+
font?: {
|
|
65
|
+
bold?: boolean | undefined;
|
|
66
|
+
italics?: boolean | undefined;
|
|
67
|
+
underline?: boolean | undefined;
|
|
68
|
+
color?: string | undefined;
|
|
69
|
+
size?: string | undefined;
|
|
70
|
+
fontFamily?: string | undefined;
|
|
71
|
+
} | undefined;
|
|
72
|
+
formattingOptions?: {
|
|
73
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
74
|
+
} | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
export declare const LinkToMatrixAssetNode: z.ZodObject<{
|
|
77
|
+
type: z.ZodLiteral<"link-to-matrix-asset">;
|
|
78
|
+
matrixIdentifier: z.ZodOptional<z.ZodString>;
|
|
79
|
+
matrixDomain: z.ZodString;
|
|
80
|
+
matrixAssetId: z.ZodString;
|
|
81
|
+
target: z.ZodEnum<["_blank", "_self", "_parent", "_top"]>;
|
|
82
|
+
formattingOptions: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
alignment: z.ZodEnum<["left", "center", "right", "justify"]>;
|
|
84
|
+
}, "strip", z.ZodTypeAny, {
|
|
85
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
86
|
+
}, {
|
|
87
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
88
|
+
}>>;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
type: "link-to-matrix-asset";
|
|
91
|
+
matrixDomain: string;
|
|
92
|
+
matrixAssetId: string;
|
|
93
|
+
target: "_blank" | "_self" | "_parent" | "_top";
|
|
94
|
+
matrixIdentifier?: string | undefined;
|
|
95
|
+
formattingOptions?: {
|
|
96
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
97
|
+
} | undefined;
|
|
98
|
+
}, {
|
|
99
|
+
type: "link-to-matrix-asset";
|
|
100
|
+
matrixDomain: string;
|
|
101
|
+
matrixAssetId: string;
|
|
102
|
+
target: "_blank" | "_self" | "_parent" | "_top";
|
|
103
|
+
matrixIdentifier?: string | undefined;
|
|
104
|
+
formattingOptions?: {
|
|
105
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
106
|
+
} | undefined;
|
|
107
|
+
}>;
|
|
108
|
+
export declare const MatrixImageNode: z.ZodObject<{
|
|
109
|
+
type: z.ZodLiteral<"matrix-image">;
|
|
110
|
+
matrixIdentifier: z.ZodOptional<z.ZodString>;
|
|
111
|
+
matrixDomain: z.ZodString;
|
|
112
|
+
matrixAssetId: z.ZodString;
|
|
113
|
+
formattingOptions: z.ZodOptional<z.ZodObject<{
|
|
114
|
+
alignment: z.ZodEnum<["left", "center", "right", "justify"]>;
|
|
115
|
+
}, "strip", z.ZodTypeAny, {
|
|
116
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
117
|
+
}, {
|
|
118
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
119
|
+
}>>;
|
|
120
|
+
}, "strip", z.ZodTypeAny, {
|
|
121
|
+
type: "matrix-image";
|
|
122
|
+
matrixDomain: string;
|
|
123
|
+
matrixAssetId: string;
|
|
124
|
+
matrixIdentifier?: string | undefined;
|
|
125
|
+
formattingOptions?: {
|
|
126
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
127
|
+
} | undefined;
|
|
128
|
+
}, {
|
|
129
|
+
type: "matrix-image";
|
|
130
|
+
matrixDomain: string;
|
|
131
|
+
matrixAssetId: string;
|
|
132
|
+
matrixIdentifier?: string | undefined;
|
|
133
|
+
formattingOptions?: {
|
|
134
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
135
|
+
} | undefined;
|
|
136
|
+
}>;
|
|
137
|
+
export declare const ComponentNode: z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"component">;
|
|
139
|
+
componentId: z.ZodString;
|
|
140
|
+
componentSet: z.ZodString;
|
|
141
|
+
contentItem: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
142
|
+
id: z.ZodString;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
id: string;
|
|
145
|
+
}, {
|
|
146
|
+
id: string;
|
|
147
|
+
}>, z.ZodObject<{
|
|
148
|
+
content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
149
|
+
schemaName: z.ZodString;
|
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
|
151
|
+
content: Record<string, unknown>;
|
|
152
|
+
schemaName: string;
|
|
153
|
+
}, {
|
|
154
|
+
content: Record<string, unknown>;
|
|
155
|
+
schemaName: string;
|
|
156
|
+
}>]>>;
|
|
157
|
+
}, "strip", z.ZodTypeAny, {
|
|
158
|
+
type: "component";
|
|
159
|
+
componentId: string;
|
|
160
|
+
componentSet: string;
|
|
161
|
+
contentItem?: {
|
|
162
|
+
id: string;
|
|
163
|
+
} | {
|
|
164
|
+
content: Record<string, unknown>;
|
|
165
|
+
schemaName: string;
|
|
166
|
+
} | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
type: "component";
|
|
169
|
+
componentId: string;
|
|
170
|
+
componentSet: string;
|
|
171
|
+
contentItem?: {
|
|
172
|
+
id: string;
|
|
173
|
+
} | {
|
|
174
|
+
content: Record<string, unknown>;
|
|
175
|
+
schemaName: string;
|
|
176
|
+
} | undefined;
|
|
177
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentNode = exports.MatrixImageNode = exports.LinkToMatrixAssetNode = exports.TagNode = exports.TextNode = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
// TODO: Move the FormattedText node definitions to a separate package
|
|
6
|
+
const FormattingOptions = zod_1.z.object({
|
|
7
|
+
alignment: zod_1.z.enum(['left', 'center', 'right', 'justify']),
|
|
8
|
+
});
|
|
9
|
+
const FontOptions = zod_1.z.object({
|
|
10
|
+
bold: zod_1.z.boolean().optional(),
|
|
11
|
+
italics: zod_1.z.boolean().optional(),
|
|
12
|
+
underline: zod_1.z.boolean().optional(),
|
|
13
|
+
color: zod_1.z.string().optional(),
|
|
14
|
+
size: zod_1.z.string().optional(),
|
|
15
|
+
fontFamily: zod_1.z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
exports.TextNode = zod_1.z.object({
|
|
18
|
+
type: zod_1.z.literal('text'),
|
|
19
|
+
value: zod_1.z.string(),
|
|
20
|
+
});
|
|
21
|
+
exports.TagNode = zod_1.z.object({
|
|
22
|
+
type: zod_1.z.literal('tag'),
|
|
23
|
+
tag: zod_1.z.string().min(1),
|
|
24
|
+
attributes: zod_1.z.record(zod_1.z.string()).optional(),
|
|
25
|
+
font: FontOptions.optional(),
|
|
26
|
+
formattingOptions: FormattingOptions.optional(),
|
|
27
|
+
});
|
|
28
|
+
exports.LinkToMatrixAssetNode = zod_1.z.object({
|
|
29
|
+
type: zod_1.z.literal('link-to-matrix-asset'),
|
|
30
|
+
matrixIdentifier: zod_1.z.string().optional(),
|
|
31
|
+
matrixDomain: zod_1.z.string().min(1),
|
|
32
|
+
matrixAssetId: zod_1.z.string().min(1),
|
|
33
|
+
target: zod_1.z.enum(['_blank', '_self', '_parent', '_top']),
|
|
34
|
+
formattingOptions: FormattingOptions.optional(),
|
|
35
|
+
});
|
|
36
|
+
exports.MatrixImageNode = zod_1.z.object({
|
|
37
|
+
type: zod_1.z.literal('matrix-image'),
|
|
38
|
+
matrixIdentifier: zod_1.z.string().optional(),
|
|
39
|
+
matrixDomain: zod_1.z.string().min(1),
|
|
40
|
+
matrixAssetId: zod_1.z.string().min(1),
|
|
41
|
+
formattingOptions: FormattingOptions.optional(),
|
|
42
|
+
});
|
|
43
|
+
exports.ComponentNode = zod_1.z.object({
|
|
44
|
+
type: zod_1.z.literal('component'),
|
|
45
|
+
componentId: zod_1.z.string(),
|
|
46
|
+
componentSet: zod_1.z.string(),
|
|
47
|
+
contentItem: zod_1.z
|
|
48
|
+
.object({
|
|
49
|
+
id: zod_1.z.string(),
|
|
50
|
+
})
|
|
51
|
+
.or(zod_1.z.object({
|
|
52
|
+
content: zod_1.z.record(zod_1.z.unknown()),
|
|
53
|
+
schemaName: zod_1.z.string(),
|
|
54
|
+
}))
|
|
55
|
+
.optional(),
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=formatted-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatted-text.js","sourceRoot":"","sources":["../src/formatted-text.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,sEAAsE;AAEtE,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;CAC1D,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC5B,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC/B,SAAS,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAEU,QAAA,QAAQ,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACvB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAEU,QAAA,OAAO,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACtB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,CAAC;IAC5B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;IACxB,WAAW,EAAE,OAAC;SACX,MAAM,CAAC;QACN,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;KACf,CAAC;SACD,EAAE,CACD,OAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,OAAO,EAAE,CAAC;QAC9B,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;KACvB,CAAC,CACH;SACA,QAAQ,EAAE;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const BaseLayoutContentNodes: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"component">;
|
|
4
|
+
componentId: z.ZodString;
|
|
5
|
+
componentSet: z.ZodString;
|
|
6
|
+
contentItem: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
id: string;
|
|
10
|
+
}, {
|
|
11
|
+
id: string;
|
|
12
|
+
}>, z.ZodObject<{
|
|
13
|
+
content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
14
|
+
schemaName: z.ZodString;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
content: Record<string, unknown>;
|
|
17
|
+
schemaName: string;
|
|
18
|
+
}, {
|
|
19
|
+
content: Record<string, unknown>;
|
|
20
|
+
schemaName: string;
|
|
21
|
+
}>]>>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
type: "component";
|
|
24
|
+
componentId: string;
|
|
25
|
+
componentSet: string;
|
|
26
|
+
contentItem?: {
|
|
27
|
+
id: string;
|
|
28
|
+
} | {
|
|
29
|
+
content: Record<string, unknown>;
|
|
30
|
+
schemaName: string;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
type: "component";
|
|
34
|
+
componentId: string;
|
|
35
|
+
componentSet: string;
|
|
36
|
+
contentItem?: {
|
|
37
|
+
id: string;
|
|
38
|
+
} | {
|
|
39
|
+
content: Record<string, unknown>;
|
|
40
|
+
schemaName: string;
|
|
41
|
+
} | undefined;
|
|
42
|
+
}>, z.ZodObject<{
|
|
43
|
+
type: z.ZodLiteral<"text">;
|
|
44
|
+
value: z.ZodString;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
value: string;
|
|
47
|
+
type: "text";
|
|
48
|
+
}, {
|
|
49
|
+
value: string;
|
|
50
|
+
type: "text";
|
|
51
|
+
}>, z.ZodObject<{
|
|
52
|
+
type: z.ZodLiteral<"tag">;
|
|
53
|
+
tag: z.ZodString;
|
|
54
|
+
attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
55
|
+
font: z.ZodOptional<z.ZodObject<{
|
|
56
|
+
bold: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
italics: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
+
underline: z.ZodOptional<z.ZodBoolean>;
|
|
59
|
+
color: z.ZodOptional<z.ZodString>;
|
|
60
|
+
size: z.ZodOptional<z.ZodString>;
|
|
61
|
+
fontFamily: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
bold?: boolean | undefined;
|
|
64
|
+
italics?: boolean | undefined;
|
|
65
|
+
underline?: boolean | undefined;
|
|
66
|
+
color?: string | undefined;
|
|
67
|
+
size?: string | undefined;
|
|
68
|
+
fontFamily?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
bold?: boolean | undefined;
|
|
71
|
+
italics?: boolean | undefined;
|
|
72
|
+
underline?: boolean | undefined;
|
|
73
|
+
color?: string | undefined;
|
|
74
|
+
size?: string | undefined;
|
|
75
|
+
fontFamily?: string | undefined;
|
|
76
|
+
}>>;
|
|
77
|
+
formattingOptions: z.ZodOptional<z.ZodObject<{
|
|
78
|
+
alignment: z.ZodEnum<["left", "center", "right", "justify"]>;
|
|
79
|
+
}, "strip", z.ZodTypeAny, {
|
|
80
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
81
|
+
}, {
|
|
82
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
83
|
+
}>>;
|
|
84
|
+
}, "strip", z.ZodTypeAny, {
|
|
85
|
+
type: "tag";
|
|
86
|
+
tag: string;
|
|
87
|
+
attributes?: Record<string, string> | undefined;
|
|
88
|
+
font?: {
|
|
89
|
+
bold?: boolean | undefined;
|
|
90
|
+
italics?: boolean | undefined;
|
|
91
|
+
underline?: boolean | undefined;
|
|
92
|
+
color?: string | undefined;
|
|
93
|
+
size?: string | undefined;
|
|
94
|
+
fontFamily?: string | undefined;
|
|
95
|
+
} | undefined;
|
|
96
|
+
formattingOptions?: {
|
|
97
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
98
|
+
} | undefined;
|
|
99
|
+
}, {
|
|
100
|
+
type: "tag";
|
|
101
|
+
tag: string;
|
|
102
|
+
attributes?: Record<string, string> | undefined;
|
|
103
|
+
font?: {
|
|
104
|
+
bold?: boolean | undefined;
|
|
105
|
+
italics?: boolean | undefined;
|
|
106
|
+
underline?: boolean | undefined;
|
|
107
|
+
color?: string | undefined;
|
|
108
|
+
size?: string | undefined;
|
|
109
|
+
fontFamily?: string | undefined;
|
|
110
|
+
} | undefined;
|
|
111
|
+
formattingOptions?: {
|
|
112
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
113
|
+
} | undefined;
|
|
114
|
+
}>, z.ZodObject<{
|
|
115
|
+
type: z.ZodLiteral<"link-to-matrix-asset">;
|
|
116
|
+
matrixIdentifier: z.ZodOptional<z.ZodString>;
|
|
117
|
+
matrixDomain: z.ZodString;
|
|
118
|
+
matrixAssetId: z.ZodString;
|
|
119
|
+
target: z.ZodEnum<["_blank", "_self", "_parent", "_top"]>;
|
|
120
|
+
formattingOptions: z.ZodOptional<z.ZodObject<{
|
|
121
|
+
alignment: z.ZodEnum<["left", "center", "right", "justify"]>;
|
|
122
|
+
}, "strip", z.ZodTypeAny, {
|
|
123
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
124
|
+
}, {
|
|
125
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
126
|
+
}>>;
|
|
127
|
+
}, "strip", z.ZodTypeAny, {
|
|
128
|
+
type: "link-to-matrix-asset";
|
|
129
|
+
matrixDomain: string;
|
|
130
|
+
matrixAssetId: string;
|
|
131
|
+
target: "_blank" | "_self" | "_parent" | "_top";
|
|
132
|
+
matrixIdentifier?: string | undefined;
|
|
133
|
+
formattingOptions?: {
|
|
134
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
135
|
+
} | undefined;
|
|
136
|
+
}, {
|
|
137
|
+
type: "link-to-matrix-asset";
|
|
138
|
+
matrixDomain: string;
|
|
139
|
+
matrixAssetId: string;
|
|
140
|
+
target: "_blank" | "_self" | "_parent" | "_top";
|
|
141
|
+
matrixIdentifier?: string | undefined;
|
|
142
|
+
formattingOptions?: {
|
|
143
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
144
|
+
} | undefined;
|
|
145
|
+
}>, z.ZodObject<{
|
|
146
|
+
type: z.ZodLiteral<"matrix-image">;
|
|
147
|
+
matrixIdentifier: z.ZodOptional<z.ZodString>;
|
|
148
|
+
matrixDomain: z.ZodString;
|
|
149
|
+
matrixAssetId: z.ZodString;
|
|
150
|
+
formattingOptions: z.ZodOptional<z.ZodObject<{
|
|
151
|
+
alignment: z.ZodEnum<["left", "center", "right", "justify"]>;
|
|
152
|
+
}, "strip", z.ZodTypeAny, {
|
|
153
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
154
|
+
}, {
|
|
155
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
156
|
+
}>>;
|
|
157
|
+
}, "strip", z.ZodTypeAny, {
|
|
158
|
+
type: "matrix-image";
|
|
159
|
+
matrixDomain: string;
|
|
160
|
+
matrixAssetId: string;
|
|
161
|
+
matrixIdentifier?: string | undefined;
|
|
162
|
+
formattingOptions?: {
|
|
163
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
164
|
+
} | undefined;
|
|
165
|
+
}, {
|
|
166
|
+
type: "matrix-image";
|
|
167
|
+
matrixDomain: string;
|
|
168
|
+
matrixAssetId: string;
|
|
169
|
+
matrixIdentifier?: string | undefined;
|
|
170
|
+
formattingOptions?: {
|
|
171
|
+
alignment: "left" | "center" | "right" | "justify";
|
|
172
|
+
} | undefined;
|
|
173
|
+
}>]>;
|
|
174
|
+
type BaseLayoutContentNodes = z.infer<typeof BaseLayoutContentNodes>;
|
|
175
|
+
/**
|
|
176
|
+
* All the nodes which allow children
|
|
177
|
+
*/
|
|
178
|
+
declare const NODES_WITH_CHILDREN: readonly ["tag", "link-to-matrix-asset"];
|
|
179
|
+
type NodesWithChildren = ChooseNodesWithChildren<(typeof NODES_WITH_CHILDREN)[number]>;
|
|
180
|
+
/**
|
|
181
|
+
* Comprehensive list of all nodes and the existence of child nodes within
|
|
182
|
+
*/
|
|
183
|
+
export type LayoutContentNodes = Exclude<BaseLayoutContentNodes, NodesWithChildren> | (NodesWithChildren & {
|
|
184
|
+
children: LayoutContentNodes[];
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Schema for all possible layout content nodes with checks for children
|
|
188
|
+
*/
|
|
189
|
+
export declare const LayoutContentNodes: z.ZodType<LayoutContentNodes, z.ZodTypeDef, BaseLayoutContentNodes>;
|
|
190
|
+
export type PageLayoutContent = z.infer<typeof LayoutContentNodes>[];
|
|
191
|
+
type ContentResolver<K extends LayoutContentNodes['type']> = (node: Extract<LayoutContentNodes, {
|
|
192
|
+
type: K;
|
|
193
|
+
}>) => Promise<LayoutContentNodes>;
|
|
194
|
+
type PossibleResolvers = {
|
|
195
|
+
[K in LayoutContentNodes['type']]?: ContentResolver<K>;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Walk through the layout content and resolve the content items.
|
|
199
|
+
*
|
|
200
|
+
* TODO: think about allowing a resolver configuration to be passed in
|
|
201
|
+
*/
|
|
202
|
+
export declare class PageLayoutContentResolver {
|
|
203
|
+
private contentResolvers;
|
|
204
|
+
constructor(contentResolvers: PossibleResolvers);
|
|
205
|
+
resolve(layoutContent: PageLayoutContent): Promise<PageLayoutContent>;
|
|
206
|
+
}
|
|
207
|
+
type ChooseNodesWithChildren<T extends BaseLayoutContentNodes['type']> = Extract<BaseLayoutContentNodes, {
|
|
208
|
+
type: T;
|
|
209
|
+
}>;
|
|
210
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PageLayoutContentResolver = exports.LayoutContentNodes = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const formatted_text_1 = require("./formatted-text");
|
|
6
|
+
const BaseLayoutContentNodes = zod_1.z.discriminatedUnion('type', [
|
|
7
|
+
formatted_text_1.ComponentNode,
|
|
8
|
+
formatted_text_1.TextNode,
|
|
9
|
+
formatted_text_1.TagNode,
|
|
10
|
+
formatted_text_1.LinkToMatrixAssetNode,
|
|
11
|
+
formatted_text_1.MatrixImageNode,
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* All the nodes which allow children
|
|
15
|
+
*/
|
|
16
|
+
const NODES_WITH_CHILDREN = ['tag', 'link-to-matrix-asset'];
|
|
17
|
+
/**
|
|
18
|
+
* Schema for all possible layout content nodes with checks for children
|
|
19
|
+
*/
|
|
20
|
+
exports.LayoutContentNodes = zod_1.z
|
|
21
|
+
.object({
|
|
22
|
+
children: zod_1.z.lazy(() => zod_1.z.array(exports.LayoutContentNodes)).optional(),
|
|
23
|
+
})
|
|
24
|
+
.and(BaseLayoutContentNodes)
|
|
25
|
+
.refine((value) => {
|
|
26
|
+
// Only certain node types to contain children
|
|
27
|
+
if ('children' in value && NODES_WITH_CHILDREN.includes(value.type) === false) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Walk through the layout content and resolve the content items.
|
|
34
|
+
*
|
|
35
|
+
* TODO: think about allowing a resolver configuration to be passed in
|
|
36
|
+
*/
|
|
37
|
+
class PageLayoutContentResolver {
|
|
38
|
+
constructor(contentResolvers) {
|
|
39
|
+
this.contentResolvers = contentResolvers;
|
|
40
|
+
}
|
|
41
|
+
async resolve(layoutContent) {
|
|
42
|
+
const resolvedContent = [];
|
|
43
|
+
for (let node of layoutContent) {
|
|
44
|
+
if ('children' in node && node.children) {
|
|
45
|
+
node = {
|
|
46
|
+
...node,
|
|
47
|
+
children: await this.resolve(node.children),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const maybeResolver = this.contentResolvers[node.type];
|
|
51
|
+
if (maybeResolver) {
|
|
52
|
+
node = await maybeResolver(node);
|
|
53
|
+
}
|
|
54
|
+
resolvedContent.push(node);
|
|
55
|
+
}
|
|
56
|
+
return resolvedContent;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.PageLayoutContentResolver = PageLayoutContentResolver;
|
|
60
|
+
//# sourceMappingURL=layout-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-content.js","sourceRoot":"","sources":["../src/layout-content.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,qDAA4G;AAE5G,MAAM,sBAAsB,GAAG,OAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC1D,8BAAa;IACb,yBAAQ;IACR,wBAAO;IACP,sCAAqB;IACrB,gCAAe;CAChB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAU,CAAC;AAUrE;;GAEG;AACU,QAAA,kBAAkB,GAAwE,OAAC;KACrG,MAA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