Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: view pages #71

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3470cd5
add ability to create views for queries that are treated like any oth…
GamerGirlandCo Aug 11, 2024
be5b447
rename `datacore-view-page` -> `view-page`
GamerGirlandCo Oct 3, 2024
04be842
use SHOUTING_CASE for constants
GamerGirlandCo Oct 3, 2024
54c279e
changes
GamerGirlandCo Oct 3, 2024
670cc20
fix mapping of fetched values
GamerGirlandCo Oct 3, 2024
280e15b
make select element wider
GamerGirlandCo Oct 3, 2024
f7fc2aa
make select field styles more "generalized" (not limited to editable …
GamerGirlandCo Oct 3, 2024
fb062fa
fix selectable input not being wide enough
GamerGirlandCo Oct 3, 2024
d63c645
remove `jsRenderer` child only if it's not null
GamerGirlandCo Oct 3, 2024
815105a
use the currently selected file as the default value in the view conf…
GamerGirlandCo Oct 4, 2024
83442f7
update `currentFile` on selection change
GamerGirlandCo Oct 4, 2024
c30b580
Refactor and simplify a bit of logic
blacksmithgu Oct 8, 2024
1035eaa
add `.docusaurus` to .gitignore
GamerGirlandCo Oct 13, 2024
b092c66
add yarn command to generate the typedocs
GamerGirlandCo Oct 13, 2024
15e9de8
add yarnrc
GamerGirlandCo Oct 13, 2024
10840fc
add yarnrc
GamerGirlandCo Oct 13, 2024
b75aa6e
remove duplicate file
GamerGirlandCo Oct 13, 2024
0d1c651
Revert "add yarnrc"
GamerGirlandCo Oct 13, 2024
e68b3ae
re-add yarnrc
GamerGirlandCo Oct 13, 2024
8d583e4
unignore the index file at docs/root/api
GamerGirlandCo Oct 14, 2024
0667ea7
add github workflow for generating the documentation
GamerGirlandCo Oct 14, 2024
93174e1
remove duplicate gitignore lines
GamerGirlandCo Oct 18, 2024
228e52a
tick off the "view pages" roadmap item
GamerGirlandCo Oct 18, 2024
87081e3
add pages plugin to config to allow for non-api docs to be included i…
GamerGirlandCo Oct 14, 2024
9294584
remove old docs artifacts
GamerGirlandCo Oct 21, 2024
dcc3572
fix errors
GamerGirlandCo Oct 21, 2024
4471edc
add testing stuff to gitignore
GamerGirlandCo Oct 28, 2024
92b776e
fix type errors with `ItemView.getState()`
GamerGirlandCo Oct 28, 2024
ce231a6
remove a couple unrelated changes from branch
GamerGirlandCo Nov 2, 2024
19d5f31
use a proper codemirror editor instead of a plain textarea for better…
GamerGirlandCo Nov 3, 2024
7ab1093
delete unused import and console.log
GamerGirlandCo Nov 3, 2024
1a002f2
add vim bindings if user already has vim mode enabled in obsidian
GamerGirlandCo Nov 3, 2024
60cbda4
add popover previews when links are hovered in datacorejs views
GamerGirlandCo Nov 3, 2024
0760302
make sure the "Escape" key doesn't switch tabs when using vim keybind…
GamerGirlandCo Nov 3, 2024
26d6656
remove redundant parentElement references in `registerDomEvent`
GamerGirlandCo Nov 4, 2024
89893e4
fix ternary in `CurrentFileSelector` making the select element displa…
GamerGirlandCo Nov 4, 2024
dca39ae
simplify language mode selection, fix some styles
GamerGirlandCo Nov 4, 2024
f469cac
more styling
GamerGirlandCo Nov 4, 2024
cad17ba
even more styling
GamerGirlandCo Nov 4, 2024
3f698c5
implement autocomplete via addon plugin
GamerGirlandCo Nov 6, 2024
722245a
remove useeffect cleanup
GamerGirlandCo Jan 12, 2025
10d28c5
fix bug caused by having vim mode disabled
GamerGirlandCo Jan 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ build/

docs/root/api/**/*.*
!docs/root/api/index.md
.docuaurus/
.docuaurus/

# testing
test-vault/.obsidian/plugins/**/*
playwright-report/
test-results/**/*

# keep folders with .gitkeep
!/**/.gitkeep
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Each view will have the following general functionality:

Additionally, there is potential for a few extra nice features:

- [ ] **View Pages**: Special page types which are just Datacore views and which can be put into the side bar or as
- [X] **View Pages**: Special page types which are just Datacore views and which can be put into the side bar or as
regular pages.

## Data Input
Expand Down
5 changes: 1 addition & 4 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ async function build(prod) {
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
"pdfjs-dist",
...builtins],
alias: {
Expand All @@ -55,4 +52,4 @@ async function build(prod) {
}

// Run the build.
build(process.argv[2] === 'production');
build(process.argv[2] === 'production');
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"author": "Michael Brenan",
"license": "MIT",
"devDependencies": {
"@codemirror/language": "https://github.com/lishid/cm-language",
"@codemirror/autocomplete": "^6.18.2",
"@codemirror/language": "^6.10.3",
"@codemirror/state": "^6.0.1",
"@codemirror/view": "^6.0.1",
"@types/jest": "^27.0.1",
Expand All @@ -42,10 +43,13 @@
"typescript": "^5.4.2"
},
"dependencies": {
"@codemirror/lang-javascript": "^6.2.2",
"@datastructures-js/queue": "^4.2.3",
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@replit/codemirror-vim": "^6.2.1",
"codemirror": "^6.0.1",
"emoji-regex": "^10.2.1",
"flatqueue": "^2.0.3",
"localforage": "1.10.0",
Expand All @@ -56,5 +60,6 @@
"sorted-btree": "^1.8.1",
"sucrase": "3.35.0",
"yaml": "^2.3.3"
}
},
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GamerGirlandCo - did you mean to leave this here? It's a VERY specific version of yarn so I just wanted to be sure. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is to ensure other package managers can't accidentally be used

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

}
4 changes: 4 additions & 0 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Coerce } from "./coerce";
import { DataArray } from "./data-array";
import * as luxon from "luxon";
import * as preact from "preact";
import * as phooks from "preact/hooks";

/** Exterally visible API for datacore.
* @group Core
Expand All @@ -38,6 +39,9 @@ export class DatacoreApi {
get app(): App {
return this.core.app;
}
get hooks(): typeof phooks {
return phooks;
}

///////////////
// Local API //
Expand Down
16 changes: 16 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DateTime } from "luxon";
import { App, Plugin, PluginSettingTab, Setting } from "obsidian";
import { createElement, render } from "preact";
import { DEFAULT_SETTINGS, Settings } from "settings";
import { DatacoreQueryView as DatacoreJSView, VIEW_TYPE_DATACOREJS } from "ui/view-page";
import { IndexStatusBar } from "ui/index-status";

/** Reactive data engine for your Obsidian.md vault. */
Expand Down Expand Up @@ -52,6 +53,21 @@ export default class DatacorePlugin extends Plugin {
-100
);

// Views: DatacoreJS view.
// @ts-ignore be quiet
this.registerView(VIEW_TYPE_DATACOREJS, (leaf) => new DatacoreJSView(leaf, this.api));

// Add a command for creating a new view page.
this.addCommand({
id: "datacore-add-view-page",
name: "Create View Page",
callback: () => {
const newLeaf = this.app.workspace.getLeaf("tab");
newLeaf.setViewState({ type: VIEW_TYPE_DATACOREJS, active: true });
this.app.workspace.setActiveLeaf(newLeaf, { focus: true });
},
});

// Register JS highlighting for codeblocks.
this.register(this.registerCodeblockHighlighting());

Expand Down
54 changes: 54 additions & 0 deletions src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import { Extension } from "@codemirror/state";
import type { DatacoreApi } from "api/api";
import { CanvasMetadataIndex } from "index/types/json/canvas";
import "obsidian";
import { App } from "obsidian";
import * as hooks from "preact/hooks";

/** @hidden */
declare module "obsidian" {
interface WorkspaceLeaf {
serialize(): {
id: string;
type: "leaf";
state: {
type: string;
state: any;
};
};
tabHeaderEl: HTMLElement;
tabHeaderInnerTitleEl: HTMLElement;
}
interface View {
getState(): any;
}
interface ItemView {
titleEl: HTMLElement;
getState(): any;
}

interface InternalPlugin<T> {
id: string;
name: string;
description: string;
instance: T;
}
export interface PagePreviewPlugin {
onLinkHover: (
view: View,
hovered: HTMLElement,
hoveredPath: string,
sourcePath: string,
_unknown: unknown
) => void;
}

interface FileManager {
linkUpdaters: {
canvas: {
Expand All @@ -15,6 +54,9 @@ declare module "obsidian" {
};
};
}
interface Vault {
getConfig: (conf: string) => any;
}
interface App {
appId?: string;
plugins: {
Expand All @@ -23,8 +65,15 @@ declare module "obsidian" {
datacore?: {
api: DatacoreApi;
};
"datacore-addon-autocomplete"?: {
readonly extensions: Extension[];
};
};
};
internalPlugins: {
getPluginById: <T>(id: string) => InternalPlugin<T>;
};

embedRegistry: {
embedByExtension: {
[key: string]: unknown;
Expand All @@ -50,5 +99,10 @@ declare module "obsidian" {
declare global {
interface Window {
datacore?: DatacoreApi;
app: App;
CodeMirror: {
defineMode: (mode: string, conf: (config: any) => any) => unknown;
[key: string]: any;
};
}
}
25 changes: 20 additions & 5 deletions src/ui/fields/fields.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,36 @@
font-size: 1.3rem;
}

.datacore-editable-outer .prompt-input {
.datacore-selectable__input-container,
.datacore-selectable__input-container input {
min-width: 100% !important;
width: 100% !important;
display: inline-flex !important;
}

.datacore-editable-outer .prompt-input.datacore-selectable__input-container {
display: inline-block !important;
flex-grow: 1;
}
.datacore-selectable__input-container input {
width: inherit !important;
min-width: max-content !important;
display: inline-block;
}

.datacore-selectable__menu {
z-index: 99999 !important;
top: 0 !important;
}

.datacore-editable-outer .prompt-input input:after {
.prompt-input.datacore-selectable__input-container::after {
content: none !important;
}

.datacore-editable-outer > .suggestion-container:has(.datacore-selectable__control--menu-is-open) {
.value-container.datacore-selectable__value-container {
}

.suggestion-container:has(.datacore-selectable__control--menu-is-open) {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
Expand All @@ -84,13 +99,13 @@
color: var(--text-on-accent-inverted);
}

.datacore-editable-outer .datacore-multi-select-container {
.datacore-multi-select-container {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}

.datacore-editable-outer .datacore-multi-select-value {
.datacore-multi-select-value {
background-color: var(--interactive-accent);
border-radius: var(--tag-radius);
padding: var(--tag-padding-y) var(--tag-padding-x);
Expand Down
16 changes: 13 additions & 3 deletions src/ui/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Provides core preact / rendering utilities for all view types.
* @module ui
*/
import { App, MarkdownRenderer } from "obsidian";
import { App, MarkdownRenderer, MarkdownView, PagePreviewPlugin } from "obsidian";
import { Component } from "obsidian";
import { Link, Literal, Literals } from "expression/literal";
import { Datacore } from "index/datacore";
Expand Down Expand Up @@ -53,7 +53,8 @@ export function DatacoreContextProvider({
* @hidden
*/
export function RawLink({ link, sourcePath: maybeSourcePath }: { link: Link | string; sourcePath?: string }) {
const workspace = useContext(APP_CONTEXT)?.workspace;
const app = useContext(APP_CONTEXT);
const workspace = app.workspace;
const currentPath = useContext(CURRENT_FILE_CONTEXT);
const sourcePath = maybeSourcePath ?? currentPath ?? "";
const parsed = useMemo(() => (Literals.isLink(link) ? link : Link.infer(link)), [link]);
Expand All @@ -65,17 +66,26 @@ export function RawLink({ link, sourcePath: maybeSourcePath }: { link: Link | st
},
[parsed, sourcePath]
);
const linkRef = useRef<HTMLAnchorElement>(null);
const hoverCallback = useCallback(() => {
let pagePreview = app.internalPlugins.getPluginById<PagePreviewPlugin>("page-preview").instance;
const leaf = app.workspace.getMostRecentLeaf();
if (linkRef.current && leaf && !(leaf.view instanceof MarkdownView))
// this last condition prevents duplicate popovers in markdown views
pagePreview.onLinkHover(leaf.view, linkRef.current, parsed.obsidianLink(), sourcePath, null);
}, [linkRef.current]);

return (
<a
ref={linkRef}
aria-label={parsed.displayOrDefault()}
onClick={onClick}
className="internal-link"
target="_blank"
rel="noopener"
data-tooltip-position="top"
data-href={parsed.obsidianLink()}
href={parsed.obsidianLink()}
onMouseOver={hoverCallback}
>
{parsed.displayOrDefault()}
</a>
Expand Down
24 changes: 24 additions & 0 deletions src/ui/view-page.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.dc-cm-editor .cm-gutters {
flex: 0 0 auto;
background-color: transparent;
color: var(--text-faint) !important;
border-right: none !important;
margin-inline-end: var(--file-folding-offset);
font-size: var(--font-ui-smaller);
z-index: 1;
font-variant: tabular-nums;
}
.cm-typeName {
color: var(--headers);
}
.dc-cm-editor {
padding: 1em;
border-radius: 0.5em;
border: 1px solid var(--h5-color);
}
.cm-tooltip.cm-tooltip-autocomplete {
background: var(--embed-bg);
}
.dc-cm-editor img.cm-widgetBuffer[aria-hidden="true"] {
display: none;
}
Loading
Loading