-
Notifications
You must be signed in to change notification settings - Fork 276
/
models.ts
139 lines (126 loc) · 2.81 KB
/
models.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* A reply from the Sitecore Layout Service
*/
export interface LayoutServiceData {
sitecore: LayoutServiceContextData & {
route: RouteData | null;
};
}
/**
* Layout Service page state enum
*/
export enum LayoutServicePageState {
Preview = 'preview',
Edit = 'edit',
Normal = 'normal',
}
/**
* Shape of context data from the Sitecore Layout Service
*/
export interface LayoutServiceContext {
[key: string]: unknown;
pageEditing?: boolean;
language?: string;
pageState?: LayoutServicePageState;
visitorIdentificationTimestamp?: number;
site?: {
name?: string;
};
}
/**
* Context information from the Sitecore Layout Service
*/
export interface LayoutServiceContextData {
context: LayoutServiceContext;
}
/**
* Shape of route data returned from Sitecore Layout Service
*/
export interface RouteData {
name: string;
displayName?: string;
fields?: {
[name: string]: Field;
};
databaseName?: string;
deviceId?: string;
itemLanguage?: string;
itemVersion?: number;
layoutId?: string;
templateId?: string;
templateName?: string;
placeholders: PlaceholdersData;
itemId?: string;
}
/**
* Placeholder contents data (name: placeholder name, then array of components within that placeholder name)
* Note: HtmlElementRendering is used by Sitecore Experience Editor
*/
export type PlaceholdersData<TYPEDNAME extends string = string> = {
[P in TYPEDNAME]: Array<ComponentRendering | HtmlElementRendering>;
};
/**
* Content field data passed to a component
*/
export interface ComponentFields {
[name: string]: Field | Item | Item[];
}
/**
* Component params
*/
export interface ComponentParams {
[name: string]: string;
}
/**
* Definition of a component instance within a placeholder on a route
*/
export interface ComponentRendering {
componentName: string;
dataSource?: string;
uid?: string;
placeholders?: PlaceholdersData;
fields?: ComponentFields;
params?: ComponentParams;
}
/**
* HTML content used to support Sitecore Experience Editor
*/
export interface HtmlElementRendering {
name: string;
type?: string;
contents: string | null;
attributes: {
[name: string]: string | undefined;
};
}
/**
* Field value data on a component
*/
export type GenericFieldValue =
| string
| boolean
| number
| { [key: string]: unknown }
| Array<{ [key: string]: unknown }>;
export interface Field<T = GenericFieldValue> {
value: T;
editable?: string;
}
/**
* Content data returned from Content Service
*/
export interface Item {
name: string;
displayName?: string;
fields: {
[name: string]: Field | Item | Item[] | undefined;
};
}
/**
* Contents of a single placeholder returned from placeholder service
*/
export interface PlaceholderData {
name: string;
path: string;
elements: Array<HtmlElementRendering | ComponentRendering>;
}