Skip to content

Commit 06c8550

Browse files
committed
rename the context used for stable html (it's not special to iframes anymore)
1 parent 2415b24 commit 06c8550

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/packages/frontend/jupyter/cell-list.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ import { LLMTools, NotebookMode, Scroll } from "@cocalc/jupyter/types";
3737
import { JupyterActions } from "./browser-actions";
3838
import { Cell } from "./cell";
3939
import HeadingTagComponent from "./heading-tag";
40-
interface IFrameContextType {
40+
interface StableHtmlContextType {
4141
iframeDivRef?: MutableRefObject<any>;
4242
cellListDivRef?: MutableRefObject<any>;
4343
iframeOnScrolls?: { [key: string]: () => void };
4444
}
45-
const IFrameContext = createContext<IFrameContextType>({});
46-
export const useIFrameContext: () => IFrameContextType = () => {
47-
return useContext(IFrameContext);
45+
const StableHtmlContext = createContext<StableHtmlContextType>({});
46+
export const useStableHtmlContext: () => StableHtmlContextType = () => {
47+
return useContext(StableHtmlContext);
4848
};
4949

5050
// 3 extra cells:
@@ -602,7 +602,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
602602
const virtuosoHeightsRef = useRef<{ [index: number]: number }>({});
603603
if (use_windowed_list) {
604604
body = (
605-
<IFrameContext.Provider
605+
<StableHtmlContext.Provider
606606
value={{ iframeDivRef, cellListDivRef, iframeOnScrolls }}
607607
>
608608
<div ref={cellListDivRef} className="smc-vfill">
@@ -682,7 +682,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
682682
{...virtuosoScroll}
683683
/>
684684
</div>
685-
</IFrameContext.Provider>
685+
</StableHtmlContext.Provider>
686686
);
687687
} else {
688688
// This is needed for **the share server**, which hasn't had

src/packages/frontend/jupyter/output-messages/iframe.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ReactDOM from "react-dom";
1313
import useIsMountedRef from "@cocalc/frontend/app-framework/is-mounted-hook";
1414
import useCounter from "@cocalc/frontend/app-framework/counter-hook";
1515
import { get_blob_url } from "../server-urls";
16-
import { useIFrameContext } from "@cocalc/frontend/jupyter/cell-list";
16+
import { useStableHtmlContext } from "@cocalc/frontend/jupyter/cell-list";
1717
import HTML from "./mime-types/html";
1818

1919
// This impact loading the iframe data from the backend project (via the sha1 hash).
@@ -35,9 +35,9 @@ interface Props {
3535

3636
export default function IFrame(props: Props) {
3737
// we only use cached iframe if the iframecontext is setup, e.g., it is in Jupyter notebooks, but not in whiteboards.
38-
const iframeContext = useIFrameContext();
38+
const stableHtmlContext = useStableHtmlContext();
3939
if (
40-
iframeContext.iframeDivRef == null ||
40+
stableHtmlContext.iframeDivRef == null ||
4141
props.cacheId == null ||
4242
!props.trust
4343
) {

src/packages/frontend/jupyter/output-messages/stable-unsafe-html.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ the idle timeout is reset.
2727
import { useCallback, useEffect, useRef } from "react";
2828
import $ from "jquery";
2929
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
30-
import { useIFrameContext } from "@cocalc/frontend/jupyter/cell-list";
30+
import { useStableHtmlContext } from "@cocalc/frontend/jupyter/cell-list";
3131
import { sha1 } from "@cocalc/util/misc";
3232
import TTL from "@isaacs/ttlcache";
3333

@@ -81,7 +81,7 @@ export default function StableUnsafeHtml({
8181
const divRef = useRef<any>(null);
8282
const intervalRef = useRef<any>(null);
8383
const { isVisible, project_id, path, id } = useFrameContext();
84-
const iframeContext = useIFrameContext();
84+
const stableHtmlContext = useStableHtmlContext();
8585

8686
const globalKey = sha1(`${project_id}-${id}-${docId}-${path}-${html}`);
8787

@@ -120,7 +120,7 @@ export default function StableUnsafeHtml({
120120
// }px`;
121121

122122
// clip our immortal html so it isn't visible outside the parent
123-
const parent = $(iframeContext.cellListDivRef?.current)[0];
123+
const parent = $(stableHtmlContext.cellListDivRef?.current)[0];
124124
if (parent != null) {
125125
const parentRect = parent.getBoundingClientRect();
126126
// Calculate the overlap area
@@ -138,7 +138,7 @@ export default function StableUnsafeHtml({
138138
// scroll work in there though -- if you want to see the whole thing, you
139139
// must not collapse it.
140140
const containerRect = $(divRef.current)
141-
.closest(".cocalc-jupyter-rendered")[0]
141+
.closest(".cocalc-output-div")[0]
142142
?.getBoundingClientRect();
143143
const bottom = Math.max(
144144
top,
@@ -216,13 +216,13 @@ export default function StableUnsafeHtml({
216216

217217
useEffect(() => {
218218
// TOOD: can we get rid of interval by using a resize observer on
219-
// this iframeContext.cellListDivRef?
219+
// this stableHtmlContext.cellListDivRef?
220220
intervalRef.current = setInterval(
221221
position,
222222
POSITION_WHEN_MOUNTED_INTERVAL_MS,
223223
);
224-
if (iframeContext.iframeOnScrolls != null) {
225-
iframeContext.iframeOnScrolls[globalKey] = async () => {
224+
if (stableHtmlContext.iframeOnScrolls != null) {
225+
stableHtmlContext.iframeOnScrolls[globalKey] = async () => {
226226
position();
227227
await new Promise(requestAnimationFrame);
228228
position();
@@ -232,7 +232,7 @@ export default function StableUnsafeHtml({
232232
setTimeout(position, 0);
233233

234234
return () => {
235-
delete iframeContext.iframeOnScrolls?.[globalKey];
235+
delete stableHtmlContext.iframeOnScrolls?.[globalKey];
236236
if (intervalRef.current) {
237237
clearInterval(intervalRef.current);
238238
}

0 commit comments

Comments
 (0)