Skip to content

Commit

Permalink
0.9.1014
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-cen committed Dec 23, 2024
1 parent cacf5ff commit 3a21dad
Show file tree
Hide file tree
Showing 43 changed files with 1,025 additions and 501 deletions.
284 changes: 142 additions & 142 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.1013",
"version": "0.9.1014",
"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
11 changes: 2 additions & 9 deletions src/adapters/image/imageAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@

import { hashCode } from "core/utils/hash";
import MakeMDPlugin from "main";
import { AFile, FileTypeAdapter, FilesystemMiddleware } from "makemd-core";
import { Platform } from "obsidian";
import pica from "pica";
type ImageTypeCache = Record<never, never>

const hashCode = (str: string) => {
let hash = 0;
for (let i = 0, len = str.length; i < len; i++) {
const chr = str.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}

type ImageTypeContent = Record<never, never>
export class ImageFileTypeAdapter implements FileTypeAdapter<ImageTypeCache, ImageTypeContent> {
private picaInstance;
Expand Down
3 changes: 3 additions & 0 deletions src/adapters/obsidian/filetypes/markdownAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public app: App;
this.parseCache(tFileToAFile(file), true);

}

public async parseCache (file: AFile, refresh?: boolean) {
if (!file) return;
const fCache = this.app.metadataCache.getCache(file.path);
Expand Down Expand Up @@ -153,6 +154,7 @@ public app: App;
.map((f) => "#" + f)
);
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,
Expand All @@ -167,6 +169,7 @@ public app: App;
sticker: fCache.frontmatter?.[this.plugin.superstate.settings.fmKeySticker],
color: fCache.frontmatter?.[this.plugin.superstate.settings.fmKeyColor],
preview: removeMarkdown(contents.slice(fCache.frontmatterPosition?.end.offset ?? 0, 1000))

}}

if (currentCache) {
Expand Down
11 changes: 9 additions & 2 deletions src/adapters/obsidian/replaceMobileMainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import { windowFromDocument } from "utils/dom";
export const replaceMobileMainMenu = (plugin: MakeMDPlugin) => {
if (isTouchScreen(plugin.superstate.ui)) {
const header = plugin.app.workspace.containerEl.querySelector(
".workspace-drawer.mod-left .workspace-drawer-header-left"
plugin.superstate.settings.spacesRightSplit
? ".workspace-drawer.mod-right .workspace-drawer-header-left"
: ".workspace-drawer.mod-left .workspace-drawer-header-left"
);
console.log(header);
header.innerHTML = "";
const reactEl = plugin.superstate.ui.createRoot(header);
reactEl.render(
Expand Down Expand Up @@ -151,7 +154,11 @@ export const ObsidianMobileMainMenu = (props: {
<div
aria-label={i18n.buttons.togglePin}
className="mk-main-menu-button"
onClick={(e) => props.plugin.app.workspace.leftSplit.togglePinned()}
onClick={(e) =>
props.plugin.superstate.settings.spacesRightSplit
? props.plugin.app.workspace.rightSplit.togglePinned()
: props.plugin.app.workspace.leftSplit.togglePinned()
}
>
<div
className="mk-icon-small"
Expand Down
7 changes: 5 additions & 2 deletions src/adapters/obsidian/ui/showMainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ export const showMainMenu = (
const leafs = [];
let spaceActive = true;
if (isMobile) {
const mobileDrawer = plugin.app.workspace
.leftSplit as WorkspaceMobileDrawer;
const mobileDrawer = (
plugin.superstate.settings.spacesRightSplit
? plugin.app.workspace.rightSplit
: plugin.app.workspace.leftSplit
) as WorkspaceMobileDrawer;
const leaves = mobileDrawer.children as WorkspaceLeaf[];
const index = leaves.reduce((p: number, c, i) => {
return c.getViewState().type == FILE_TREE_VIEW_TYPE ? i : p;
Expand Down
3 changes: 2 additions & 1 deletion src/core/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class T {
divider: "Divider",
note: "Note Block",
link: "Web Link",
internalLink: "Link",
callout: "Callout",
bookmark: "Bookmark",
table: "New Table",
Expand All @@ -57,7 +58,7 @@ class T {
emoji: "Emoji",
image: "Image",

newNote: "New Note",
newNote: "Note",
tag: "Tag",
makeMenu: "Flow Menu",
selectStyle: "Style",
Expand Down
17 changes: 16 additions & 1 deletion src/core/react/components/MarkdownEditor/BannerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ export const BannerView = (props: {
pathState?.metadata.property?.[props.superstate.settings.fmKeySticker]
?.length > 0;
setHasSticker(hasSticker);
setOffset(
pathState?.metadata.property?.[
props.superstate.settings.fmKeyBannerOffset
]
? `${Math.min(
100,
parseFloat(
pathState?.metadata.property?.[
props.superstate.settings.fmKeyBannerOffset
]
) * 100
).toString()}%`
: "center"
);
if (banner) {
setBanner(banner);
} else {
Expand All @@ -51,7 +65,8 @@ export const BannerView = (props: {

const [offset, setOffset] = useState(
pathState?.metadata.property?.[props.superstate.settings.fmKeyBannerOffset]
? `${(
? `${Math.min(
100,
parseFloat(
pathState?.metadata.property?.[
props.superstate.settings.fmKeyBannerOffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ export const SpaceTreeComponent = (props: SpaceTreeComponentProps) => {

const dragEnded = (e: React.DragEvent<HTMLDivElement>, overId: string) => {
const modifiers = eventToModifier(e);

dropPathsInTree(
superstate,
dragPaths,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import i18n from "core/i18n";
import { PathCrumb } from "core/react/components/UI/Crumbs/PathCrumb";
import { ContextEditorContext } from "core/react/context/ContextEditorContext";
import { SpaceContext } from "core/react/context/SpaceContext";
import { parseFieldValue } from "core/schemas/parseFieldValue";
import {
addPathToSpaceAtIndex,
Expand All @@ -12,13 +10,8 @@ import {
deletePropertyMultiValue,
updateContextValue,
} from "core/utils/contexts/context";
import React, {
PropsWithChildren,
useContext,
useEffect,
useMemo,
useState,
} from "react";
import React, { PropsWithChildren, useEffect, useMemo, useState } from "react";
import { SpaceTables } from "types/mdb";
import { uniq } from "utils/array";
import { parseMultiString } from "utils/parsers";
import {
Expand All @@ -31,10 +24,12 @@ import { OptionCellBase } from "./OptionCell";
export const ContextCell = (
props: TableCellMultiProp & {
source: string;
contextTable: SpaceTables;
contextPath: string;
}
) => {
const { spaceState } = useContext(SpaceContext);
const { contextTable } = useContext(ContextEditorContext);
const { contextTable } = props;

const fieldValue = useMemo(
() => parseFieldValue(props.propertyValue, "context", props.superstate),
[props.propertyValue]
Expand All @@ -44,10 +39,10 @@ export const ContextCell = (
fieldValue
? props.superstate.spaceManager.resolvePath(
fieldValue.space,
spaceState?.path
props.contextPath
)
: null,
[fieldValue.space, spaceState]
[fieldValue.space, props.contextPath]
);
const parseValue = (v: string, multi: boolean) =>
(multi ? parseMultiString(v) ?? [] : [v]).filter((f) => f);
Expand Down Expand Up @@ -168,7 +163,7 @@ export const ContextCell = (
<PathCrumb
superstate={props.superstate}
path={_props.value}
source={spaceState?.path}
source={props.contextPath}
>
{_props.children}
</PathCrumb>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type DataTypeViewProps = {
compactMode?: boolean;
source?: string;
setEditMode?: (mode: [string, string]) => void;
contextPath?: string;
};

export const DataTypeView: React.FC<DataTypeViewProps> = (
Expand Down Expand Up @@ -106,6 +107,8 @@ export const DataTypeView: React.FC<DataTypeViewProps> = (
{...viewProps}
multi={fieldType.multiType == column.type}
source={props.source}
contextTable={props.contextTable}
contextPath={props.contextPath}
></ContextCell>
);
} else if (fieldType.type == "aggregate") {
Expand All @@ -115,6 +118,9 @@ export const DataTypeView: React.FC<DataTypeViewProps> = (
multi={fieldType.multiType == column.type}
row={row}
source={props.source}
contextTable={props.contextTable}
contextPath={props.contextPath}
cols={props.columns}
></ReduceCell>
);
} else if (fieldType.type == "fileprop") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ContextEditorContext } from "core/react/context/ContextEditorContext";
import { SpaceContext } from "core/react/context/SpaceContext";
import { parseFieldValue } from "core/schemas/parseFieldValue";
import { PathPropertyName } from "core/types/context";
import { calculateAggregate } from "core/utils/contexts/predicate/aggregates";
import React, { useContext, useEffect, useMemo, useState } from "react";
import { DBRow } from "types/mdb";
import React, { useEffect, useMemo, useState } from "react";
import { DBRow, SpaceTableColumn, SpaceTables } from "types/mdb";
import { uniq } from "utils/array";
import { parseMultiString } from "utils/parsers";
import { TableCellMultiProp } from "../TableView/TableView";
Expand All @@ -13,54 +11,56 @@ export const ReduceCell = (
props: TableCellMultiProp & {
source: string;
row: DBRow;
contextTable: SpaceTables;
contextPath: string;
cols: SpaceTableColumn[];
}
) => {
const { spaceState } = useContext(SpaceContext);
const { contextTable, cols } = useContext(ContextEditorContext);

const fieldValue = useMemo(
() => parseFieldValue(props.propertyValue, "aggregate", props.superstate),
[props.propertyValue]
);

const refFieldValue = useMemo(() => {
const field = cols.find((f) => f.name == fieldValue.ref);
const field = props.cols?.find((f) => f.name == fieldValue.ref);
if (field && field.type == "context") {
return parseFieldValue(field.value, "context", props.superstate);
}
return null;
}, [cols, fieldValue]);
}, [props.cols, fieldValue]);

const spacePath = useMemo(() => {
if (refFieldValue && refFieldValue.space) {
return props.superstate.spaceManager.resolvePath(
refFieldValue.space,
spaceState?.path
props.contextPath
);
}
}, [refFieldValue, spaceState]);
}, [refFieldValue, props.contextPath]);

const column = useMemo(() => {
return contextTable[spacePath]?.cols.find(
return props.contextTable[spacePath]?.cols.find(
(f) => f.name == fieldValue.field
);
}, [fieldValue.field, contextTable, spacePath]);
}, [fieldValue.field, props.contextTable, spacePath]);
const parseValue = (v: string, multi: boolean) =>
(multi ? parseMultiString(v) ?? [] : [v]).filter((f) => f);

const [propValues, setPropValues] = useState([]);
useEffect(() => {
if (!fieldValue?.field || !contextTable[spacePath]) {
if (!refFieldValue?.field || !props.contextTable[spacePath]) {
return;
}

setPropValues(
contextTable[spacePath].rows.reduce((p, c) => {
if (parseMultiString(c[fieldValue.field]).includes(props.path)) {
props.contextTable[spacePath].rows.reduce((p, c) => {
if (parseMultiString(c[refFieldValue.field]).includes(props.path)) {
return [...p, c[PathPropertyName]];
}
return p;
}, [])
);
}, [spacePath, fieldValue, props.path, contextTable]);
}, [spacePath, refFieldValue, props.path, props.contextTable]);

const [value, setValue] = useState<string[]>([]);
const result = useMemo(() => {
Expand All @@ -72,14 +72,16 @@ export const ReduceCell = (
props.superstate,
uniq([...value, ...propValues])
.map((f) =>
contextTable[spacePath].rows.find((r) => r[PathPropertyName] == f)
props.contextTable[spacePath].rows.find(
(r) => r[PathPropertyName] == f
)
)
.filter((f) => f)
.map((f) => f[column.name]),
fieldValue.fn,
column
);
}, [value, propValues, fieldValue, contextTable, spacePath, column]);
}, [value, propValues, fieldValue, props.contextTable, spacePath, column]);

useEffect(() => {
setValue(parseValue(props.row[fieldValue.ref], props.multi));
Expand Down
Loading

0 comments on commit 3a21dad

Please sign in to comment.