-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathtypes.ts
More file actions
339 lines (295 loc) · 8.48 KB
/
types.ts
File metadata and controls
339 lines (295 loc) · 8.48 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
* types.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*/
import { RenderServices } from "../command/render/types.ts";
import { Metadata, PandocFlags } from "../config/types.ts";
import { Format, FormatExtras } from "../config/types.ts";
import {
Brand,
LightDarkBrand,
LightDarkBrandDarkFlag,
} from "../core/brand/brand.ts";
import { MappedString } from "../core/mapped-text.ts";
import { PartitionedMarkdown } from "../core/pandoc/types.ts";
import {
ExecutionEngineDiscovery,
ExecutionEngineInstance,
ExecutionTarget,
} from "../execute/types.ts";
import { InspectedMdCell } from "../inspect/inspect-types.ts";
import { NotebookContext } from "../render/notebook/notebook-types.ts";
import {
LogoLightDarkSpecifier,
NavigationItem as NavItem,
NavigationItemObject,
NavigationItemObject as SidebarTool,
ProjectConfig as ProjectConfig_Project,
} from "../resources/types/schema-types.ts";
import { ProjectEnvironment } from "./project-environment-types.ts";
import { ProjectCache } from "../core/cache/cache-types.ts";
import { TempContext } from "../core/temp-types.ts";
import { Cloneable } from "../core/safe-clone-deep.ts";
export {
type NavigationItem as NavItem,
type NavigationItemObject,
type NavigationItemObject as SidebarTool,
type PageFooter as NavigationFooter,
type ProjectPreview,
} from "../resources/types/schema-types.ts";
export const kProjectType = "type";
export const kProjectTitle = "title";
export const kProjectRender = "render";
export const kProjectPreRender = "pre-render";
export const kProjectPostRender = "post-render";
export const kProjectExecuteDir = "execute-dir";
export const kProjectOutputDir = "output-dir";
export const kProjectLibDir = "lib-dir";
export const kProjectResources = "resources";
export const kProjectWatchInputs = "watch-inputs";
export type FileInclusion = {
source: string;
target: string;
};
export type FileInformation = {
fullMarkdown?: MappedString;
includeMap?: FileInclusion[];
codeCells?: InspectedMdCell[];
engine?: ExecutionEngineInstance;
target?: ExecutionTarget;
metadata?: Metadata;
brand?: LightDarkBrandDarkFlag;
};
export interface FileInformationCache extends Map<string, FileInformation> {
// Removes a cache entry and cleans up any associated transient files from disk.
// Use this instead of delete() when invalidating entries that may reference
// transient notebooks (.quarto_ipynb) to prevent file accumulation.
invalidateForFile(key: string): void;
}
export interface ProjectContext extends Cloneable<ProjectContext> {
dir: string;
engines: string[];
files: ProjectFiles;
config?: ProjectConfig;
notebookContext: NotebookContext;
outputNameIndex?: Map<string, { file: string; format: Format } | undefined>;
fileInformationCache: FileInformationCache;
// This is a cache of _brand.yml for a project
brandCache?: { brand?: LightDarkBrandDarkFlag };
resolveBrand: (
fileName?: string,
) => Promise<
undefined | LightDarkBrandDarkFlag
>;
// expands markdown for a file
// input file doesn't have to be markdown; it can be, for example, a knitr spin file
// output file is always markdown, though, and it is cached in the project
resolveFullMarkdownForFile: (
engine: ExecutionEngineInstance | undefined,
file: string,
markdown?: MappedString,
force?: boolean,
) => Promise<MappedString>;
fileExecutionEngineAndTarget: (
file: string,
force?: boolean,
) => Promise<{ engine: ExecutionEngineInstance; target: ExecutionTarget }>;
fileMetadata: (
file: string,
force?: boolean,
) => Promise<Metadata>;
formatExtras?: (
source: string,
flags: PandocFlags,
format: Format,
services: RenderServices,
) => Promise<FormatExtras>;
// declaring renderFormats here is a relatively ugly hack to avoid a circular import chain
// that causes a deno bundler bug
renderFormats: (
file: string,
services: RenderServices,
to: string | undefined,
project: ProjectContext,
) => Promise<Record<string, Format>>;
environment: () => Promise<ProjectEnvironment>;
isSingleFile: boolean;
previewServer?: boolean;
diskCache: ProjectCache;
temp: TempContext;
cleanup: () => void;
}
export interface ProjectFiles {
input: string[];
resources?: string[];
config?: string[];
configResources?: string[];
}
export interface ProjectConfig {
project: ProjectConfig_Project;
[key: string]: unknown;
}
export const kProject404File = "404.html";
export type LayoutBreak = "" | "sm" | "md" | "lg" | "xl" | "xxl";
/**
* A restricted version of ProjectContext that only exposes
* functionality needed by execution engines.
*/
export interface EngineProjectContext {
/**
* Base directory of the project
*/
dir: string;
/**
* Flag indicating if project consists of a single file
*/
isSingleFile: boolean;
/**
* Config object containing project configuration
* Used primarily for config?.engines access
* Can contain arbitrary configuration properties
*/
config?: {
engines?: string[];
project?: {
[kProjectOutputDir]?: string;
};
[key: string]: unknown;
};
/**
* For file information cache management
* Used for the transient notebook tracking in Jupyter
*/
fileInformationCache: FileInformationCache;
/**
* Get the output directory for the project
*
* @returns Path to output directory
*/
getOutputDirectory: () => string;
/**
* Resolves full markdown content for a file, including expanding includes
*
* @param engine - The execution engine
* @param file - Path to the file
* @param markdown - Optional existing markdown content
* @param force - Whether to force re-resolution even if cached
* @returns Promise resolving to mapped markdown string
*/
resolveFullMarkdownForFile: (
engine: ExecutionEngineInstance | undefined,
file: string,
markdown?: MappedString,
force?: boolean,
) => Promise<MappedString>;
}
export const kAriaLabel = "aria-label";
export const kCollapseLevel = "collapse-level";
export const kCollapseBelow = "collapse-below";
export const kToolsCollapse = "tools-collapse";
export const kLogoAlt = "logo-alt";
export const kLogoHref = "logo-href";
export const kSidebarMenus = "sidebar-menus";
export interface Navbar {
title?: string | false;
logo?: LogoLightDarkSpecifier;
[kLogoAlt]?: string;
[kLogoHref]?: string;
background:
| "primary"
| "secondary"
| "success"
| "danger"
| "warning"
| "info"
| "light"
| "dark";
search?: boolean | string;
left?: NavItem[];
right?: NavItem[];
collapse?: boolean;
tools?: SidebarTool[];
pinned?: boolean;
[kCollapseBelow]?: LayoutBreak;
[kSidebarMenus]?: boolean;
darkToggle?: boolean;
readerToggle?: boolean;
[kToolsCollapse]?: boolean;
}
/* export interface NavItem {
// href + more readable/understndable aliases
icon?: string;
href?: string;
file?: string;
text?: string;
url?: string;
[kAriaLabel]?: string;
// core identification
id?: string;
// more
menu?: NavItem[];
}
*/
export interface Sidebar {
id?: string;
title?: string;
subtitle?: string;
logo?: LogoLightDarkSpecifier;
[kLogoAlt]?: string;
[kLogoHref]?: string;
alignment?: "left" | "right" | "center";
align?: "left" | "right" | "center"; // This is here only because older versions of Quarto used to use it even though it wasn't documented
background?:
| "none"
| "primary"
| "secondary"
| "success"
| "danger"
| "warning"
| "info"
| "light"
| "dark"
| "white";
search?: boolean | string;
[kCollapseLevel]?: number;
contents: SidebarItem[];
tools: SidebarTool[];
style: "docked" | "floating";
pinned?: boolean;
header?: Array<string> | string;
footer?: Array<string> | string;
}
export type SidebarItem = NavigationItemObject & {
// core structure/contents
section?: string;
sectionId?: string;
contents?: SidebarItem[];
// more
expanded?: boolean;
active?: boolean;
// transient properties used for expanding 'auto'
auto?: boolean | string | string[];
};
export interface InputTargetIndex extends Metadata {
title?: string;
markdown: PartitionedMarkdown;
formats: Record<string, Format>;
draft?: boolean;
}
export interface InputTarget {
input: string;
title?: string;
outputHref: string;
draft: boolean;
}
/*export interface SidebarTool {
// label/contents
icon?: string;
text?: string;
menu?: NavItem[];
// href + more readable/understndable aliases
href?: string;
file?: string;
url?: string;
}*/