Skip to content

Commit

Permalink
feat: Added API method for creating JUGGL instances
Browse files Browse the repository at this point in the history
  • Loading branch information
HEmile committed Jan 12, 2022
1 parent 2ef9aea commit 5891f1a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docs/Features/Filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The syntax of this simulates [the search syntax in Obsidian](https://help.obsidi
# Search Operators
- `file:`, `path:`, `content:` and `tag:` all work as documented in the [Obsidian help vault](https://help.obsidian.md/Plugins/Search)
- `class:`: Search based on [[CSS Styling#Classes|CSS class]].
- `raw:`: Search using a [[CSS Styling#Selectors|CSS selector]].
- `raw:`: Search using a [[CSS Styling#Selectors|CSS selector]]. For example, if you have a YAML attribute like `year`, you can get all nodes after 2000 using `raw:[year>2000]`
- Any attribute you use in your YAML frontmatter can be used for querying, for instance `aliases:`, `color:` and `title:`.

## Tips
Expand Down
55 changes: 17 additions & 38 deletions main.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"devDependencies": {
"@egjs/hammerjs": "^2.0.17",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^8.1.0",
"@tsconfig/svelte": "^1.0.10",
"@types/cytoscape": "^3.14.11",
Expand All @@ -39,11 +39,12 @@
"hammerjs": "^2.0.8",
"keycharm": "^0.2.0",
"moment": "^2.29.1",
"rollup-plugin-ignore": "^1.0.10",
"rollup": "^2.32.1",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-ignore": "^1.0.10",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-svelte": "7.0.0",
"obsidian": "^0.13.11",
"svelte": "^3.32.1",
"svelte-check": "^1.1.31",
"svelte-preprocess": "4.6.5",
Expand Down
58 changes: 18 additions & 40 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
IDataStore,
IJugglStores,
IJugglPlugin,
IJuggl,
IJuggl, IJugglSettings,
} from 'juggl-api';
import {OBSIDIAN_STORE_NAME, ObsidianStore} from './obsidian-store';
import cytoscape, {NodeSingular} from 'cytoscape';
Expand Down Expand Up @@ -345,45 +345,6 @@ export default class JugglPlugin extends Plugin implements IJugglPlugin {
await leaf.open(neovisView);
}
}
// nodeCypher(label: string): string {
// return 'MATCH (n) WHERE n.name="' + label +
// '" AND n.' + PROP_VAULT + '="' + this.app.vault.getName() +
// '" RETURN n';
// }
//
// localNeighborhoodCypher(label:string): string {
// return 'MATCH (n {name: "' + label +
// '", ' + PROP_VAULT + ':"' + this.app.vault.getName() +
// '"}) OPTIONAL MATCH (n)-[r]-(m) RETURN n,r,m';
// }


// executeQuery() {
// // Code taken from https://github.com/mrjackphil/obsidian-text-expand/blob/0.6.4/main.ts
// const currentView = this.app.workspace.activeLeaf.view;
//
// if (!(currentView instanceof MarkdownView)) {
// return;
// }
//
// const cmDoc = currentView.sourceMode.cmEditor;
// const curNum = cmDoc.getCursor().line;
// const query = this.getContentBetweenLines(curNum, '```cypher', '```', cmDoc);
// if (query.length > 0) {
// const leaf = this.app.workspace.splitActiveLeaf(this.settings.splitDirection);
// try {
// // TODO: Pass query.
// // const neovisView = new NeoVisView((leaf, this, name, [new ObsidianStore(this)]);
// // leaf.open(neovisView);
// } catch (e) {
// if (e instanceof Neo4jError) {
// new Notice('Invalid cypher query. Check console for more info.');
// } else {
// throw e;
// }
// }
// }
// }

public activeGraphs(): IJuggl[] {
// TODO: This is not a great method, no way to find back the inline graphs!
Expand Down Expand Up @@ -412,4 +373,21 @@ export default class JugglPlugin extends Plugin implements IJugglPlugin {
}
this.coreStores[name] = store;
}

public createJuggl(el: HTMLElement, settings?: IJugglSettings, datastores?: IJugglStores, initialNodes?: string[]): IJuggl {
// Public constructor for Juggl instances. Used for the API.
if (!settings) {
settings = Object.assign({}, DefaultJugglSettings.embedSettings);
if (initialNodes) {
settings.expandInitial = false;
}
}
if (!datastores) {
datastores = {
dataStores: [this.coreStores[settings.coreStore] as IDataStore].concat(this.stores),
coreStore: this.coreStores[settings.coreStore],
};
}
return new Juggl(el, this, datastores, settings, initialNodes);
}
}

0 comments on commit 5891f1a

Please sign in to comment.