Skip to content

Commit

Permalink
0.9.993
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-cen committed Jul 25, 2024
1 parent ce9460a commit b16e4c0
Show file tree
Hide file tree
Showing 69 changed files with 6,136 additions and 5,425 deletions.
9,686 changes: 4,989 additions & 4,697 deletions main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "make-md",
"name": "MAKE.md",
"version": "0.9.992",
"version": "0.9.993",
"minAppVersion": "0.16.0",
"description": "Make.md brings powerful and modern note-taking features to Obsidian. Capture, organize and connect information with more flexibility without any code.",
"author": "MAKE.md",
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/mdb/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export const saveDBToPath = async (
if (mdb) {
let mdbStruct : DBRows = []
try {
mdbStruct = dbResultsToDBTables(db.exec(`SELECT name FROM sqlite_master WHERE type='table' AND name='m_schema' OR name='m_fields';`))[0].rows
mdbStruct = dbResultsToDBTables(db.exec(`SELECT name FROM sqlite_master WHERE type='table' AND name='m_schema' OR name='m_fields';`))[0]?.rows ?? []
} catch (e) {
console.log(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/adapters/mdb/localCache/localCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { debounce } from "lodash";
import { CacheDBSchema } from "schemas/cache";
import { Database } from "sql.js";
import { DBRow, DBTables } from "types/mdb";
import { sanitizeSQLStatement } from "utils/sanitizers";
import { LocalCachePersister } from "../../../core/middleware/types/persister";

/** Simpler wrapper for a file-backed cache for arbitrary metadata. */
Expand Down Expand Up @@ -50,7 +51,7 @@ public reset() {
}
public async remove(path: string, type: string): Promise<void> {
if (!this.db) return;
await deleteFromDB(this.db, type, `path='${path}'`)
await deleteFromDB(this.db, type, `path='${sanitizeSQLStatement(path)}'`)
this.debounceSaveSpaceDatabase();
return;
}
Expand Down
32 changes: 31 additions & 1 deletion src/adapters/obsidian/filetypes/markdownAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { parseMultiDisplayString, parseProperty } from "utils/parsers";
import { getAbstractFileAtPath, tFileToAFile } from "../utils/file";
import { frontMatterForFile } from "./frontmatter/fm";
import { frontMatterKeys } from "./frontmatter/frontMatterKeys";
import _ from "lodash";
import { IndexMap } from "core/types/indexMap";

type CachedMetadataContentTypes = {
resolvedLinks: string;
inlinks: string;
links: string;
embeds: string;
tags: string[];
Expand All @@ -22,13 +25,14 @@ type CachedMetadataContentTypes = {
label: string;
}

type CleanCachedMetadata = Omit<CachedMetadata, 'tags'> & { tags: string[], resolvedLinks: string[], label: PathLabel }
type CleanCachedMetadata = Omit<CachedMetadata, 'tags'> & { tags: string[], resolvedLinks: string[], label: PathLabel, inlinks: string[] }

export class ObsidianMarkdownFiletypeAdapter implements FileTypeAdapter<CleanCachedMetadata, CachedMetadataContentTypes> {

public id = "metadata.obsidian.md"
public cache : Map<string, CleanCachedMetadata>;
public supportedFileTypes = ['md'];
private linksMap: IndexMap;
public middleware: FilesystemMiddleware;
public app: App;
public constructor (public plugin: MakeMDPlugin) {
Expand All @@ -38,9 +42,11 @@ public app: App;
public initiate (middleware: FilesystemMiddleware) {
this.middleware = middleware;
this.cache = new Map();
this.linksMap = new IndexMap();

}
public metadataChange (file: TFile) {

this.parseCache(tFileToAFile(file), true);

}
Expand All @@ -49,6 +55,14 @@ public app: App;
const fCache = this.app.metadataCache.getCache(file.path);
if (!fCache) return;
const rt = [];

let resolved = this.app.metadataCache.resolvedLinks;
let incoming = new Set<string>(this.linksMap.getInverse(file.path));
const currentCache = this.cache.get(file.path);
if (!currentCache)
{for (let [key, value] of Object.entries(resolved)) {
if (file.path in value) incoming.add(key);
}}
if (fCache && fCache.tags)
rt.push(...(fCache.tags?.map((f) => f.tag) ?? []));
if (fCache && fCache.frontmatter?.tags)
Expand All @@ -75,8 +89,10 @@ public app: App;
);
const contents = await this.plugin.app.vault.cachedRead(getAbstractFileAtPath(this.plugin.app, file.path)as TFile)
const links = fCache.links?.map(f => this.plugin.app.metadataCache.getFirstLinkpathDest(f.link, file.path)?.path).filter(f => f)
this.linksMap.set(file.path, new Set(links));
const updatedCache = {...fCache,
resolvedLinks: links ?? [],
inlinks: Array.from(incoming),
tags: rt,
property: fCache.frontmatter,
tasks: fCache.listItems?.filter(f => f.task).map(f => contents.slice(f.position.start.offset, f.position.end.offset)) ?? [],
Expand All @@ -87,6 +103,20 @@ public app: App;
color: fCache.frontmatter?.[this.plugin.superstate.settings.fmKeyColor],
preview: contents.slice(fCache.frontmatterPosition?.end.offset ?? 0, 1000)
}}

if (currentCache) {

if (!_.isEqual(currentCache.resolvedLinks, updatedCache.resolvedLinks)) {
const newLinks = updatedCache.resolvedLinks.filter(f => !currentCache.resolvedLinks.includes(f));
const removedLinks = currentCache.resolvedLinks.filter(f => !updatedCache.resolvedLinks.includes(f));
for (const link of [...newLinks, ...removedLinks]) {
const file = this.plugin.app.vault.getAbstractFileByPath(link);
if (file && file instanceof TFile)
this.metadataChange(file)
}

}
}
this.cache.set(file.path, updatedCache);
this.middleware.updateFileCache(file.path, updatedCache, refresh);
}
Expand Down
58 changes: 53 additions & 5 deletions src/adapters/obsidian/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab {
this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName(t.settings.folderNoteName.name)
.setDesc(t.settings.folderNoteName.desc)
.addText((text) => {
text
.setValue(this.plugin.superstate.settings.folderNoteName)
.setPlaceholder("Folder Name")
.onChange(async (value) => {
this.plugin.superstate.settings.folderNoteName = value;
await this.plugin.saveSettings();
});
});



Expand Down Expand Up @@ -117,6 +130,17 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab {
})
);

// new Setting(spaceAppearances)
// .setName(t.settings.flowState.name)
// .setDesc(t.settings.flowState.desc)
// .addToggle((toggle) =>
// toggle.setValue(this.plugin.superstate.settings.flowState).onChange((value) => {
// this.plugin.superstate.settings.flowState = value;
// this.plugin.saveSettings();
// document.body.classList.toggle("mk-flow-state", !value);
// })
// );



new Setting(spaceAppearances)
Expand Down Expand Up @@ -167,13 +191,15 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab {
new Setting(spaceAppearances)
.setName(t.settings.spaceRowHeight.name)
.setDesc(t.settings.spaceRowHeight.desc)
.addText((text) => {
.addSlider((text) => {
text
.setValue(this.plugin.superstate.settings.spaceRowHeight.toString())
.setValue(this.plugin.superstate.settings.spaceRowHeight)
.setDynamicTooltip()
.setLimits(20, 40, 1)
.onChange(async (value) => {
text.setValue(parseInt(value).toString());
this.plugin.superstate.settings.spaceRowHeight = parseInt(value);
await this.plugin.saveSettings();

this.plugin.superstate.settings.spaceRowHeight = value;
this.plugin.saveSettings();
});
});

Expand Down Expand Up @@ -354,6 +380,17 @@ containerEl.createEl("h3", { text: t.settings.sectionStickers });
})
);
new Setting(containerEl)
.setName(t.settings.contextPagination.name)
.setDesc(t.settings.contextPagination.desc)
.addText((text) => {
text
.setValue(this.plugin.superstate.settings.contextPagination.toString())
.onChange(async (value) => {
this.plugin.superstate.settings.contextPagination = parseInt(value);
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName(t.settings.defaultDateFormat.name)
.setDesc(t.settings.defaultDateFormat.desc)
.addText((text) => {
Expand Down Expand Up @@ -683,6 +720,17 @@ containerEl.createEl("h3", { text: t.settings.sectionStickers });
);
}
new Setting(containerEl)
.setName("Perform Search in Background")
.setDesc("Perform search in background to prevent lag")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.superstate.settings.searchWorker)
.onChange((value) => {
this.plugin.superstate.settings.searchWorker = value;
this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName(t.settings.experimental.name)
.setDesc(t.settings.experimental.desc)
.addToggle((toggle) =>
Expand Down
6 changes: 6 additions & 0 deletions src/adapters/obsidian/types/obsidian.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { EditorView } from "@codemirror/view";
import { FlowEditorParent } from "adapters/obsidian/ui/editors/FlowEditor";

declare module "obsidian" {
export enum PopoverState {
Shown,
Hiding,
Hidden,
Showing
}
interface Vault {
getConfig(config: string): any
}
Expand Down
33 changes: 11 additions & 22 deletions src/adapters/obsidian/ui/editors/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import MakeMDPlugin from "main";
import {
App,
Component,
EphemeralState,
HoverPopover,
Expand Down Expand Up @@ -100,7 +101,7 @@ export class FlowEditor extends nosuper(HoverPopover) {
return windows;
}

static containerForDocument(doc: Document) {
static containerForDocument(app: App, doc: Document) {
if (doc !== document && app.workspace.floatingSplit)
for (const container of app.workspace.floatingSplit.children) {
if (container.doc === doc) return container;
Expand Down Expand Up @@ -216,7 +217,7 @@ export class FlowEditor extends nosuper(HoverPopover) {
this.document === document ? "rootSplit" : "floatingSplit"
]!;
this.rootSplit.getContainer = () =>
FlowEditor.containerForDocument(this.document);
FlowEditor.containerForDocument(this.plugin.app, this.document);

this.titleEl.insertAdjacentElement("afterend", this.rootSplit.containerEl);
const leaf = this.plugin.app.workspace.createLeafInParent(
Expand Down Expand Up @@ -277,7 +278,6 @@ export class FlowEditor extends nosuper(HoverPopover) {
this.parent.flowEditor = this;
this.parent.view.addChild(this);
}

await this.onShowCallback?.(this);
this.onShowCallback = undefined; // only call it once
const viewHeaderEl = this.hoverEl.querySelector(".view-header");
Expand All @@ -290,20 +290,15 @@ export class FlowEditor extends nosuper(HoverPopover) {

transition() {
if (this.shouldShow()) {
//@ts-ignore
if (this.state === PopoverState.Hiding) {
//@ts-ignore
this.state = PopoverState.Shown;
clearTimeout(this.timer);
}
} else {
//@ts-ignore
if (this.state === PopoverState.Showing) {
this.hide();
} else {
//@ts-ignore
if (this.state === PopoverState.Shown) {
//@ts-ignore
this.state = PopoverState.Hiding;
this.timer = window.setTimeout(() => {
if (this.shouldShow()) {
Expand Down Expand Up @@ -340,7 +335,6 @@ export class FlowEditor extends nosuper(HoverPopover) {
!this.detaching &&
!!(
this.onTarget ||
//@ts-ignore
this.state == PopoverState.Shown ||
this.document.querySelector(
`body>.modal-container, body > #he${this.id} ~ .menu, body > #he${this.id} ~ .suggestion-container`
Expand All @@ -350,18 +344,13 @@ export class FlowEditor extends nosuper(HoverPopover) {
}

show() {
if (!this.targetEl || this.document.body.contains(this.targetEl)) {
//@ts-ignore
this.state = PopoverState.Shown;
this.timer = 0;
this.shownPos = mouseCoords;
this.targetEl.replaceChildren(this.hoverEl);
this.onShow();
app.workspace.onLayoutChange();
this.load();
} else {
this.hide();
}
this.state = PopoverState.Shown;
this.timer = 0;
this.shownPos = mouseCoords;
this.targetEl.replaceChildren(this.hoverEl);
this.onShow();
app.workspace.onLayoutChange();
this.load();
}

onHide() {
Expand Down Expand Up @@ -414,7 +403,7 @@ export class FlowEditor extends nosuper(HoverPopover) {

nativeHide() {
const { hoverEl, targetEl } = this;
//@ts-ignore

this.state = PopoverState.Hidden;

hoverEl.detach();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import MakeMDPlugin from "main";
import { i18n } from "makemd-core";

import { FlowEditorHover } from "adapters/obsidian/ui/editors/markdownView/FlowEditorHover";
import { loadFlowEditorByDOM } from "adapters/obsidian/utils/flow/flowEditor";
import { PathStickerContainer } from "core/react/components/UI/Stickers/PathSticker/PathSticker";
import { CollapseToggle } from "core/react/components/UI/Toggles/CollapseToggle";
import { compareByField } from "core/utils/tree";
Expand Down Expand Up @@ -364,7 +363,10 @@ export const flowEditorField = (plugin: MakeMDPlugin) =>
});

class FlowEditorWidget extends WidgetType {
constructor(readonly info: FlowEditorInfo, public plugin: MakeMDPlugin) {
constructor(
private readonly info: FlowEditorInfo,
public plugin: MakeMDPlugin
) {
super();
}

Expand All @@ -379,7 +381,16 @@ class FlowEditorWidget extends WidgetType {
div.setAttribute("id", "mk-flow-" + this.info.id);
const placeholder = div.createDiv("mk-floweditor-placeholder");
placeholder.style.setProperty("height", this.info.height + "px");
loadFlowEditorByDOM(this.plugin, div, view, this.info.id);
if (this.info.link && view.state.field(editorInfoField, false)) {
const infoField = view.state.field(editorInfoField, false);
const file = infoField.file;
const uri = this.plugin.superstate.spaceManager.uriByString(
this.info.link,
file?.path
);
this.plugin.superstate.ui.openPath(uri.fullPath, false, div);
}
// loadFlowEditorByDOM(this.plugin, div, view, this.info.id);
return div;
}
get estimatedHeight(): number {
Expand Down Expand Up @@ -409,7 +420,7 @@ class LinkSticker extends WidgetType {
const file = infoField.file;
const uri = this.plugin.superstate.spaceManager.uriByString(
this.info.link,
file.path
file?.path
);
reactEl.render(
<PathStickerContainer
Expand Down
Loading

0 comments on commit b16e4c0

Please sign in to comment.