Skip to content

Commit

Permalink
0.9.1001
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-cen committed Aug 10, 2024
1 parent 36dd834 commit 58eabe2
Show file tree
Hide file tree
Showing 45 changed files with 803 additions and 430 deletions.
236 changes: 118 additions & 118 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.1000",
"version": "0.9.1001",
"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
10 changes: 9 additions & 1 deletion src/adapters/obsidian/SpaceViewContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import classNames from "classnames";
import { SystemSettings } from "core/react/components/System/SystemSettings";
import { SpaceView, Superstate } from "makemd-core";
import { ItemView, ViewStateResult, WorkspaceLeaf } from "obsidian";
Expand Down Expand Up @@ -153,7 +154,14 @@ export class SpaceViewContainer extends ItemView {
key={path}
readOnly={false}
>
<div className="mk-space-scroller markdown-source-view mod-cm6 is-readable-line-width">
<div
className={classNames(
"mk-space-scroller markdown-source-view mod-cm6",
this.superstate.settings.readableLineWidth
? "is-readable-line-width"
: ""
)}
>
<SpaceInner
superstate={this.superstate}
header={true}
Expand Down
19 changes: 13 additions & 6 deletions src/adapters/obsidian/filesystem/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MobileCachePersister } from "adapters/mdb/localCache/localCacheMobile";
import { DEFAULT_SETTINGS } from "core/schemas/settings";
import { defaultFocusFile } from "core/spaceManager/filesystemAdapter/filesystemAdapter";
import { parsePathState } from "core/utils/superstate/parser";
import { parseURI } from "core/utils/uri";
import { DBRows, DBTables } from "types/mdb";
import { uniqueNameFromString } from "utils/array";
import { getParentPathFromString, pathToString, removeTrailingSlashFromFolder } from "utils/path";
Expand Down Expand Up @@ -145,8 +146,8 @@ export class ObsidianFileSystem implements FileSystemAdapter {
this.vaultDBCache.forEach(f => {
const file = tFileToAFile(getAbstractFileAtPath(this.plugin.app, f.path))
if (file?.path == '/') {
file.name = this.plugin.app.vault.getName()
f.name = this.plugin.app.vault.getName()
file.name = "Vault"
f.name = "Vault"
}
this.checkIllegalCharacters(file);

Expand Down Expand Up @@ -239,11 +240,17 @@ export class ObsidianFileSystem implements FileSystemAdapter {
}
public resolvePath (path: string, source: string) {
if (!source || !path) return path;

if (path.includes("#")) {
const [basePath, fragment] = path.split('#');
return this.plugin.app.metadataCache.getFirstLinkpathDest(basePath, source)?.path+'#'+fragment ?? path
const uri = parseURI(path);
if (uri.refStr?.length > 0)
{
if (uri.refType == 'block' || uri.refType == 'heading') {
const resolvedPath = this.plugin.app.metadataCache.getFirstLinkpathDest(uri.basePath, source)?.path;
if (resolvedPath)
return resolvedPath + "#" + uri.refStr
}
return path;
}

return this.plugin.app.metadataCache.getFirstLinkpathDest(path, source)?.path ?? path
}

Expand Down
54 changes: 44 additions & 10 deletions src/adapters/obsidian/filetypes/jsonAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

import { AFile, FileTypeAdapter, FilesystemMiddleware } from "makemd-core";

import { omit } from "lodash";
import MakeMDPlugin from "main";
import { parseProperty, safelyParseJSON } from "utils/parsers";

type CachedMetadataContentTypes = {
property: any;
label: string;
definition: any;
}

export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>, CachedMetadataContentTypes> {
Expand All @@ -23,9 +25,13 @@ export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>,
public middleware: FilesystemMiddleware;
public async parseCache (file: AFile, refresh?: boolean) {
if (!file) return;
const label = this.middleware.getFileCache(file.path)?.label
// const contents = safelyParseJSON(await this.plugin.app.vault.cachedRead(getAbstractFileAtPath(this.plugin.app, file.path)as TFile))
const cache = safelyParseJSON(await this.middleware.readTextFromFile(file.path)) ?? {};
const label = cache.label ?? {}
const property = cache.property ?? {}
const definition = omit(cache, ['label', 'property']);
const updatedCache = {
property: property,
definition: definition,
label: {
name: file.name,
sticker: label?.sticker?.length > 0 ? label.sticker : "ui//json",
Expand All @@ -34,13 +40,21 @@ export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>,
thumbnail: ''
}}

// const contents = safelyParseJSON(await this.plugin.app.vault.cachedRead(getAbstractFileAtPath(this.plugin.app, file.path)as TFile))
if (file.parent.split('/').pop() == this.plugin.superstate.settings.spaceSubFolder && file.path.split('/').pop() == 'def.json') {
const spaceFolder = await this.middleware.getFile(file.parent)
const name = spaceFolder.parent == '/' ? this.plugin.superstate.settings.systemName : spaceFolder.parent.split('/').pop();
const label = await this.readContent(file, 'label', null);
updatedCache.label = {...label, name: name}
}


this.cache.set(file.path, updatedCache);
this.middleware.updateFileCache(file.path, updatedCache, refresh);
}
public cache: Map<string, Record<string, any>>;
public cacheTypes: (file: AFile) => string[];
public contentTypes (file: AFile) { return ["property", 'label'] as Array<keyof CachedMetadataContentTypes>;}
public contentTypes (file: AFile) { return ["property", 'label', 'definition'] as Array<keyof CachedMetadataContentTypes>;}
public async newFile (parent: string, name: string, type: string, content: string) {
const newPath = parent == '/' ? name+".json" : `${parent}/${name}.json`;

Expand All @@ -53,16 +67,20 @@ export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>,
public getCacheTypeByRefString: (file: AFile, refString: string) => any;
public getCache: (file: AFile, fragmentType: string, query?: string) => never;
public async readContent (file: AFile, fragmentType: string, fragmentId: any) {
if (fragmentType == 'definition') {
const cache = await this.middleware.readTextFromFile(file.path);
return omit(safelyParseJSON(cache) ?? {}, ['label', 'property']);
}
if (fragmentType == 'property') {
const cache = await this.middleware.readTextFromFile(file.path);
return safelyParseJSON(cache) ?? {};
return safelyParseJSON(cache)?.property ?? {};
}
if (fragmentType == 'label') {
const cache = await this.middleware.readTextFromFile(file.path);
const fm = safelyParseJSON(cache) ?? {};
const fm = safelyParseJSON(cache).label ?? {};
const sticker = parseProperty("sticker", fm[this.plugin.superstate.settings.fmKeySticker])
const color = parseProperty("color", fm[this.plugin.superstate.settings.fmKeyColor])
const name = parseProperty("color", fm[this.plugin.superstate.settings.fmKeyAlias])[0]
const name = parseProperty("aliases", fm[this.plugin.superstate.settings.fmKeyAlias])[0]
const rows : Record<string, any> = {};
if (sticker?.length > 0) {
rows['sticker'] = sticker;
Expand All @@ -80,7 +98,7 @@ export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>,
public newContent: (file: AFile, fragmentType: string, name: string, content: never, options: { [key: string]: any; }) => Promise<any>;
public async saveContent (file: AFile, fragmentType: string, fragmentId: any, content: (prev: any) => any) {
if (fragmentType == 'label') {
const currentProperties = await this.readContent(file, fragmentType, fragmentId);
const currentProperties = await this.readContent(file, "label", fragmentId);

if (fragmentId == 'sticker') {
currentProperties[this.plugin.superstate.settings.fmKeySticker] = content(currentProperties);
Expand All @@ -89,13 +107,27 @@ export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>,
} else if (fragmentId == 'name') {
currentProperties[this.plugin.superstate.settings.fmKeyAlias] = [content(currentProperties)];
}

const currentJSON = safelyParseJSON(await this.middleware.readTextFromFile(file.path)) ?? {};

await this.middleware.writeTextToFile(file.path, JSON.stringify({...currentJSON, label: currentProperties}));
this.parseCache(file, true);

}
if (fragmentType == 'definition') {
const currentProperties = await this.readContent(file, fragmentType, fragmentId);

const newProperties = content(currentProperties);
const currentJSON = safelyParseJSON(await this.middleware.readTextFromFile(file.path)) ?? {};
await this.middleware.writeTextToFile(file.path, JSON.stringify({...currentJSON, ...newProperties}));
this.parseCache(file, true);
}
if (fragmentType == 'property') {
const currentProperties = await this.readContent(file, fragmentType, fragmentId);

const newProperties = content(currentProperties);
await this.middleware.writeTextToFile(file.path, JSON.stringify(newProperties));
const currentJSON = safelyParseJSON(await this.middleware.readTextFromFile(file.path))?.property ?? {};
await this.middleware.writeTextToFile(file.path, JSON.stringify({...currentJSON, property: newProperties}));
this.parseCache(file, true);
}
return true;
}
Expand All @@ -104,7 +136,9 @@ export class JSONFiletypeAdapter implements FileTypeAdapter<Record<string, any>,
if (fragmentType == 'property') {
const currentProperties = await this.readContent(file, fragmentType, fragmentId);
delete currentProperties[fragmentId];
await this.middleware.writeTextToFile(file.path, JSON.stringify(currentProperties));
const currentJSON = safelyParseJSON(await this.middleware.readTextFromFile(file.path)) ?? {};
await this.middleware.writeTextToFile(file.path, JSON.stringify({...currentJSON, property: currentProperties}));
this.parseCache(file, true);
}
}

Expand Down
155 changes: 151 additions & 4 deletions src/adapters/obsidian/replaceMobileMainMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { SidebarProvider } from "core/react/context/SidebarContext";
import classNames from "classnames";
import { ScreenType, Warning } from "core/middleware/ui";
import { defaultAddAction } from "core/react/components/UI/Menus/navigator/showSpaceAddMenu";
import {
NavigatorContext,
SidebarProvider,
} from "core/react/context/SidebarContext";
import { isTouchScreen } from "core/utils/ui/screen";
import MakeMDPlugin from "main";
import React from "react";
import { MainMenu } from "../../core/react/components/Navigator/MainMenu";
import { i18n, Superstate } from "makemd-core";
import React, { useContext, useEffect, useRef } from "react";
import { windowFromDocument } from "utils/dom";

export const replaceMobileMainMenu = (plugin: MakeMDPlugin) => {
if (isTouchScreen(plugin.superstate.ui)) {
Expand All @@ -13,8 +20,148 @@ export const replaceMobileMainMenu = (plugin: MakeMDPlugin) => {
const reactEl = plugin.superstate.ui.createRoot(header);
reactEl.render(
<SidebarProvider superstate={plugin.superstate}>
<MainMenu superstate={plugin.superstate}></MainMenu>
<ObsidianMobileMainMenu
superstate={plugin.superstate}
plugin={plugin}
></ObsidianMobileMainMenu>
</SidebarProvider>
);
}
};

export const ObsidianMobileMainMenu = (props: {
plugin: MakeMDPlugin;
superstate: Superstate;
}) => {
const { superstate } = props;
const { setActivePath, setDragPaths } = useContext(NavigatorContext);

const ref = useRef<HTMLDivElement>();
const [warnings, setWarnings] = React.useState<Warning[]>([]);
useEffect(() => {
setTimeout(() => {
props.superstate.ui
.getWarnings()
.filter(
(f) =>
!props.superstate.settings.suppressedWarnings.some((g) => f.id == g)
);
}, 1000);
}, []);

const settingsChanged = () => {
setWarnings(
props.superstate.ui
.getWarnings()
.filter(
(f) =>
!props.superstate.settings.suppressedWarnings.some((g) => f.id == g)
)
);
};
useEffect(() => {
props.superstate.eventsDispatcher.addListener(
"superstateUpdated",
settingsChanged
);
props.superstate.eventsDispatcher.addListener(
"settingsChanged",
settingsChanged
);
props.superstate.eventsDispatcher.addListener(
"warningsChanged",
settingsChanged
);
return () => {
props.superstate.eventsDispatcher.removeListener(
"superstateUpdated",
settingsChanged
);
props.superstate.eventsDispatcher.removeListener(
"settingsChanged",
settingsChanged
);
props.superstate.eventsDispatcher.removeListener(
"warningsChanged",
settingsChanged
);
};
}, []);
return (
<div className="mk-main-menu-container">
<div className="mk-main-menu-inner">
<div className={classNames("mk-main-menu")}>
<div
className={`mk-main-menu-button mk-main-menu-button-primary`}
ref={ref}
onClick={(e) => {
props.superstate.ui.mainMenu(ref.current, superstate);
}}
>
{props.superstate.settings.systemName}
{warnings.length > 0 && (
<div
className="mk-icon-xsmall"
dangerouslySetInnerHTML={{
__html: props.superstate.ui.getSticker("ui//warning"),
}}
></div>
)}
<div
className="mk-icon-xsmall"
dangerouslySetInnerHTML={{
__html: props.superstate.ui.getSticker("ui//chevrons-up-down"),
}}
></div>
</div>

<div
className="mk-main-menu-button"
onClick={(e) => props.superstate.ui.quickOpen(superstate)}
>
<div
className="mk-icon-small"
dangerouslySetInnerHTML={{
__html: props.superstate.ui.getSticker("ui//search"),
}}
></div>
</div>
</div>

<button
aria-label={i18n.buttons.newNote}
className="mk-main-menu-button"
onClick={(e) =>
defaultAddAction(
superstate,
null,
windowFromDocument(e.view.document),
e.metaKey ? "tab" : false
)
}
>
<div
className="mk-icon-small"
dangerouslySetInnerHTML={{
__html: props.superstate.ui.getSticker("ui//new-note"),
}}
></div>
</button>
{props.superstate.ui.getScreenType() == ScreenType.Tablet && (
<div
aria-label={i18n.buttons.newNote}
className="mk-main-menu-button"
onClick={(e) => props.plugin.app.workspace.leftSplit.togglePinned()}
>
<div
className="mk-icon-small"
dangerouslySetInnerHTML={{
__html: props.superstate.ui.getSticker("ui//pin"),
}}
></div>
</div>
)}
</div>
</div>
);
};
Loading

0 comments on commit 58eabe2

Please sign in to comment.