Big refactors and fixes
* Query regen * Fix anchor completion * Dependency fixes * Changelog update
This commit is contained in:
@@ -180,12 +180,13 @@ export function attachmentExtension(editor: Editor) {
|
||||
if (!finalFileName) {
|
||||
return;
|
||||
}
|
||||
await editor.space.writeAttachment(finalFileName, new Uint8Array(data));
|
||||
let attachmentMarkdown = `[${finalFileName}](${
|
||||
encodeURIComponent(finalFileName)
|
||||
})`;
|
||||
await editor.space.writeAttachment(
|
||||
finalFileName,
|
||||
new Uint8Array(data),
|
||||
);
|
||||
let attachmentMarkdown = `[${finalFileName}](${encodeURI(finalFileName)})`;
|
||||
if (mimeType.startsWith("image/")) {
|
||||
attachmentMarkdown = `})`;
|
||||
attachmentMarkdown = `})`;
|
||||
}
|
||||
editor.editorView!.dispatch({
|
||||
changes: [
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import { decoratorStateField } from "./util.ts";
|
||||
|
||||
import type { Space } from "../space.ts";
|
||||
import type { Editor } from "../editor.tsx";
|
||||
|
||||
class InlineImageWidget extends WidgetType {
|
||||
constructor(
|
||||
@@ -39,13 +40,7 @@ class InlineImageWidget extends WidgetType {
|
||||
this.space.setCachedImageHeight(this.url, img.height);
|
||||
}
|
||||
};
|
||||
if (this.url.startsWith("http")) {
|
||||
img.src = this.url;
|
||||
} else {
|
||||
// This is an attachment image, rewrite the URL a little
|
||||
img.src = `/.fs/${decodeURIComponent(this.url)}`;
|
||||
}
|
||||
|
||||
img.src = this.url;
|
||||
img.alt = this.title;
|
||||
img.title = this.title;
|
||||
img.style.display = "block";
|
||||
@@ -58,7 +53,7 @@ class InlineImageWidget extends WidgetType {
|
||||
}
|
||||
}
|
||||
|
||||
export function inlineImagesPlugin(space: Space) {
|
||||
export function inlineImagesPlugin(editor: Editor) {
|
||||
return decoratorStateField((state: EditorState) => {
|
||||
const widgets: Range<Decoration>[] = [];
|
||||
const imageRegex = /!\[(?<title>[^\]]*)\]\((?<url>.+)\)/;
|
||||
@@ -76,11 +71,14 @@ export function inlineImagesPlugin(space: Space) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = imageRexexResult.groups.url;
|
||||
let url = imageRexexResult.groups.url;
|
||||
const title = imageRexexResult.groups.title;
|
||||
if (url.indexOf("://") === -1) {
|
||||
url = `/.fs/${url}`;
|
||||
}
|
||||
widgets.push(
|
||||
Decoration.widget({
|
||||
widget: new InlineImageWidget(url, title, space),
|
||||
widget: new InlineImageWidget(url, title, editor.space),
|
||||
block: true,
|
||||
}).range(node.to),
|
||||
);
|
||||
|
||||
@@ -37,7 +37,7 @@ class TableViewWidget extends WidgetType {
|
||||
// Annotate every element with its position so we can use it to put
|
||||
// the cursor there when the user clicks on the table.
|
||||
annotationPositions: true,
|
||||
inlineAttachments: (url) => {
|
||||
translateUrls: (url) => {
|
||||
if (!url.includes("://")) {
|
||||
return `/.fs/${url}`;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export function cleanWikiLinkPlugin(editor: Editor) {
|
||||
if (page.includes("@")) {
|
||||
cleanPage = page.split("@")[0];
|
||||
}
|
||||
// console.log("Resolved page", resolvedPage);
|
||||
for (const pageMeta of allPages) {
|
||||
if (pageMeta.name === cleanPage) {
|
||||
pageExists = true;
|
||||
@@ -76,8 +77,10 @@ export function cleanWikiLinkPlugin(editor: Editor) {
|
||||
widget: new LinkWidget(
|
||||
{
|
||||
text: linkText,
|
||||
title: pageExists ? `Navigate to ${page}` : `Create ${page}`,
|
||||
href: `/${page}`,
|
||||
title: pageExists
|
||||
? `Navigate to ${cleanPage}`
|
||||
: `Create ${cleanPage}`,
|
||||
href: `/${cleanPage}`,
|
||||
cssClass: pageExists
|
||||
? "sb-wiki-link-page"
|
||||
: "sb-wiki-link-page-missing",
|
||||
|
||||
Reference in New Issue
Block a user