Skip to content

Commit

Permalink
0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brenan committed Apr 4, 2021
1 parent e8a9bc0 commit 0e824f5
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "dataview",
"name": "Dataview",
"version": "0.2.2",
"version": "0.2.3",
"minAppVersion": "0.10.13",
"description": "Complex data views for the data-obsessed.",
"author": "Michael Brenan <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-dataview",
"version": "0.2.2",
"version": "0.2.3",
"description": "Advanced data views for Obsidian.md.",
"main": "main.js",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions src/eval.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Evaluates fields in the expression language. */
import { BinaryOp, LiteralType, LiteralField, LiteralFieldRepr, Field, Fields } from 'src/query';
import { normalizeDuration } from "src/util/normalize";

/////////////////////////////////
// Core Context Implementation //
Expand Down Expand Up @@ -268,14 +269,14 @@ export const BINARY_OPS = BinaryOpHandler.create()
le: (a, b) => Fields.bool(a.value < b.value)
})
// Date Operations.
.add("-", 'date', 'date', (a, b) => Fields.literal('duration', b.value.until(a.value).toDuration("seconds")))
.add("-", 'date', 'date', (a, b) => Fields.literal('duration', normalizeDuration(b.value.until(a.value).toDuration("seconds"))))
.addComparison('date', {
equals: (a, b) => Fields.bool(a.value.equals(b.value)),
le: (a, b) => Fields.bool(a.value < b.value)
})
// Duration operations.
.add('+', 'duration', 'duration', (a, b) => Fields.literal('duration', a.value.plus(b.value)))
.add('-', 'duration', 'duration', (a, b) => Fields.literal('duration', a.value.minus(b.value)))
.add('+', 'duration', 'duration', (a, b) => Fields.literal('duration', normalizeDuration(a.value.plus(b.value))))
.add('-', 'duration', 'duration', (a, b) => Fields.literal('duration', normalizeDuration(a.value.minus(b.value))))
.addComparison('duration', {
equals: (a, b) => Fields.bool(a.value.equals(b.value)),
le: (a, b) => Fields.bool(a.value < b.value)
Expand All @@ -301,6 +302,11 @@ export const BINARY_OPS = BinaryOpHandler.create()
}
return Fields.object(result);
})
// Link operations.
.addComparison('link', {
equals: (a, b) => Fields.bool(a.value == b.value),
le: (a, b) => Fields.bool(a.value < b.value)
})
// Boolean operations.
.add('&', '*', '*', (a, b) => Fields.literal('boolean', Fields.isTruthy(a) && Fields.isTruthy(b)))
.add('|', '*', '*', (a, b) => Fields.literal('boolean', Fields.isTruthy(a) || Fields.isTruthy(b)))
Expand Down
8 changes: 3 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export default class DataviewPlugin extends Plugin {
settings: DataviewSettings;
workspace: Workspace;

index: FullIndex;
tasks: TaskCache;
index: FullIndex = null;
tasks: TaskCache = null;

async onload() {
this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData());
this.workspace = this.app.workspace;
this.index = null;
this.tasks = null;

this.addSettingTab(new DataviewSettingsTab(this.app, this));

Expand Down Expand Up @@ -96,7 +94,7 @@ export default class DataviewPlugin extends Plugin {

private wrapWithEnsureTaskIndex(ctx: MarkdownPostProcessorContext, container: HTMLElement, success: () => MarkdownRenderChild): EnsurePredicateRenderer {
return new EnsurePredicateRenderer(ctx, container,
() => (this.index != null) && (this.tasks != null),
() => (this.index != null) && (this.tasks != null) && (this.index != undefined) && (this.tasks != undefined),
success);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const EXPRESSION = P.createLanguage<ExpressionLanguage>({
identifierDot: q => P.regexp(/[\p{Letter}\p{Emoji_Presentation}][\p{Letter}\p{Emoji_Presentation}\.\w_-]*/u).desc("variable identifier"),

// An Obsidian link of the form [[<link>]].
link: q => P.regexp(/\[\[(.*)\]\]/u, 1).desc("file link"),
link: q => P.regexp(/\[\[(.*?)\]\]/u, 1).desc("file link"),

// Binary plus or minus operator.
binaryPlusMinus: q => P.regexp(/\+|-/).map(str => str as BinaryOp).desc("'+' or '-'"),
Expand Down
3 changes: 2 additions & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DateTime, Duration } from 'luxon';
import { Field, LiteralField } from 'src/query';
import { normalizeDuration } from './util/normalize';

/** Make an Obsidian-friendly internal link. */
export function createAnchor(text: string, target: string, internal: boolean): HTMLAnchorElement {
Expand Down Expand Up @@ -101,7 +102,7 @@ export function renderMinimalDate(time: DateTime): string {

/** Render a duration in a minimal format to save space. */
export function renderMinimalDuration(dur: Duration): string {
dur = dur.shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds").normalize();
dur = normalizeDuration(dur);

let result = "";
if (dur.years) result += `${dur.years} years, `;
Expand Down
6 changes: 6 additions & 0 deletions src/util/normalize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Duration } from "luxon";

/** Normalize a duration to all of the proper units. */
export function normalizeDuration(dur: Duration) {
return dur.shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds").normalize();
}
10 changes: 10 additions & 0 deletions src/util/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ export class Result<T, E> {
else return Result.failure<U, E>(this.error);
}

public mapErr<U>(func: (err: E) => U): Result<T, U> {
if (this.success) return Result.success<T, U>(this.result);
else return Result.failure<T, U>(func(this.error));
}

public flatMap<U>(func: (res: T) => Result<U, E>): Result<U, E> {
if (this.success) return func(this.result);
else return Result.failure<U, E>(this.error);
}

public flatMapErr<U>(func: (err: E) => Result<T, U>): Result<T, U> {
if (this.success) return Result.success<T, U>(this.result);
else return func(this.error);
}
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"0.2.0": "0.10.13",
"": "0.10.13",
"0.2.1": "0.10.13",
"0.2.2": "0.10.13"
"0.2.2": "0.10.13",
"0.2.3": "0.10.13"
}

0 comments on commit 0e824f5

Please sign in to comment.