Skip to content

Commit

Permalink
Merge pull request #3268 from obsidian-tasks-group/chore-obsidian-api…
Browse files Browse the repository at this point in the history
…-1.4.0

build(deps-dev): bump obsidian API from 1.1.1 to 1.4.0
  • Loading branch information
claremacrae authored Jan 9, 2025
2 parents 5351ab4 + 378497e commit 7eae9fc
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 67 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "obsidian-tasks-plugin",
"name": "Tasks",
"version": "7.14.0",
"minAppVersion": "1.1.1",
"minAppVersion": "1.4.0",
"description": "Track tasks across your vault. Supports due dates, recurring tasks, done dates, sub-set of checklist items, and filtering.",
"helpUrl": "https://publish.obsidian.md/tasks/",
"author": "Clare Macrae and Ilyas Landikov (created by Martin Schenck)",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"madge": "^8.0.0",
"markdownlint-cli2": "^0.13.0",
"moment": "^2.29.4",
"obsidian": "^1.1.1",
"obsidian": "^1.4.0",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^3.59.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ heading includes Rendering of Task Blocks
- View this file in **Reading mode**...
- On the task line above:
- [ ] #task **left**-click on a date value, and use the date picker to select and save a different date. Check that the date is updated.
- [ ] #task **left**-click on a date value, and click outside the date picker, to confirm that the picker closes.
- [ ] #task **right**-click on a date value, and use the context menu to select and save a different date. Check that the date is updated.
- [ ] #task **right**-click on a date value, and click outside the context menu, to confirm that the menu closes.
- [ ] #task **left**-click on a date value (above), and use the date picker to select and save a different date. Check that the date is updated.
- [ ] #task **left**-click on a date value (above), and click outside the date picker, to confirm that the picker closes.
- [ ] #task **right**-click on a date value (above), and use the context menu to select and save a different date. Check that the date is updated.
- [ ] #task **right**-click on a date value (above), and click outside the context menu, to confirm that the menu closes.
- In the tasks search block below:
- [ ] #task **left**-click on a date value, and use the date picker to select and save a different date. Check that the date is updated.
- [ ] #task **left**-click on a date value, and click outside the date picker, to confirm that the picker closes.
- [ ] #task **right**-click on a date value, and use the context menu to select and save a different date. Check that the date is updated.
- [ ] #task **right**-click on a date value, and click outside the context menu, to confirm that the menu closes.
- [ ] #task **left**-click on a date value (below), and use the date picker to select and save a different date. Check that the date is updated.
- [ ] #task **left**-click on a date value (below), and click outside the date picker, to confirm that the picker closes.
- [ ] #task **right**-click on a date value (below), and use the context menu to select and save a different date. Check that the date is updated.
- [ ] #task **right**-click on a date value (below), and click outside the context menu, to confirm that the menu closes.
- [ ] #task **check**: Checked all above steps for **editing dates** worked

```tasks
Expand Down
4 changes: 4 additions & 0 deletions src/Obsidian/TasksEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class TasksEvents {

public onCacheUpdate(handler: (cacheData: CacheUpdateData) => void): EventRef {
this.logger.debug('TasksEvents.onCacheUpdate()');
// @ts-expect-error: error TS2345: Argument of type '(cacheData: CacheUpdateData) => void'
// is not assignable to parameter of type '(...data: unknown[]) => unknown'.
return this.obsidianEvents.on(Event.CacheUpdate, handler);
}

Expand All @@ -34,6 +36,8 @@ export class TasksEvents {

public onRequestCacheUpdate(handler: (fn: (cacheData: CacheUpdateData) => void) => void): EventRef {
this.logger.debug('TasksEvents.onRequestCacheUpdate()');
// @ts-expect-error: error TS2345: Argument of type '(cacheData: CacheUpdateData) => void'
// is not assignable to parameter of type '(...data: unknown[]) => unknown'.
return this.obsidianEvents.on(Event.RequestCacheUpdate, handler);
}

Expand Down
94 changes: 50 additions & 44 deletions src/Renderer/QueryRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { TasksEvents } from '../Obsidian/TasksEvents';
import { TasksFile } from '../Scripting/TasksFile';
import { DateFallback } from '../DateTime/DateFallback';
import type { Task } from '../Task/Task';
import { QueryResultsRenderer } from './QueryResultsRenderer';
import { type BacklinksEventHandler, type EditButtonClickHandler, QueryResultsRenderer } from './QueryResultsRenderer';
import { createAndAppendElement } from './TaskLineRenderer';

export class QueryRenderer {
Expand Down Expand Up @@ -155,62 +155,68 @@ class QueryRenderChild extends MarkdownRenderChild {
await this.queryResultsRenderer.render(state, tasks, content, {
allTasks: this.plugin.getTasks(),
allMarkdownFiles: this.app.vault.getMarkdownFiles(),
backlinksClickHandler,
backlinksMousedownHandler,
editTaskPencilClickHandler,
backlinksClickHandler: createBacklinksClickHandler(this.app),
backlinksMousedownHandler: createBacklinksMousedownHandler(this.app),
editTaskPencilClickHandler: createEditTaskPencilClickHandler(this.app),
});

this.containerEl.firstChild?.replaceWith(content);
}
}

function editTaskPencilClickHandler(event: MouseEvent, task: Task, allTasks: Task[]) {
event.preventDefault();

const onSubmit = async (updatedTasks: Task[]): Promise<void> => {
await replaceTaskWithTasks({
originalTask: task,
newTasks: DateFallback.removeInferredStatusIfNeeded(task, updatedTasks),
function createEditTaskPencilClickHandler(app: App): EditButtonClickHandler {
return function editTaskPencilClickHandler(event: MouseEvent, task: Task, allTasks: Task[]) {
event.preventDefault();

const onSubmit = async (updatedTasks: Task[]): Promise<void> => {
await replaceTaskWithTasks({
originalTask: task,
newTasks: DateFallback.removeInferredStatusIfNeeded(task, updatedTasks),
});
};

// Need to create a new instance every time, as cursor/task can change.
const taskModal = new TaskModal({
app,
task,
onSubmit,
allTasks,
});
taskModal.open();
};

// Need to create a new instance every time, as cursor/task can change.
const taskModal = new TaskModal({
app,
task,
onSubmit,
allTasks,
});
taskModal.open();
}

async function backlinksClickHandler(ev: MouseEvent, task: Task) {
const result = await getTaskLineAndFile(task, app.vault);
if (result) {
const [line, file] = result;
const leaf = app.workspace.getLeaf(Keymap.isModEvent(ev));
// When the corresponding task has been found,
// suppress the default behavior of the mouse click event
// (which would interfere e.g. if the query is rendered inside a callout).
ev.preventDefault();
// Instead of the default behavior, open the file with the required line highlighted.
await leaf.openFile(file, { eState: { line: line } });
}
}

async function backlinksMousedownHandler(ev: MouseEvent, task: Task) {
// Open in a new tab on middle-click.
// This distinction is not available in the 'click' event, so we handle the 'mousedown' event
// solely for this.
// (for regular left-click we prefer the 'click' event, and not to just do everything here, because
// the 'click' event is more generic for touch devices etc.)
if (ev.button === 1) {
function createBacklinksClickHandler(app: App): BacklinksEventHandler {
return async function backlinksClickHandler(ev: MouseEvent, task: Task) {
const result = await getTaskLineAndFile(task, app.vault);
if (result) {
const [line, file] = result;
const leaf = app.workspace.getLeaf('tab');
const leaf = app.workspace.getLeaf(Keymap.isModEvent(ev));
// When the corresponding task has been found,
// suppress the default behavior of the mouse click event
// (which would interfere e.g. if the query is rendered inside a callout).
ev.preventDefault();
await leaf.openFile(file, { eState: { line: line } });
// Instead of the default behavior, open the file with the required line highlighted.
await leaf.openFile(file, { eState: { line } });
}
}
};
}

function createBacklinksMousedownHandler(app: App): BacklinksEventHandler {
return async function backlinksMousedownHandler(ev: MouseEvent, task: Task) {
// Open in a new tab on middle-click.
// This distinction is not available in the 'click' event, so we handle the 'mousedown' event
// solely for this.
// (for regular left-click we prefer the 'click' event, and not to just do everything here, because
// the 'click' event is more generic for touch devices etc.)
if (ev.button === 1) {
const result = await getTaskLineAndFile(task, app.vault);
if (result) {
const [line, file] = result;
const leaf = app.workspace.getLeaf('tab');
ev.preventDefault();
await leaf.openFile(file, { eState: { line: line } });
}
}
};
}
4 changes: 2 additions & 2 deletions src/Renderer/QueryResultsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { Task } from '../Task/Task';
import { PostponeMenu } from '../ui/Menus/PostponeMenu';
import { TaskLineRenderer, type TextRenderer, createAndAppendElement } from './TaskLineRenderer';

type BacklinksEventHandler = (ev: MouseEvent, task: Task) => Promise<void>;
type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void;
export type BacklinksEventHandler = (ev: MouseEvent, task: Task) => Promise<void>;
export type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void;

export interface QueryRendererParameters {
allTasks: Task[];
Expand Down
2 changes: 0 additions & 2 deletions tests/Obsidian/Cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,6 @@ describe('accessing links in file', function () {
});

it('should access links in frontmatter', () => {
// Update to Obsidian API 1.4.0 to access cachedMetadata.frontmatterLinks
// @ts-expect-error TS2551: Property frontmatterLinks does not exist on type CachedMetadata
const frontMatterLinks = cachedMetadata['frontmatterLinks'];
expect(frontMatterLinks).toBeDefined();

Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1112,10 +1112,10 @@
dependencies:
"@babel/types" "^7.3.0"

"@types/codemirror@0.0.108":
version "0.0.108"
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.108.tgz#e640422b666bf49251b384c390cdeb2362585bde"
integrity sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw==
"@types/codemirror@5.60.8":
version "5.60.8"
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-5.60.8.tgz#b647d04b470e8e1836dd84b2879988fc55c9de68"
integrity sha512-VjFgDF/eB+Aklcy15TtOTLQeMjTo07k7KAjql8OK5Dirr7a6sJY4T1uVBDuTVG9VEmn1uUsohOpYnVfgC6/jyw==
dependencies:
"@types/tern" "*"

Expand Down Expand Up @@ -4573,12 +4573,12 @@ object.values@^1.1.7:
define-properties "^1.2.0"
es-abstract "^1.22.1"

obsidian@^1.1.1:
version "1.2.5"
resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-1.2.5.tgz#86a075de3894303b90450fb98af1293918d13bc3"
integrity sha512-RKN4W3PaHsoWwlNRg1SV+iJssQ5vnQYzsCSfmFAUHvA8Q8nzk4pW3HGWXSvor3ZM532KECljG86lEx02OvBwpA==
obsidian@^1.4.0:
version "1.7.2"
resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-1.7.2.tgz#2d989288742ae7a65760fd87a953d1ff2a402808"
integrity sha512-k9hN9brdknJC+afKr5FQzDRuEFGDKbDjfCazJwpgibwCAoZNYHYV8p/s3mM8I6AsnKrPKNXf8xGuMZ4enWelZQ==
dependencies:
"@types/codemirror" "0.0.108"
"@types/codemirror" "5.60.8"
moment "2.29.4"

once@^1.3.0:
Expand Down

0 comments on commit 7eae9fc

Please sign in to comment.