Skip to content

Commit

Permalink
0.9.995
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-cen committed Jul 27, 2024
1 parent 8b311fd commit 3c3c7e1
Show file tree
Hide file tree
Showing 21 changed files with 246 additions and 184 deletions.
183 changes: 114 additions & 69 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.994",
"version": "0.9.995",
"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
5 changes: 4 additions & 1 deletion src/adapters/obsidian/types/obsidian.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EditorView } from "@codemirror/view";
import { FlowEditorParent } from "adapters/obsidian/ui/editors/FlowEditor";
import { FlowEditor, FlowEditorParent } from "adapters/obsidian/ui/editors/FlowEditor";

declare module "obsidian" {
export enum PopoverState {
Expand Down Expand Up @@ -126,12 +126,15 @@ declare module "obsidian" {
children: any[];
}
interface WorkspaceLeaf {
id: string;
containerEl: HTMLElement;
tabHeaderInnerTitleEl: HTMLElement;
tabHeaderInnerIconEl: HTMLElement;
history: {
backHistory: any[];
};
isFlowBlock?: boolean;
flowEditors?: FlowEditor[];
}
interface Editor {
cm: EditorView;
Expand Down
15 changes: 9 additions & 6 deletions src/adapters/obsidian/ui/editors/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { genId } from "core/utils/uuid";

export interface FlowEditorParent {
flowEditor: FlowEditor | null;
flowEditors: FlowEditor[] | null;
containerEl?: HTMLElement;
view?: View;
dom?: HTMLElement;
Expand Down Expand Up @@ -77,7 +77,7 @@ export class FlowEditor extends nosuper(HoverPopover) {

hideNavBarEl: HTMLElement;

oldPopover = this.parent?.flowEditor;
oldPopover = this.parent?.flowEditors.find((he) => he.id !== this.id);
document: Document =
this.targetEl?.ownerDocument ?? window.activeDocument ?? window.document;

Expand Down Expand Up @@ -275,7 +275,8 @@ export class FlowEditor extends nosuper(HoverPopover) {
);

if (this.parent) {
this.parent.flowEditor = this;
if (!this.parent.flowEditors) this.parent.flowEditors = [];
this.parent.flowEditors.push(this);
this.parent.view.addChild(this);
}
await this.onShowCallback?.(this);
Expand Down Expand Up @@ -349,14 +350,16 @@ export class FlowEditor extends nosuper(HoverPopover) {
this.shownPos = mouseCoords;
this.targetEl.replaceChildren(this.hoverEl);
this.onShow();
app.workspace.onLayoutChange();
this.plugin.app.workspace.onLayoutChange();
this.load();
}

onHide() {
this.oldPopover = null;
if (this.parent?.flowEditor === this) {
this.parent.flowEditor = null;
if (this.parent?.flowEditors.find((he) => he == this)) {
this.parent.flowEditors = this.parent.flowEditors.filter(
(he) => he.id !== this.id
);
}
}

Expand Down
110 changes: 46 additions & 64 deletions src/adapters/obsidian/utils/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,66 +41,64 @@ export const patchWorkspace = (plugin: MakeMDPlugin) => {
},

getLeaf(old) {
//Patch get leaf to always return root leaf if leaf is a flow block
return function (newLeaf?: "split", direction?: SplitDirection) {
let leaf = old.call(this, newLeaf, direction);

let leaf : WorkspaceLeaf = old.call(this, newLeaf, direction);
if (leaf.isFlowBlock) {
const currentLeafId = leaf.id
let foundLeaf = false;
plugin.app.workspace.iterateLeaves((_leaf) => {
//@ts-ignore
if (_leaf.flowEditor) {
//@ts-ignore
_leaf.flowEditor.leaves().forEach((l) => {
if (l.id == leaf.id) {
foundLeaf = true;
leaf = _leaf;
return;
}
if (_leaf.flowEditors && !foundLeaf) {
_leaf.flowEditors.forEach((f) => {
f.leaves().forEach((l) => {
if (l.id == currentLeafId) {
foundLeaf = true;
leaf = _leaf;
return;
}
})

})
if (foundLeaf) return true;
}
leaf = _leaf
return;

}, plugin.app.workspace["rootSplit"]!);

}

return leaf;
};
},
iterateLeaves(old) {
type leafIterator = (item: WorkspaceLeaf) => boolean | void;
return function (arg1, arg2) {
// Fast exit if desired leaf found
if (old.call(this, arg1, arg2)) return true;
// iterateLeaves(old) {
// type leafIterator = (item: WorkspaceLeaf) => boolean | void;
// return function (arg1, arg2) {
// // Fast exit if desired leaf found
// if (old.call(this, arg1, arg2)) return true;

// Handle old/new API parameter swap
const cb: leafIterator = (
typeof arg1 === "function" ? arg1 : arg2
) as leafIterator;
const parent: WorkspaceItem = (
typeof arg1 === "function" ? arg2 : arg1
) as WorkspaceItem;
// // Handle old/new API parameter swap
// const cb: leafIterator = (
// typeof arg1 === "function" ? arg1 : arg2
// ) as leafIterator;
// const parent: WorkspaceItem = (
// typeof arg1 === "function" ? arg2 : arg1
// ) as WorkspaceItem;

if (!parent) return false; // <- during app startup, rootSplit can be null
if (layoutChanging) return false; // Don't let HEs close during workspace change
// if (!parent) return false; // <- during app startup, rootSplit can be null
// if (layoutChanging) return false; // Don't let HEs close during workspace change

// 0.14.x doesn't have WorkspaceContainer; this can just be an instanceof check once 15.x is mandatory:
if (
parent === plugin.app.workspace.rootSplit ||
(WorkspaceContainer && parent instanceof WorkspaceContainer)
) {
for (const popover of FlowEditor.popoversForWindow(
(parent as WorkspaceContainer).win
)) {
// Use old API here for compat w/0.14.x
if (old.call(this, cb, popover.rootSplit)) return true;
}
}
return false;
};
},
// // 0.14.x doesn't have WorkspaceContainer; this can just be an instanceof check once 15.x is mandatory:
// if (
// parent === plugin.app.workspace.rootSplit ||
// (WorkspaceContainer && parent instanceof WorkspaceContainer)
// ) {
// for (const popover of FlowEditor.popoversForWindow(
// (parent as WorkspaceContainer).win
// )) {
// // Use old API here for compat w/0.14.x
// if (old.call(this, cb, popover.rootSplit)) return true;
// }
// }
// return false;
// };
// },
openLinkText(old) {
return function openLinkText(linkText: string, sourcePath: string, newLeaf?: PaneType | boolean, openViewState?: OpenViewState) {
if (linkText.startsWith('spaces://')) {
Expand Down Expand Up @@ -170,32 +168,16 @@ export const patchWorkspaceLeaf = (plugin: MakeMDPlugin) => {
return top.getRoot === this.getRoot ? top : top.getRoot();
};
},
onResize(old) {
return function () {
this.view?.onResize();
};
},
setViewState(old) {
return async function (viewState: ViewState, eState?: unknown) {
const result = await old.call(this, viewState, eState);
try {
const he = FlowEditor.forLeaf(this);
if (he) {
if (viewState.type)
he.hoverEl.setAttribute(
"data-active-view-type",
viewState.type
);
const titleEl = he.hoverEl.querySelector(".popover-title");
if (titleEl) {
titleEl.textContent = this.view?.getDisplayText();
if (this.view?.file?.path) {
titleEl.setAttribute("data-path", this.view.file.path);
} else {
titleEl.removeAttribute("data-path");
}
if (this.flowEditors) {
for (const he of this.flowEditors) {
he.hide();
}
}
this.flowEditors = [];
} catch {}
return result;
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class T {
newView: "New View",
calendarView: "Calendar View",
dayView: "Day View",
closeSpace: "Close Space",
closeSpace: "Close Space in Focus",
customView: "Custom View",
detailsView: "Details View",
catalogView: "Catalog View",
Expand Down Expand Up @@ -774,7 +774,7 @@ class T {
},
hideFrontmatter: {
name: "Hide Context Properties",
desc: "Hide properties you have addeed in context from the Obsidian properties panel",
desc: "Hide properties you have added in context from the Obsidian properties panel",
},
openFileContext: {
name: "Auto Open Explorer",
Expand Down
1 change: 0 additions & 1 deletion src/core/react/components/Explorer/PropertiesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export const PropertiesView = (props: {
...(props.superstate.settings.hideFrontmatter
? columns.map((f) => f.name)
: []),
...(props.excludeKeys ?? []),
]);
setValues(
linkContextRow(
Expand Down
2 changes: 1 addition & 1 deletion src/core/react/components/MarkdownEditor/Backlinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const BacklinkItem = (props: {
useEffect(() => {
refreshBlock(props.path);
}, [props.path]);
const [collapsed, setCollapsed] = useState(false);
const [collapsed, setCollapsed] = useState(true);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export const TreeItem = (props: TreeItemProps) => {
() => setPathState(superstate.pathsIndex.get(data.item.path)),
[data.item.path]
);
const openAuxClick = (e: React.MouseEvent) => {
if (e.button == 1) {
superstate.ui.openPath(pathState.path, "tab");
setActivePath(pathState.path);
setSelectedPaths([data]);
}
};
const openPathAtTarget = (path: TreeNode, e: React.MouseEvent) => {
if (e.shiftKey) {
onSelectRange(path.id as string);
Expand Down Expand Up @@ -338,6 +345,7 @@ export const TreeItem = (props: TreeItemProps) => {
onMouseLeave={mouseOut}
onMouseEnter={hoverItem}
onKeyDown={onKeyDown}
onAuxClick={openAuxClick}
onClick={(e) => openPathAtTarget(data, e)}
onContextMenu={(e) => handleRightClick(e)}
{...dropProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ export const ContextListContainer = (props: {
setView?: (view: string) => void;
}) => {
const { pathState } = useContext(PathContext);
const {
predicate,
editMode,
setEditMode,
dbSchema,
filteredData,
tableData,
} = useContext(ContextEditorContext);
const { predicate, editMode, setEditMode, dbSchema, tableData } =
useContext(ContextEditorContext);
const { frameSchema } = useContext(FramesMDBContext);
const [editSection, setEditSection] = useState<ContextListSections>(null);
const [selectedIndex, setSelectedIndex] = useState<string>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ export const HeaderPropertiesView = (props: {
const toggleCollapsed = () => {
startTransition(() => setCollapsed((f) => !f));
};
const excludedKeys = [
...FMMetadataKeys(props.superstate.settings),
...FMSpaceKeys(props.superstate.settings),
];
return (
<div className="mk-props-contexts">
{!readMode && props.collapseSpaces && (
Expand Down Expand Up @@ -529,9 +533,8 @@ export const HeaderPropertiesView = (props: {
force={true}
compactMode={false}
excludeKeys={[
...FMMetadataKeys(props.superstate.settings),
"tags",
...FMSpaceKeys(props.superstate.settings),
...excludedKeys,
props.superstate.settings.fmKeyAlias,
]}
editable={true}
></PropertiesView>
Expand Down Expand Up @@ -563,6 +566,16 @@ export const HeaderPropertiesView = (props: {
</div>
</div>
)}
{excludedKeys.length > 0 && (
<style>
{`${excludedKeys
.map((f) => `.metadata-property[data-property-key="${f}"]`)
.join(", ")}
{
display: none;
}`}
</style>
)}
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,6 @@ export const TableView = (props: { superstate: Superstate }) => {
}
};

const toggleFlow = (path: string) => {
setOpenFlows((f) =>
f.find((p) => p == path) ? f.filter((p) => p != path) : uniq([...f, path])
);
};

const selectItem = (modifier: PointerModifiers, index: string) => {
if (modifier.metaKey) {
props.superstate.ui.openPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const NewPropertyMenuComponent = (
!existingCols.some((g) => g.name == f.name) &&
![
...FMMetadataKeys(props.superstate.settings),
props.superstate.settings.fmKeyAlias,
"tags",
...FMSpaceKeys(props.superstate.settings),
].some((g) => g == f.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export const showSpaceContextMenu = (
const space = superstate.spacesIndex.get(path.path);
if (!space) return;
const menuOptions: SelectOption[] = [];
menuOptions.push({
name: i18n.menu.openFilePane,
icon: "ui//go-to-file",
onClick: (e) => {
superstate.ui.openPath(path.path, true);
},
});
menuOptions.push(menuSeparator);

menuOptions.push({
name: "New",
type: SelectOptionType.Submenu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const PathStickerView = (props: {
if (!pathState) return;

e.preventDefault();
e.stopPropagation();
const menuOptions: SelectOption[] = [];
menuOptions.push({
name: t.buttons.changeIcon,
Expand Down Expand Up @@ -59,6 +60,7 @@ export const PathStickerView = (props: {
return false;
};
const triggerStickerMenu = (e: React.MouseEvent) => {
e.stopPropagation();
if (pathState?.type == "space") {
props.superstate.ui.openPalette(
(_props: { hide: () => void }) => (
Expand Down
Loading

0 comments on commit 3c3c7e1

Please sign in to comment.