Skip to content

Commit

Permalink
0.9.1005
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-cen committed Aug 17, 2024
1 parent fa6cf91 commit 103d465
Show file tree
Hide file tree
Showing 25 changed files with 203 additions and 185 deletions.
174 changes: 87 additions & 87 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.1004",
"version": "0.9.1005",
"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
1 change: 0 additions & 1 deletion src/adapters/mdb/utils/mdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export const getMDBTableProperties = async (
fieldsTables = dbResultsToDBTables(db.exec(`SELECT * FROM m_fields`))[0].rows as SpaceProperty[];

} catch (e) {
adapter.plugin.superstate.ui.error(e);
db.close();
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/obsidian/filetypes/markdownAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public app: App;
this.cache.set(file.path, updatedCache);
this.middleware.updateFileCache(file.path, updatedCache, refresh);
}
private metadataKeys = ['property', 'links', 'embeds', 'tags', 'headings', 'sections', 'listItems', 'frontmatter', 'frontmatterPostion', 'frontmatterLinks', 'blocks'] as Array<keyof CachedMetadata>;
private metadataKeys = ['property', 'links', 'embeds', 'tags', 'headings', 'sections', 'listItems', 'frontmatter', 'frontmatterPosition', 'frontmatterLinks', 'blocks'] as Array<keyof CachedMetadata>;
public cacheTypes (file: AFile) : (keyof CleanCachedMetadata)[] {
return this.metadataKeys;
}
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/obsidian/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,20 +576,19 @@ containerEl.createEl("h3", { text: t.settings.sectionStickers });
.setName(t.settings.editorFlowStyle.name)
.setDesc(t.settings.editorFlowStyle.desc)
.addDropdown((dropdown: DropdownComponent) => {
dropdown.addOption("classic", t.settings.editorFlowStyle.classic);
dropdown.addOption("seamless", t.settings.editorFlowStyle.seamless);
dropdown.addOption("minimal", t.settings.editorFlowStyle.minimal);
dropdown
.setValue(this.plugin.superstate.settings.editorFlowStyle)
.onChange(async (value) => {
this.plugin.superstate.settings.editorFlowStyle = value;
document.body.classList.toggle("mk-flow-classic", false);
document.body.classList.toggle("mk-flow-seamless", false);
document.body.classList.toggle("mk-flow-minimal", false);
document.body.classList.toggle("mk-flow-seamless", false);

if (value == "seamless")
document.body.classList.toggle("mk-flow-seamless", true);
if (value == "classic")
document.body.classList.toggle("mk-flow-classic", true);
document.body.classList.toggle("mk-flow-minimal", true);
if (value == "minimal")
document.body.classList.toggle("mk-flow-minimal", true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React from "react";
import { flowTypeStateField } from "./flowStateFields";

import MakeMDPlugin from "main";
import { i18n } from "makemd-core";
import { i18n, NoteView } from "makemd-core";

import { FlowEditorHover } from "adapters/obsidian/ui/editors/markdownView/FlowEditorHover";
import { PathStickerContainer } from "core/react/components/UI/Stickers/PathSticker/PathSticker";
Expand Down Expand Up @@ -379,17 +379,22 @@ class FlowEditorWidget extends WidgetType {
div.classList.add("mk-floweditor-container");

div.setAttribute("id", "mk-flow-" + this.info.id);
const placeholder = div.createDiv("mk-floweditor-placeholder");
placeholder.style.setProperty("height", this.info.height + "px");
div.style.setProperty("height", this.info.height + "px");
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.resolvePath(
this.info.link,
file?.path
);

this.plugin.superstate.ui.openPath(uri, false, div);
this.plugin.superstate.ui
.createRoot(div)
.render(
<NoteView
load={true}
superstate={this.plugin.superstate}
path={this.info.link}
source={file.path}
></NoteView>
);
// this.plugin.superstate.ui.openPath(uri, false, div);
}
// loadFlowEditorByDOM(this.plugin, div, view, this.info.id);
return div;
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/obsidian/ui/editors/markdownView/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ class HoverPlugin {
this.checkHover = this.checkHover.bind(this);
view.dom.addEventListener(
"mouseleave",
(this.mouseleave = this.mouseleave.bind(this))
(this.mouseleave)
);
view.dom.addEventListener(
"mousemove",
(this.mousemove = this.mousemove.bind(this))
(this.mousemove)
);
}

Expand Down
5 changes: 1 addition & 4 deletions src/adapters/obsidian/utils/flow/flowEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ export const getLineRangeFromRef = (
(f, i) => i > index && f.level <= level
);

const start =
plugin.superstate.settings.editorFlowStyle == "classic"
? heading.position.start.line + 1
: heading.position.start.line + 2;
const start = heading.position.start.line + 2;
if (index < headings.length - 1 && nextIndex != -1) {
return [start, headings[nextIndex].position.end.line];
}
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/obsidian/utils/flow/markdownPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ export const replaceAllTables = (
/(?:!\[!\[|!!\[\[)([^\]]+)\]\]/g
)) {
const link = match[1];
element.style.display = "none";
const reactEl = plugin.ui.createRoot(element.parentElement);
// const flowType = cm.state.field(flowTypeStateField, false);
reactEl.render(
<NoteView
load={true}
superstate={plugin.superstate}
path={link}
source={ctx.sourcePath}
></NoteView>
);
}
Expand Down
1 change: 0 additions & 1 deletion src/core/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ class T {
name: "Flow Block Style",
desc: "Select a theme for your flow block",
seamless: "Seamless",
classic: "Classic",
minimal: "Minimal",
},
},
Expand Down
9 changes: 9 additions & 0 deletions src/core/middleware/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SelectMenuProps } from "core/react/components/UI/Menus/menu/SelectionMe
import { showSelectMenu } from "core/react/components/UI/Menus/selectMenu";
import { Superstate } from "core/superstate/superstate";
import { MenuObject } from "core/utils/ui/menu";
import _ from "lodash";
import { Root, RootOptions } from "react-dom/client";
import { TargetLocation } from "types/path";
import { Anchors, Pos, Rect } from "../../types/Pos";
Expand All @@ -12,6 +13,7 @@ import { InputManager } from "./inputManager";

export type UIManagerEventTypes = {
'activePathChanged': string;
'activeStateChanged': null;
'activeSelectionChanged': {path: string, content: string};
'windowReady': null;
}
Expand Down Expand Up @@ -88,8 +90,15 @@ export class UIManager {
return this.mainFrame.availableViews();
}

public activeState: Record<string, any> = {};
public setActiveState (state: Record<string, any>) {
if (_.isEqual(state, this.activeState)) return;
this.activeState = state;
this.eventsDispatch.dispatchEvent('activeStateChanged', null);
}
public activePath: string;
public setActivePath (path: string) {

this.activePath = path;
this.eventsDispatch.dispatchEvent('activePathChanged', path);
}
Expand Down
1 change: 1 addition & 0 deletions src/core/react/components/Explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export const ExplorerFlowRow = (props: {
load={true}
superstate={props.superstate}
path={path}
forceNote={true}
properties={{
from: block[0]?.line,
to: block[1] ? block[1].line + 1 : null,
Expand Down
1 change: 1 addition & 0 deletions src/core/react/components/MarkdownEditor/Backlinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const BacklinkItem = (props: {
<div className="mk-path-context-backlink">
<NoteView
load={true}
forceNote={true}
superstate={props.superstate}
path={props.path}
properties={{ from: block[0], to: block[1] }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export const SpaceTreeComponent = (props: SpaceTreeComponentProps) => {
if (!path || parentSpaces.length == 0) return;

let newOpenFolders = expandedSpaces;

parentSpaces.forEach((space) => {
const folders = path.split("/");
const pathLevel = space.path
Expand All @@ -379,12 +380,15 @@ export const SpaceTreeComponent = (props: SpaceTreeComponentProps) => {
: [
index == 0
? "//" + c
: p[index] + "/" + folders.slice(0, index + 1).join("/"),
: space.path +
"/" +
folders.slice(0, index + 1).join("/"),
]),
],
[space.path]
)
.slice(0, -1);

newOpenFolders = [
...(newOpenFolders.filter((f) => !openPaths.find((g) => g == f)) ??
[]),
Expand Down
37 changes: 31 additions & 6 deletions src/core/react/components/PathView/NoteView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface NoteViewProps {
load: boolean;
properties?: Record<string, any>;
classname?: string;
forceNote?: boolean;
}

export const NoteView = forwardRef((props: NoteViewProps, ref) => {
Expand All @@ -25,11 +26,13 @@ export const NoteView = forwardRef((props: NoteViewProps, ref) => {
);

const properties: Record<string, any> = props.properties;
const pathState = props.superstate.pathsIndex.get(path.fullPath);
const pathState = props.superstate.pathsIndex.get(path.basePath);
const filePath =
pathState?.type == "space"
pathState?.type == "space" && props.forceNote
? props.superstate.spacesIndex.get(props.path)?.space.notePath
: pathState?.path;
: pathState
? path.fullPath
: null;

if (!filePath) {
if (!force) {
Expand Down Expand Up @@ -77,9 +80,31 @@ export const NoteView = forwardRef((props: NoteViewProps, ref) => {
useEffect(() => {
toggleFlow();
}, [props.load, props.path]);
// useEffect(() => {
// toggleFlow();
// }, []);

useEffect(() => {
const reloadFlow = () => {
if (
flowRef.current &&
!flowRef.current.hasChildNodes() &&
props.load &&
!existsPas
) {
loadPath();
}
};
props.superstate.ui.eventsDispatch.addListener(
"activeStateChanged",
reloadFlow
);

return () => {
props.superstate.ui.eventsDispatch.removeListener(
"activeStateChanged",
reloadFlow
);
};
}, []);

return (
<>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function parseContent(input: string): string {
}

function addSlashBeforeHash(input: string): string {
return input.replace(/([^/])#([*^])/g, "$1/#$2");
return input?.replace(/([^/])#([*^])/g, "$1/#$2");
}
export const ContextNodeView = (
props: FrameNodeViewProps & {
Expand Down
2 changes: 1 addition & 1 deletion src/core/schemas/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const DEFAULT_SETTINGS: MakeMDSettings = {
contextEnabled: true,
spaceViewEnabled: true,
saveAllContextToFrontmatter: true,
editorFlowStyle: "seamless",
editorFlowStyle: "minimal",
autoOpenFileContext: false,
activeView: "/",
hideFrontmatter: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class FilesystemSpaceAdapter implements SpaceAdapter {
return this.spaceManager.uriByString(path);
}
public allPaths (type?: string[]) {

return [...this.fileSystem.allFiles().filter(f => type ? type.some(g => g == 'folder' ? f.isFolder : f.extension == g) : true).map(g => g.path).filter(f => !excludeSpacesPredicate(this.spaceManager.superstate.settings, f))];
}
public async pathExists (path: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/spaceManager/spaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class SpaceManager {
}
//basic item operations
public allPaths (type?: string[]) {
return this.primarySpaceAdapter.allPaths(type);
return this.spaceAdapters.flatMap(f => f.allPaths(type));
}
public createItemAtPath (parent: string, type: string, name: string, content?: any) :Promise<string> {
return this.adapterForPath(parent).createItemAtPath(parent, type, name, content);
Expand Down
20 changes: 14 additions & 6 deletions src/core/superstate/cacheParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { PathCache } from "core/spaceManager/spaceManager";
import { MakeMDSettings } from "core/types/settings";
import { ContextState, PathState, SpaceState } from "core/types/superstate";
import _ from "lodash";
import { SpaceInfo, SpaceTable, SpaceTables } from "types/mdb";
import { SpaceInfo, SpaceProperty, SpaceTable, SpaceTables } from "types/mdb";
import { orderStringArrayByArray, uniq } from "utils/array";

import { PathPropertyName } from "core/types/context";
import { builtinSpacePathPrefix, builtinSpaces, tagsSpacePath } from "core/types/space";
import { linkContextRow, propertyDependencies } from "core/utils/contexts/linkContextRow";
import { pathByDef } from "core/utils/spaces/query";
import { ensureArray, tagSpacePathFromTag } from "core/utils/strings";
import { defaultContextSchemaID } from "schemas/mdb";
import { defaultContextDBSchema, defaultContextFields, defaultContextSchemaID } from "schemas/mdb";
import { excludePathPredicate } from "utils/hide";
import { parseLinkString, parseMultiString } from "utils/parsers";
import { pathToString } from "utils/path";
Expand All @@ -20,6 +20,7 @@ import { pathToString } from "utils/path";
export const parseContextTableToCache = (space: SpaceInfo, mdb: SpaceTables, paths: string[], dbExists: boolean, pathsIndex: Map<string, PathState>, runContext: math.MathJsInstance) : { changed: boolean, cache: ContextState } => {

const spaceMap : { [key: string] : { [key: string] : string[] } } = {};

if (!space) return {changed: false, cache: null}
if (!mdb) {
return {changed: false, cache: {
Expand All @@ -35,13 +36,20 @@ export const parseContextTableToCache = (space: SpaceInfo, mdb: SpaceTables, pat
}}
}
const schemas = Object.values(mdb).map(f => f.schema);

let cols = mdb[defaultContextSchemaID]?.cols;
if (!cols || cols.length == 0) {
cols = defaultContextFields.rows as SpaceProperty[];
}
const schema = mdb[defaultContextSchemaID]?.schema ?? defaultContextDBSchema;
const contextPaths = mdb[defaultContextSchemaID]?.rows?.map(f => f[PathPropertyName]) ?? [];

const missingPaths = paths.filter(f => !contextPaths.includes(f));
const newPaths = [...orderStringArrayByArray(paths ?? [], contextPaths), ...missingPaths];
const dependencies = propertyDependencies(mdb[defaultContextSchemaID].cols);
const rows = [...mdb[defaultContextSchemaID].rows.filter(f => paths.includes(f[PathPropertyName])), ...missingPaths.map(f => ({[PathPropertyName]: f}))].map(f => linkContextRow(runContext, pathsIndex, f, mdb[defaultContextSchemaID].cols, pathsIndex.get(space.path), dependencies))
const contextTable : SpaceTable = {...mdb[defaultContextSchemaID],
const dependencies = propertyDependencies(cols);
const rows = [...(mdb[defaultContextSchemaID]?.rows ?? []).filter(f => paths.includes(f[PathPropertyName])), ...missingPaths.map(f => ({[PathPropertyName]: f}))].map(f => linkContextRow(runContext, pathsIndex, f, cols, pathsIndex.get(space.path), dependencies))
const contextTable : SpaceTable = {
schema,
cols,
rows: rows
} as SpaceTable;

Expand Down
3 changes: 2 additions & 1 deletion src/core/superstate/superstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,15 @@ public api: API;


const allSpaces = [...this.spaceManager.allSpaces().values()]

const promises = allSpaces.map(f =>
this.reloadSpace(f, null, true));
[...this.spacesIndex.keys()].filter(f => !allSpaces.some(g => g.path == f)).forEach(f =>
this.onSpaceDeleted(f))
;

await Promise.all(promises);

}

public getSpaceItems(spacePath: string, filesOnly?: boolean) : PathStateWithRank[] {
Expand All @@ -340,7 +342,6 @@ public api: API;
}

private async initializeContexts() {

await this.indexer.reload<Map<string, {cache: ContextState, changed: boolean}>>({ type: 'contexts', path: ''}).then(async r => {
const promises = [...r.entries()].map(([path, {cache, changed}]) => this.contextReloaded(path, cache, changed, true));
await Promise.all(promises);
Expand Down
Loading

0 comments on commit 103d465

Please sign in to comment.