Skip to content

Commit be989a6

Browse files
committed
Add .loose namespace with optionals
1 parent c356e3a commit be989a6

File tree

2 files changed

+261
-0
lines changed

2 files changed

+261
-0
lines changed

content-tree.d.ts

+254
Original file line numberDiff line numberDiff line change
@@ -754,4 +754,258 @@ export declare namespace ContentTree {
754754
columnSettings: TableColumnSettings[];
755755
}
756756
}
757+
namespace loose {
758+
type BodyBlock = Paragraph | Heading | ImageSet | BigNumber | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
759+
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
760+
interface Node {
761+
type: string;
762+
data?: any;
763+
}
764+
interface Parent extends Node {
765+
children: Node[];
766+
}
767+
interface Root extends Node {
768+
type: "root";
769+
body: Body;
770+
}
771+
interface Body extends Parent {
772+
type: "body";
773+
version: number;
774+
children: BodyBlock[];
775+
}
776+
interface Text extends Node {
777+
type: "text";
778+
value: string;
779+
}
780+
interface Break extends Node {
781+
type: "break";
782+
}
783+
interface ThematicBreak extends Node {
784+
type: "thematic-break";
785+
}
786+
interface Paragraph extends Parent {
787+
type: "paragraph";
788+
children: Phrasing[];
789+
}
790+
interface Heading extends Parent {
791+
type: "heading";
792+
children: Text[];
793+
level: "chapter" | "subheading" | "label";
794+
}
795+
interface Strong extends Parent {
796+
type: "strong";
797+
children: Phrasing[];
798+
}
799+
interface Emphasis extends Parent {
800+
type: "emphasis";
801+
children: Phrasing[];
802+
}
803+
interface Strikethrough extends Parent {
804+
type: "strikethrough";
805+
children: Phrasing[];
806+
}
807+
interface Link extends Parent {
808+
type: "link";
809+
url: string;
810+
title: string;
811+
children: Phrasing[];
812+
}
813+
interface List extends Parent {
814+
type: "list";
815+
ordered: boolean;
816+
children: ListItem[];
817+
}
818+
interface ListItem extends Parent {
819+
type: "list-item";
820+
children: (Paragraph | Phrasing)[];
821+
}
822+
interface Blockquote extends Parent {
823+
type: "blockquote";
824+
children: (Paragraph | Phrasing)[];
825+
}
826+
interface Pullquote extends Node {
827+
type: "pullquote";
828+
text: string;
829+
source?: string;
830+
}
831+
interface ImageSet extends Node {
832+
type: "image-set";
833+
id: string;
834+
picture?: ImageSetPicture;
835+
}
836+
type ImageSetPicture = {
837+
layoutWidth: string;
838+
imageType: "image" | "graphic";
839+
alt: string;
840+
caption: string;
841+
credit: string;
842+
images: Image[];
843+
fallbackImage: Image;
844+
};
845+
type Image = {
846+
id: string;
847+
width: number;
848+
height: number;
849+
format: "desktop" | "mobile" | "square" | "square-ftedit" | "standard" | "wide" | "standard-inline";
850+
url: string;
851+
sourceSet?: ImageSource[];
852+
};
853+
type ImageSource = {
854+
url: string;
855+
width: number;
856+
dpr: number;
857+
};
858+
interface Recommended extends Node {
859+
type: "recommended";
860+
id: string;
861+
heading?: string;
862+
teaserTitleOverride?: string;
863+
teaser?: Teaser;
864+
}
865+
type TeaserConcept = {
866+
apiUrl: string;
867+
directType: string;
868+
id: string;
869+
predicate: string;
870+
prefLabel: string;
871+
type: string;
872+
types: string[];
873+
url: string;
874+
};
875+
type Teaser = {
876+
id: string;
877+
url: string;
878+
type: "article" | "video" | "podcast" | "audio" | "package" | "liveblog" | "promoted-content" | "paid-post";
879+
title: string;
880+
publishedDate: string;
881+
firstPublishedDate: string;
882+
metaLink?: TeaserConcept;
883+
metaAltLink?: TeaserConcept;
884+
metaPrefixText?: string;
885+
metaSuffixText?: string;
886+
indicators: {
887+
accessLevel: "premium" | "subscribed" | "registered" | "free";
888+
isOpinion?: boolean;
889+
isColumn?: boolean;
890+
isPodcast?: boolean;
891+
isEditorsChoice?: boolean;
892+
isExclusive?: boolean;
893+
isScoop?: boolean;
894+
};
895+
image: {
896+
url: string;
897+
width: number;
898+
height: number;
899+
};
900+
};
901+
interface Tweet extends Node {
902+
id: string;
903+
type: "tweet";
904+
html?: string;
905+
}
906+
interface Flourish extends Node {
907+
type: "flourish";
908+
id: string;
909+
layoutWidth: string;
910+
flourishType: string;
911+
description?: string;
912+
timestamp?: string;
913+
fallbackImage?: Image;
914+
}
915+
interface BigNumber extends Node {
916+
type: "big-number";
917+
number: string;
918+
description: string;
919+
}
920+
interface Video extends Node {
921+
type: "video";
922+
id: string;
923+
embedded: boolean;
924+
}
925+
interface YoutubeVideo extends Node {
926+
type: "youtube-video";
927+
url: string;
928+
}
929+
interface ScrollyBlock extends Parent {
930+
type: "scrolly-block";
931+
theme: "sans" | "serif";
932+
children: ScrollySection[];
933+
}
934+
interface ScrollySection extends Parent {
935+
type: "scrolly-section";
936+
display: "dark-background" | "light-background";
937+
noBox?: true;
938+
position: "left" | "center" | "right";
939+
transition?: "delay-before" | "delay-after";
940+
children: [ScrollyImage, ...ScrollyCopy[]];
941+
}
942+
interface ScrollyImage extends Node {
943+
type: "scrolly-image";
944+
id: string;
945+
picture?: ImageSetPicture;
946+
}
947+
interface ScrollyCopy extends Parent {
948+
type: "scrolly-copy";
949+
children: (ScrollyHeading | Paragraph)[];
950+
}
951+
interface ScrollyHeading extends Parent {
952+
type: "scrolly-heading";
953+
level: "chapter" | "heading" | "subheading";
954+
children: Text[];
955+
}
956+
interface Layout extends Parent {
957+
type: "layout";
958+
layoutName: "auto" | "card" | "timeline";
959+
layoutWidth: string;
960+
children: [Heading, LayoutImage, ...LayoutSlot[]] | [Heading, ...LayoutSlot[]] | LayoutSlot[];
961+
}
962+
interface LayoutSlot extends Parent {
963+
type: "layout-slot";
964+
children: (Heading | Paragraph | LayoutImage)[];
965+
}
966+
interface LayoutImage extends Node {
967+
type: "layout-image";
968+
id: string;
969+
alt: string;
970+
caption: string;
971+
credit: string;
972+
picture?: ImageSetPicture;
973+
}
974+
type TableColumnSettings = {
975+
hideOnMobile: boolean;
976+
sortable: boolean;
977+
sortType: 'text' | 'number' | 'date' | 'currency' | 'percent';
978+
};
979+
interface TableCaption extends Parent {
980+
type: 'table-caption';
981+
children: Phrasing[];
982+
}
983+
interface TableCell extends Parent {
984+
type: 'table-cell';
985+
heading?: boolean;
986+
children: Phrasing[];
987+
}
988+
interface TableRow extends Parent {
989+
type: 'table-row';
990+
children: TableCell[];
991+
}
992+
interface TableBody extends Parent {
993+
type: 'table-body';
994+
children: TableRow[];
995+
}
996+
interface TableFooter extends Parent {
997+
type: 'table-footer';
998+
children: Phrasing[];
999+
}
1000+
interface Table extends Parent {
1001+
type: 'table';
1002+
stripes: boolean;
1003+
compact: boolean;
1004+
layoutWidth: 'auto' | 'full-grid' | 'inset-left' | 'inset-right' | 'full-bleed';
1005+
collapseAfterHowManyRows?: number;
1006+
responsiveStyle: 'overflow' | 'flat' | 'scroll';
1007+
children: [TableCaption, TableBody, TableFooter] | [TableCaption, TableBody] | [TableBody, TableFooter] | [TableBody];
1008+
columnSettings: TableColumnSettings[];
1009+
}
1010+
}
7571011
}

tools/maketypes/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const code = tangle(doc).replace(
1919
const full = code.replace(/^(\s+)external (.+)$/gm, "$1$2")
2020
// in the transit tree, externals must not be present
2121
const transit = code.replace(/^\s+external (.+:).+$/gm, "")
22+
// in the loose tree, externals are optional
23+
const loose = code.replace(/^(\s+)external (.+):(.+)$/gm, "$1$2?:$3")
2224

2325
process.stdout.write("export namespace ContentTree {\n")
2426
// make content-tree nodes available on the root namespace
@@ -34,4 +36,9 @@ process.stdout.write("export namespace transit {\n")
3436
process.stdout.write(transit.replace(/^/gm, "\t\t"))
3537
process.stdout.write("\n}\n")
3638

39+
// make the loose tree nodes available on ContentTree.loose
40+
process.stdout.write("export namespace loose {\n")
41+
process.stdout.write(loose.replace(/^/gm, "\t\t"))
42+
process.stdout.write("\n}\n")
43+
3744
process.stdout.write("\n}\n")

0 commit comments

Comments
 (0)