Skip to content

Commit 4245ebe

Browse files
authored
build: Update shiny TS types to Shiny 1.10.0 (#1893)
1 parent 60fbef9 commit 4245ebe

File tree

15 files changed

+107
-109
lines changed

15 files changed

+107
-109
lines changed

js/chat/chat.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class ChatInput extends LightElement {
224224
if (this.valueIsEmpty) return;
225225
if (this.disabled) return;
226226

227-
Shiny.setInputValue!(this.id, this.value, { priority: "event" });
227+
window.Shiny.setInputValue!(this.id, this.value, { priority: "event" });
228228

229229
// Emit event so parent element knows to insert the message
230230
const sentEvent = new CustomEvent("shiny-chat-input-sent", {
@@ -527,28 +527,26 @@ customElements.define(CHAT_MESSAGES_TAG, ChatMessages);
527527
customElements.define(CHAT_INPUT_TAG, ChatInput);
528528
customElements.define(CHAT_CONTAINER_TAG, ChatContainer);
529529

530-
$(function () {
531-
Shiny.addCustomMessageHandler(
532-
"shinyChatMessage",
533-
function (message: ShinyChatMessage) {
534-
const evt = new CustomEvent(message.handler, {
535-
detail: message.obj,
536-
});
530+
window.Shiny.addCustomMessageHandler(
531+
"shinyChatMessage",
532+
function (message: ShinyChatMessage) {
533+
const evt = new CustomEvent(message.handler, {
534+
detail: message.obj,
535+
});
537536

538-
const el = document.getElementById(message.id);
537+
const el = document.getElementById(message.id);
539538

540-
if (!el) {
541-
showShinyClientMessage({
542-
status: "error",
543-
message: `Unable to handle Chat() message since element with id
539+
if (!el) {
540+
showShinyClientMessage({
541+
status: "error",
542+
message: `Unable to handle Chat() message since element with id
544543
${message.id} wasn't found. Do you need to call .ui() (Express) or need a
545544
chat_ui('${message.id}') in the UI (Core)?
546545
`,
547-
});
548-
return;
549-
}
550-
551-
el.dispatchEvent(evt);
546+
});
547+
return;
552548
}
553-
);
554-
});
549+
550+
el.dispatchEvent(evt);
551+
}
552+
);

js/data-frame/index.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
527527
useEffect(() => {
528528
if (!htmlDeps) return;
529529
// Register the Shiny HtmlDependencies
530-
Shiny.renderDependenciesAsync([...htmlDeps]);
530+
window.Shiny.renderDependenciesAsync([...htmlDeps]);
531531
}, [htmlDeps]);
532532

533533
useEffect(() => {
@@ -701,7 +701,7 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
701701
} else {
702702
console.error("Unhandled row selection mode:", selectionModes);
703703
}
704-
Shiny.setInputValue!(`${id}_cell_selection`, shinyValue);
704+
window.Shiny.setInputValue!(`${id}_cell_selection`, shinyValue);
705705
}, [id, selection, selectionModes, table, table.getSortedRowModel]);
706706

707707
useEffect(() => {
@@ -714,10 +714,10 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
714714
desc: sortObj.desc,
715715
});
716716
});
717-
Shiny.setInputValue!(`${id}_sort`, shinySort);
717+
window.Shiny.setInputValue!(`${id}_sort`, shinySort);
718718

719719
// Deprecated as of 2024-05-21
720-
Shiny.setInputValue!(`${id}_column_sort`, shinySort);
720+
window.Shiny.setInputValue!(`${id}_column_sort`, shinySort);
721721
}, [columns, id, sorting]);
722722
useEffect(() => {
723723
if (!id) return;
@@ -732,10 +732,10 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
732732
value: filterObj.value as FilterValue,
733733
});
734734
});
735-
Shiny.setInputValue!(`${id}_filter`, shinyFilter);
735+
window.Shiny.setInputValue!(`${id}_filter`, shinyFilter);
736736

737737
// Deprecated as of 2024-05-21
738-
Shiny.setInputValue!(`${id}_column_filter`, shinyFilter);
738+
window.Shiny.setInputValue!(`${id}_column_filter`, shinyFilter);
739739
}, [id, columnFilters, columns]);
740740
useEffect(() => {
741741
if (!id) return;
@@ -744,10 +744,10 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
744744
// Already prefiltered rows!
745745
.getSortedRowModel()
746746
.rows.map((row) => row.index);
747-
Shiny.setInputValue!(`${id}_data_view_rows`, shinyRows);
747+
window.Shiny.setInputValue!(`${id}_data_view_rows`, shinyRows);
748748

749749
// Legacy value as of 2024-05-13
750-
Shiny.setInputValue!(`${id}_data_view_indices`, shinyRows);
750+
window.Shiny.setInputValue!(`${id}_data_view_indices`, shinyRows);
751751
}, [
752752
id,
753753
table,
@@ -773,7 +773,7 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
773773
.filter((x): x is number => x !== null)
774774
.sort();
775775
}
776-
Shiny.setInputValue!(`${id}_selected_rows`, shinyValue);
776+
window.Shiny.setInputValue!(`${id}_selected_rows`, shinyValue);
777777
}, [id, selection, selectionModes, table]);
778778

779779
// ### End row selection ############################################################
@@ -1083,7 +1083,7 @@ function useVirtualizerMeasureWorkaround(
10831083
return measureElementWithRetry;
10841084
}
10851085

1086-
class ShinyDataFrameOutputBinding extends Shiny.OutputBinding {
1086+
class ShinyDataFrameOutputBinding extends window.Shiny.OutputBinding {
10871087
find(scope: HTMLElement | JQuery<HTMLElement>): JQuery<HTMLElement> {
10881088
return $(scope).find("shiny-data-frame");
10891089
}
@@ -1103,7 +1103,7 @@ class ShinyDataFrameOutputBinding extends Shiny.OutputBinding {
11031103
el.clearError();
11041104
}
11051105
}
1106-
Shiny.outputBindings.register(
1106+
window.Shiny.outputBindings.register(
11071107
new ShinyDataFrameOutputBinding(),
11081108
"shinyDataFrame"
11091109
);
@@ -1214,12 +1214,13 @@ customElements.define("shiny-data-frame", ShinyDataFrameOutput);
12141214
// react listener.
12151215
// It would be better to have something similar to session.send_input_message
12161216
// for updating outputs, but that requires changes to ShinyJS.
1217-
$(function () {
1218-
Shiny.addCustomMessageHandler("shinyDataFrameMessage", function (message) {
1217+
window.Shiny.addCustomMessageHandler(
1218+
"shinyDataFrameMessage",
1219+
function (message) {
12191220
const evt = new CustomEvent(message.handler, {
12201221
detail: message.obj,
12211222
});
12221223
const el = document.getElementById(message.id);
12231224
el?.dispatchEvent(evt);
1224-
});
1225-
});
1225+
}
1226+
);

js/markdown-stream/markdown-stream.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ function handleMessage(message: ContentMessage | IsStreamingMessage): void {
272272
}
273273
}
274274

275-
$(function () {
276-
Shiny.addCustomMessageHandler("shinyMarkdownStreamMessage", handleMessage);
277-
});
275+
window.Shiny.addCustomMessageHandler(
276+
"shinyMarkdownStreamMessage",
277+
handleMessage
278+
);
278279

279280
export { MarkdownElement, contentToHTML };

js/package-lock.json

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/node": "^20.14.10",
1818
"@types/react": "^18.3.3",
1919
"@types/react-dom": "^18.3.0",
20-
"@types/rstudio-shiny": "git+https://git@github.com/rstudio/shiny.git#v1.8.0",
20+
"@types/rstudio-shiny": "git+https://git@github.com/rstudio/shiny.git#v1.10.0",
2121
"@typescript-eslint/eslint-plugin": "^5.59.7",
2222
"@typescript-eslint/parser": "^5.59.7",
2323
"esbuild": "^0.18.11",

js/page-output/page-output.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import type { ErrorsMessageValue } from "rstudio-shiny/srcts/types/src/shiny/shinyapp";
22

3-
class PageOutputBinding extends Shiny.OutputBinding {
3+
class PageOutputBinding extends window.Shiny.OutputBinding {
44
originalBodyTagAttrs: Array<Attr> | null = null;
55

66
find(scope: HTMLElement | JQuery<HTMLElement>): JQuery<HTMLElement> {
77
return $(scope).find(".shiny-page-output");
88
}
99

1010
onValueError(el: HTMLElement, err: ErrorsMessageValue): void {
11-
if (Shiny.unbindAll) Shiny.unbindAll(el);
11+
if (window.Shiny.unbindAll) window.Shiny.unbindAll(el);
1212
this.renderError(el, err);
1313
}
1414

1515
async renderValue(
1616
el: HTMLElement,
17-
data: Parameters<typeof Shiny.renderContentAsync>[1]
17+
data: Parameters<typeof window.Shiny.renderContentAsync>[1]
1818
): Promise<void> {
1919
if (data === null) return;
2020
if (el !== document.body) {
@@ -67,11 +67,11 @@ class PageOutputBinding extends Shiny.OutputBinding {
6767
data.html = content;
6868
}
6969

70-
await Shiny.renderContentAsync(el, data);
70+
await window.Shiny.renderContentAsync(el, data);
7171
}
7272
}
7373

74-
Shiny.outputBindings.register(
74+
window.Shiny.outputBindings.register(
7575
new PageOutputBinding(),
7676
"shinyPageOutputBinding"
7777
);

shiny/api-examples/send_custom_message/app-core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
ui.tags.div(id="messages"),
99
ui.tags.script(
1010
"""
11-
$(function() {
12-
Shiny.addCustomMessageHandler("append_msg", function(message) {
13-
$("<p>").text(message.msg).appendTo("#messages");
14-
});
11+
Shiny.addCustomMessageHandler("append_msg", function(message) {
12+
$("<p>").text(message.msg).appendTo("#messages");
1513
});
1614
"""
1715
),

shiny/api-examples/send_custom_message/app-express.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
ui.tags.div(id="messages")
99
ui.tags.script(
1010
"""
11-
$(function() {
12-
Shiny.addCustomMessageHandler("append_msg", function(message) {
13-
$("<p>").text(message.msg).appendTo("#messages");
14-
});
11+
Shiny.addCustomMessageHandler("append_msg", function(message) {
12+
$("<p>").text(message.msg).appendTo("#messages");
1513
});
1614
"""
1715
)

shiny/www/py-shiny/chat/chat.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/chat/chat.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)