Federation progress

This commit is contained in:
Zef Hemel
2023-07-29 23:41:37 +02:00
parent 272bd90ee6
commit fe4887dc78
11 changed files with 112 additions and 49 deletions
+11 -8
View File
@@ -7,14 +7,14 @@ import {
} from "../deps.ts";
import { decoratorStateField } from "./util.ts";
import type { Space } from "../space.ts";
import type { Client } from "../client.ts";
import { resolvePath } from "$sb/lib/resolve.ts";
class InlineImageWidget extends WidgetType {
constructor(
readonly url: string,
readonly title: string,
readonly space: Space,
readonly client: Client,
) {
super();
// console.log("Creating widget", url);
@@ -25,22 +25,25 @@ class InlineImageWidget extends WidgetType {
}
get estimatedHeight(): number {
const cachedHeight = this.space.getCachedImageHeight(this.url);
const cachedHeight = this.client.space.getCachedImageHeight(this.url);
// console.log("Estimated height requested", this.url, cachedHeight);
return cachedHeight;
}
toDOM() {
const img = document.createElement("img");
let url = this.url;
url = resolvePath(this.client.currentPage!, url, true);
console.log("Resolving image to", url);
// console.log("Creating DOM", this.url);
const cachedImageHeight = this.space.getCachedImageHeight(this.url);
const cachedImageHeight = this.client.space.getCachedImageHeight(url);
img.onload = () => {
// console.log("Loaded", this.url, "with height", img.height);
if (img.height !== cachedImageHeight) {
this.space.setCachedImageHeight(this.url, img.height);
this.client.space.setCachedImageHeight(url, img.height);
}
};
img.src = this.url;
img.src = url;
img.alt = this.title;
img.title = this.title;
img.style.display = "block";
@@ -53,7 +56,7 @@ class InlineImageWidget extends WidgetType {
}
}
export function inlineImagesPlugin(editor: Client) {
export function inlineImagesPlugin(client: Client) {
return decoratorStateField((state: EditorState) => {
const widgets: Range<Decoration>[] = [];
const imageRegex = /!\[(?<title>[^\]]*)\]\((?<url>.+)\)/;
@@ -78,7 +81,7 @@ export function inlineImagesPlugin(editor: Client) {
}
widgets.push(
Decoration.widget({
widget: new InlineImageWidget(url, title, editor.space),
widget: new InlineImageWidget(url, title, client),
block: true,
}).range(node.to),
);
+2 -1
View File
@@ -9,6 +9,7 @@ import { renderMarkdownToHtml } from "../../plugs/markdown/markdown_render.ts";
import { ParseTree } from "$sb/lib/tree.ts";
import { lezerToParseTree } from "../../common/markdown_parser/parse_tree.ts";
import type { Client } from "../client.ts";
import { resolvePath } from "$sb/lib/resolve.ts";
class TableViewWidget extends WidgetType {
constructor(
@@ -39,7 +40,7 @@ class TableViewWidget extends WidgetType {
annotationPositions: true,
translateUrls: (url) => {
if (!url.includes("://")) {
return `/${url}`;
url = resolvePath(this.editor.currentPage!, decodeURI(url), true);
}
return url;
},
+2
View File
@@ -8,6 +8,7 @@ import {
isCursorInRange,
LinkWidget,
} from "./util.ts";
import { resolvePath } from "$sb/lib/resolve.ts";
/**
* Plugin to hide path prefix when the cursor is not inside.
@@ -33,6 +34,7 @@ export function cleanWikiLinkPlugin(editor: Client) {
if (page.includes("@")) {
cleanPage = page.split("@")[0];
}
cleanPage = resolvePath(editor.currentPage!, cleanPage);
// console.log("Resolved page", resolvedPage);
for (const pageMeta of allPages) {
if (pageMeta.name === cleanPage) {