1
0

Upgrade @codemirror/view and height fixes

This commit is contained in:
Zef Hemel 2024-01-02 12:43:10 +01:00
parent 11693fbd00
commit 6b6ab30c92
6 changed files with 28 additions and 6 deletions

View File

@ -10,7 +10,7 @@
"@codemirror/state": "https://esm.sh/@codemirror/state@6.3.3&target=es2022",
"@codemirror/language": "https://esm.sh/@codemirror/language@6.9.3?external=@codemirror/state,@lezer/common,@lezer/lr,@codemirror/view,@lezer/highlight&target=es2022",
"@codemirror/commands": "https://esm.sh/@codemirror/commands@6.2.4?external=@codemirror/state,@codemirror/view&target=es2022",
"@codemirror/view": "https://esm.sh/@codemirror/view@6.9.0?external=@codemirror/state,@lezer/common&target=es2022",
"@codemirror/view": "https://esm.sh/@codemirror/view@6.23.0?external=@codemirror/state,@lezer/common&target=es2022",
"@codemirror/autocomplete": "https://esm.sh/@codemirror/autocomplete@6.7.1?external=@codemirror/state,@codemirror/commands,@lezer/common,@codemirror/view&target=es2022",
"@codemirror/lint": "https://esm.sh/@codemirror/lint@6.4.1?external=@codemirror/state,@codemirror/view,@lezer/common&target=es2022",
"@codemirror/lang-css": "https://esm.sh/@codemirror/lang-css@6.2.1?external=@codemirror/language,@codemirror/autocomplete,@codemirror/state,@lezer/lr,@lezer/html&target=es2022",

View File

@ -58,7 +58,7 @@ export class IFrameWidget extends WidgetType {
get estimatedHeight(): number {
const cachedHeight = this.client.getCachedWidgetHeight(this.bodyText);
// console.log("Calling estimated height", cachedHeight);
console.log("Calling estimated height", this.bodyText, cachedHeight);
return cachedHeight > 0 ? cachedHeight : 150;
}

View File

@ -104,7 +104,7 @@ export class MarkdownWidget extends WidgetType {
setTimeout(() => {
this.client.setWidgetCache(
this.bodyText,
{ height: div.clientHeight, html, buttons: widgetContent.buttons },
{ height: div.offsetHeight, html, buttons: widgetContent.buttons },
);
});
}
@ -185,7 +185,7 @@ export class MarkdownWidget extends WidgetType {
get estimatedHeight(): number {
const cacheItem = this.client.getWidgetCache(this.bodyText);
// console.log("Calling estimated height", cacheItem);
console.log("Calling estimated height", this.bodyText, cacheItem);
return cacheItem ? cacheItem.height : -1;
}

View File

@ -63,7 +63,7 @@ class TableViewWidget extends WidgetType {
const height = this.client.getCachedWidgetHeight(
`table:${this.tableBodyText}`,
);
console.log("Calling estimated height for table", height);
// console.log("Calling estimated height for table", height);
return height;
}

View File

@ -28,11 +28,27 @@ export class LinkWidget extends WidgetType {
const anchor = document.createElement("a");
anchor.className = this.options.cssClass;
anchor.textContent = this.options.text;
anchor.addEventListener("click", (e) => {
// Mouse handling
anchor.addEventListener("mousedown", (e) => {
e.preventDefault();
e.stopPropagation();
this.options.callback(e);
});
// Touch handling
let touchCount = 0;
anchor.addEventListener("touchmove", () => {
touchCount++;
});
anchor.addEventListener("touchend", (e) => {
if (touchCount === 0) {
e.preventDefault();
e.stopPropagation();
this.options.callback(new MouseEvent("click", e));
}
touchCount = 0;
});
anchor.setAttribute("title", this.options.title);
anchor.href = this.options.href || "#";
return anchor;

View File

@ -185,6 +185,12 @@ export function mountIFrame(
iframe.contentWindow!.location.href = resolvedContent.url;
if (resolvedContent.height) {
iframe.height = resolvedContent.height + "px";
if (widgetHeightCacheKey) {
client.setCachedWidgetHeight(
widgetHeightCacheKey!,
resolvedContent.height,
);
}
}
if (resolvedContent.width) {
iframe.width = resolvedContent.width + "px";