Skip to content

Commit 098e599

Browse files
authored
Merge pull request #12517 from quarto-dev/fix/quarto-preview-conflict
preview - don't set options as a const to avoid conflict with Global Scope
2 parents 4f606a1 + b8b9746 commit 098e599

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,4 @@ All changes included in 1.7:
185185
- ([#12369](https://github.com/quarto-dev/quarto-cli/pull/12369)): `quarto preview` correctly throws a YAML validation error when a `format` key does not conform.
186186
- ([#12459](https://github.com/quarto-dev/quarto-cli/pull/12459)): Add `.page-inset-*` classes to completions.
187187
- ([#12492](https://github.com/quarto-dev/quarto-cli/pull/12492)): Improve shortcode extension template with new parameters and a link to docs.
188+
- ([#12513](https://github.com/quarto-dev/quarto-cli/issues/12513)): Fix an issue with `quarto preview` when using **DiagrammeR** R package for Graphiz diagram.
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
2-
<script>window.backupDefine = window.define; window.define = undefined;</script>
1+
<script>
2+
window.backupDefine = window.define;
3+
window.define = undefined;
4+
</script>
35
<script type="text/javascript" src="quarto-preview.js"></script>
4-
<script>window.define = window.backupDefine; window.backupDefine = undefined;</script>
6+
<script>
7+
window.define = window.backupDefine;
8+
window.backupDefine = undefined;
9+
</script>
510
<script type="text/javascript">
6-
const options = {
7-
origin: "<%- origin %>",
8-
search: "<%- search %>",
9-
inputFile: "<%- inputFile %>",
10-
isPresentation: <%= isPresentation %>
11-
}
1211
document.addEventListener("DOMContentLoaded", function () {
13-
window.QuartoPreview.init(options);
14-
});
12+
window.QuartoPreview.init({
13+
origin: "<%- origin %>",
14+
search: "<%- search %>",
15+
inputFile: "<%- inputFile %>",
16+
isPresentation: <%= isPresentation %>
17+
});
18+
})
1519
</script>

src/webui/quarto-preview/src/index.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,40 @@
44
* Copyright (C) 2023 Posit Software, PBC
55
*/
66

7-
import { connectToServer } from './server/connection';
8-
import { navigationHandler } from './server/navigation';
9-
import { progressHandler } from './server/progress';
7+
import { connectToServer } from "./server/connection";
8+
import { navigationHandler } from "./server/navigation";
9+
import { progressHandler } from "./server/progress";
1010

1111
import { handleExternalLinks } from "./frame/links";
12-
import { handleMecaLinks } from './frame/meca';
12+
import { handleMecaLinks } from "./frame/meca";
1313
import { handleRevealMessages } from "./frame/reveal";
1414
import { handleViewerMessages } from "./frame/viewer";
15-
import { handleCommands } from './frame/commands';
16-
17-
import './ui/fluent.css'
15+
import { handleCommands } from "./frame/commands";
1816

17+
import "./ui/fluent.css";
1918

2019
export interface Options {
21-
origin: string | null,
22-
search: string | null,
23-
inputFile: string | null,
20+
origin: string | null;
21+
search: string | null;
22+
inputFile: string | null;
2423
isPresentation: boolean;
2524
}
2625

26+
// Store the current options
27+
let currentOptions: Options | null = null;
28+
2729
function init(options: Options) {
28-
29-
try {
30+
// Store the options for export
31+
currentOptions = options;
3032

33+
try {
3134
// detect dark mode
3235
const darkMode = detectDarkMode();
3336

3437
// server connection
3538
const disconnect = connectToServer([
3639
progressHandler(darkMode),
37-
navigationHandler()
40+
navigationHandler(),
3841
]);
3942

4043
// handle commands
@@ -50,11 +53,17 @@ function init(options: Options) {
5053

5154
// handle messages as approprate for format
5255
if (options.isPresentation) {
53-
handleRevealMessages(disconnect)
56+
handleRevealMessages(disconnect);
5457
} else {
5558
handleViewerMessages(options.inputFile);
5659
}
5760

61+
// Dispatch event when initialized
62+
const event = new CustomEvent("quarto-preview-initialized", {
63+
detail: options,
64+
});
65+
66+
document.dispatchEvent(event);
5867
} catch (error) {
5968
console.error(error);
6069
}
@@ -69,8 +78,9 @@ function detectDarkMode() {
6978
}
7079
}
7180

72-
export { init }
73-
74-
75-
81+
// Export the current options
82+
function getOptions() {
83+
return currentOptions;
84+
}
7685

86+
export { init, getOptions };

0 commit comments

Comments
 (0)