Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Jul 5, 2022
1 parent 023a3f4 commit da27948
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 34 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "excalibrain",
"name": "ExcaliBrain",
"version": "0.1.1",
"version": "0.1.2",
"minAppVersion": "0.15.3",
"description": "A clean, intuitive and editable graph view for Obsidian",
"author": "Zsolt Viczian",
Expand Down
6 changes: 5 additions & 1 deletion src/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ToolsPanel } from "./Components/ToolsPanel";
import { Neighbour, RelationType, Role } from "./Types";
import { HistoryPanel } from "./Components/HistoryPanel";
import { WarningPrompt } from "./utils/Prompts";
import { debug } from "./utils/utils";

export class Scene {
ea: ExcalidrawAutomate;
Expand Down Expand Up @@ -136,7 +137,7 @@ export class Scene {
if(!this.centralLeaf || !app.workspace.getLeafById(this.centralLeaf.id)) {
this.centralLeaf = this.ea.openFileInNewOrAdjacentLeaf(page.file);
} else {
this.centralLeaf.openFile(page.file);
this.centralLeaf.openFile(page.file, {active: false});
}
this.addToHistory(page.file.path);
} else {
Expand Down Expand Up @@ -276,6 +277,7 @@ export class Scene {
return;
}
const node = new Node({
ea: this.ea,
page: n.page,
isInferred: n.relationType === RelationType.INFERRED,
isCentral: x.isCentral,
Expand All @@ -291,6 +293,7 @@ export class Scene {
if(this.historyPanel) {
this.historyPanel.rerender()
}
if(!this.centralPagePath) return;
let centralPage = this.plugin.pages.get(this.centralPagePath);
if(!centralPage) {
//path case sensitivity issue
Expand Down Expand Up @@ -423,6 +426,7 @@ export class Scene {
this.layouts.push(lSiblings);

const rootNode = new Node({
ea: this.ea,
page: centralPage,
isInferred: false,
isCentral: true,
Expand Down
65 changes: 54 additions & 11 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface ExcaliBrainSettings {
ontologySuggesterChildTrigger: string;
ontologySuggesterFriendTrigger: string;
ontologySuggesterTrigger: string;
ontologySuggesterMidSentenceTrigger: string;
boldFields: boolean;
}

export const DEFAULT_SETTINGS: ExcaliBrainSettings = {
Expand Down Expand Up @@ -140,6 +142,8 @@ export const DEFAULT_SETTINGS: ExcaliBrainSettings = {
ontologySuggesterChildTrigger: "::c",
ontologySuggesterFriendTrigger: "::f",
ontologySuggesterTrigger: ":::",
ontologySuggesterMidSentenceTrigger: "(",
boldFields: false,
};

const HIDE_DISABLED_STYLE = "excalibrain-hide-disabled";
Expand Down Expand Up @@ -234,6 +238,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
}

const demoNode = new Node({
ea: this.ea,
page,
isInferred: false,
isCentral: true,
Expand All @@ -244,6 +249,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
demoNode.setCenter({x:0,y:0})

const demoNode2 = new Node({
ea: this.ea,
page: page2,
isInferred:false,
isCentral: false,
Expand Down Expand Up @@ -314,6 +320,10 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
if(this.plugin.settings.ontologySuggesterTrigger === "") {
this.plugin.settings.ontologySuggesterTrigger = ":::";
}
if(this.plugin.settings.ontologySuggesterMidSentenceTrigger === "") {
this.plugin.settings.ontologySuggesterMidSentenceTrigger = "(";
}

this.plugin.setHierarchyLinkStylesExtended();
this.plugin.settings.tagStyleList = Object.keys(this.plugin.settings.tagNodeStyles);
this.plugin.loadCustomNodeLabelFunction();
Expand Down Expand Up @@ -1176,7 +1186,12 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
if(!keys) return;
let f;
while(!(f = keys.next()).done) {
if(!f.value.contains(",")) fieldSet.add(f.value);
if(
!f.value.contains(",") &&
!(f.value.startsWith("**") && f.value.endsWith("**"))
) {
fieldSet.add(f.value);
}
}
});
const fieldNameMap = new Map();
Expand All @@ -1202,7 +1217,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
}
if(k!==v) fieldNameMap.delete(v);
});
return Array.from(fieldNameMap.keys()).join(", ")
return Array.from(fieldNameMap.keys()).sort((a,b)=>a.toLowerCase()<b.toLowerCase()?-1:1).join(", ")
}

async display() {
Expand All @@ -1228,6 +1243,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
page.addChild(page2,RelationType.DEFINED,LinkDirection.FROM);
page2.addParent(page,RelationType.DEFINED,LinkDirection.TO);
this.demoNode = new Node({
ea: this.ea,
page,
isInferred: false,
isCentral: false,
Expand Down Expand Up @@ -1406,7 +1422,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
})
)

let pSeq:Setting, cSeq:Setting, fSeq:Setting, seq: Setting;
let pSetting:Setting, cSetting:Setting, fSetting:Setting, gSetting: Setting, mSetting: Setting, bSetting: Setting;

new Setting(containerEl)
.setName(t("ONTOLOGY_SUGGESTER_NAME"))
Expand All @@ -1416,15 +1432,17 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
.setValue(this.plugin.settings.allowOntologySuggester)
.onChange(value => {
this.plugin.settings.allowOntologySuggester = value;
seq.setDisabled(!value);
pSeq.setDisabled(!value);
cSeq.setDisabled(!value);
fSeq.setDisabled(!value);
gSetting.setDisabled(!value);
pSetting.setDisabled(!value);
cSetting.setDisabled(!value);
fSetting.setDisabled(!value);
mSetting.setDisabled(!value);
bSetting.setDisabled(!value);
this.dirty = true;
})
)

seq = new Setting(containerEl)
gSetting = new Setting(containerEl)
.setName(t("ONTOLOGY_SUGGESTER_ALL_NAME"))
.setDisabled(!this.plugin.settings.allowOntologySuggester)
.addText(text=>
Expand All @@ -1436,7 +1454,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
})
)

pSeq = new Setting(containerEl)
pSetting = new Setting(containerEl)
.setName(t("ONTOLOGY_SUGGESTER_PARENT_NAME"))
.setDisabled(!this.plugin.settings.allowOntologySuggester)
.addText(text=>
Expand All @@ -1449,7 +1467,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
)


cSeq = new Setting(containerEl)
cSetting = new Setting(containerEl)
.setName(t("ONTOLOGY_SUGGESTER_CHILD_NAME"))
.setDisabled(!this.plugin.settings.allowOntologySuggester)
.addText(text=>
Expand All @@ -1461,7 +1479,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
})
)

fSeq = new Setting(containerEl)
fSetting = new Setting(containerEl)
.setName(t("ONTOLOGY_SUGGESTER_FRIEND_NAME"))
.setDisabled(!this.plugin.settings.allowOntologySuggester)
.addText(text=>
Expand All @@ -1473,6 +1491,31 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
})
)

mSetting = new Setting(containerEl)
.setName(t("MID_SENTENCE_SUGGESTER_TRIGGER_NAME"))
.setDesc(fragWithHTML(t("MID_SENTENCE_SUGGESTER_TRIGGER_DESC")))
.addDropdown(dropdown => {
dropdown
.addOption("(","(")
.addOption("[","[")
.setValue(this.plugin.settings.ontologySuggesterMidSentenceTrigger)
.onChange(value => {
this.plugin.settings.ontologySuggesterMidSentenceTrigger = value;
this.dirty = true;
})
})

bSetting = new Setting(containerEl)
.setName(t("BOLD_FIELDS_NAME"))
.setDesc(fragWithHTML(t("BOLD_FIELDS_DESC")))
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.boldFields)
.onChange(value => {
this.plugin.settings.boldFields = value;
this.dirty = true;
}))

this.containerEl.createEl("h1", {
cls: "excalibrain-settings-h1",
text: t("DISPLAY_HEAD")
Expand Down
52 changes: 35 additions & 17 deletions src/Suggesters/OntologySuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,40 @@ export class FieldSuggester extends EditorSuggest<string> {
const settings = this.plugin.settings;
if (settings.allowOntologySuggester) {
const sub = editor.getLine(cursor.line).substring(0, cursor.ch);
const allTrigger = new RegExp(`^${settings.ontologySuggesterTrigger}(.*)$`);
const parentTrigger = new RegExp(`^${settings.ontologySuggesterParentTrigger}(.*)$`);
const childTrigger = new RegExp(`^${settings.ontologySuggesterChildTrigger}(.*)$`);
const friendTrigger = new RegExp(`^${settings.ontologySuggesterFriendTrigger}(.*)$`);
const match =
sub.match(allTrigger)?.[1] ??
sub.match(parentTrigger)?.[1] ??
sub.match(childTrigger)?.[1] ??
sub.match(friendTrigger)?.[1];

const triggerREG = new RegExp(
`(^${settings.ontologySuggesterTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterTrigger
}|^${settings.ontologySuggesterParentTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterParentTrigger
}|^${settings.ontologySuggesterChildTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterChildTrigger
}|^${settings.ontologySuggesterFriendTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterFriendTrigger
})([^\\s\\${settings.ontologySuggesterTrigger}]*)`,"g"
);

let match:string, trigger: string, v;
const r=sub.matchAll(triggerREG);
while(!(v=r.next()).done) {
trigger = v.value[1];
match = v.value[2];
}

if (match !== undefined) {
this.suggestType = sub.match(allTrigger)
? "all"
: (sub.match(parentTrigger)
? "parent"
: sub.match(childTrigger)
? "child"
: "friend");
switch(trigger) {
case settings.ontologySuggesterTrigger:
case settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterTrigger:
this.suggestType = "all";
break;
case settings.ontologySuggesterParentTrigger:
case settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterParentTrigger:
this.suggestType = "parent";
break;
case settings.ontologySuggesterChildTrigger:
case settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterChildTrigger:
this.suggestType = "child";
break;
default:
this.suggestType = "friend";
break;
}

this.latestTriggerInfo = {
end: cursor,
Expand Down Expand Up @@ -95,7 +112,8 @@ export class FieldSuggester extends EditorSuggest<string> {
selectSuggestion(suggestion: string): void {
const { context } = this;
if (context) {
const replacement = `${suggestion}:: `;
const bold = this.plugin.settings.boldFields;
const replacement = `${(bold?"**":"") + suggestion + (bold?"**":"")}:: `;
context.editor.replaceRange(
replacement,
this.latestTriggerInfo.start,
Expand Down
3 changes: 2 additions & 1 deletion src/graph/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Node {
public title: string;

constructor(x:{
ea: ExcalidrawAutomate,
page:Page,
isInferred: boolean,
isCentral: boolean,
Expand All @@ -26,7 +27,7 @@ export class Node {
}) {
this.page = x.page;
this.settings = x.page.plugin.settings;
this.ea = x.page.plugin.EA;
this.ea = x.ea;
if(this.page.isFolder) {
this.style = {
...this.settings.baseNodeStyle,
Expand Down
10 changes: 9 additions & 1 deletion src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ export default {
EXCLUSIONS_DESC: "Dataview or YAML fields that are never used for ontology",
UNASSIGNED_NAME: "Unassigned",
UNASSIGNED_DESC: "Fields in your Vault that are neither excluded nor part of the defined ontology.",
ONTOLOGY_SUGGESTER_NAME: "Ongology Suggester",
ONTOLOGY_SUGGESTER_NAME: "Ontology Suggester",
ONTOLOGY_SUGGESTER_DESC: "Activate ontology suggester in the markdown editor. If enabled then typing the trigger sequence at the beginning of a paragraph "+
"will activate the suggester listing your ontology fields defined above.",
ONTOLOGY_SUGGESTER_ALL_NAME: "Character sequence to trigger generic suggester. The Generic suggester will include all the ontology fields regardless of their direction.",
ONTOLOGY_SUGGESTER_PARENT_NAME: "Character sequence to trigger parent suggester",
ONTOLOGY_SUGGESTER_CHILD_NAME: "Character sequence to trigger child suggester",
ONTOLOGY_SUGGESTER_FRIEND_NAME: "Character sequence to trigger friend suggester",
MID_SENTENCE_SUGGESTER_TRIGGER_NAME: "Mid-sentence dataview field suggester trigger",
MID_SENTENCE_SUGGESTER_TRIGGER_DESC: "You may add fields mid-way in sentences following one of these two formats:<br>" +
"<code>We met at [location:: [[XYZ restaurant]]] with [candidate:: [[John Doe]]]</code><br>" +
"<code>We met at (location:: [[XYZ restaurant]]) with (candidate:: [[John Doe]])</code><br>" +
"If you set this trigger to e.g. <code>(</code> then typing <code>(:::</code> anywhere in the sentence will activate the suggester (assuming you are using the default generic suggester trigger commbination of <code>:::</code> - see setting above).<br>" +
"More info on inline fields: [DataView Help](https://blacksmithgu.github.io/obsidian-dataview/data-annotation/)",
BOLD_FIELDS_NAME: "Add selected field with BOLD",
BOLD_FIELDS_DESC: "Add selected field to text with bold typeface, i.e. (**field name**:: ) resulting in (<b>field name</b>:: )",
DISPLAY_HEAD: "Display",
EXCLUDE_PATHLIST_NAME: "Filepaths to exclude",
EXCLUDE_PATHLIST_DESC: "Enter comma-separated list of filepaths to exclude from the index.",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default class ExcaliBrain extends Plugin {
new Notice("ExcaliBrain: Please start Excalidraw and try again.",4000);
return false;
}
if(!this.EA) {
if(!this.EA !== ea) {
this.EA = ea;
this.registerExcalidrawAutomateHooks()
}
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"0.1.1": "0.15.3",
"0.1.2": "0.15.3",
"0.1.0": "0.15.2",
"0.0.22": "0.14.0"
}

0 comments on commit da27948

Please sign in to comment.