Big refactors and fixes

* Query regen
* Fix anchor completion
* Dependency fixes
* Changelog update
This commit is contained in:
Zef Hemel
2023-07-02 11:25:32 +02:00
committed by GitHub
parent fee2c5928e
commit 7c825348b2
74 changed files with 935 additions and 567 deletions
+6 -5
View File
@@ -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 = `![](${encodeURIComponent(finalFileName)})`;
attachmentMarkdown = `![](${encodeURI(finalFileName)})`;
}
editor.editorView!.dispatch({
changes: [
+8 -10
View File
@@ -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),
);
+1 -1
View File
@@ -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}`;
}
+5 -2
View File
@@ -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",