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

feat: New CSS classes for "themeability" #1519

Merged
merged 34 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e7b0b48
Refactoring: initial extraction of the rendering logic out of Task, a…
esm7 Oct 30, 2022
133ee0c
New renderer works
esm7 Nov 2, 2022
32e9191
Merge remote-tracking branch 'upstream/main' into feat-themeability
esm7 Nov 2, 2022
285664b
Functionality is finished and basic (backwards compatability) tests
esm7 Nov 12, 2022
6f7d102
Merge branch 'main' into feat-themeability
esm7 Jan 8, 2023
db146cc
Themeability and tests
esm7 Jan 11, 2023
362ec19
Merge of the styling.md document, conversion to CSS vars, and a 'far'
esm7 Jan 12, 2023
03dd561
Merge remote-tracking branch 'upstream/main' into feat-themeability
esm7 Jan 12, 2023
3dcb587
Callout fix
esm7 Jan 15, 2023
1c6bbe8
More version markers in the documentation
esm7 Jan 15, 2023
f5d8595
Added specific classes for tags
esm7 Jan 25, 2023
627501b
Classes to denote hidden layout elements (no tests yet)
esm7 Feb 5, 2023
1d4fde9
More layout stuff, see here:
esm7 Feb 7, 2023
f1d44a4
Documentation and sample vault manual tests
esm7 Feb 8, 2023
b7b2287
Merge remote-tracking branch 'upstream/main' into feat-themeability
esm7 Feb 8, 2023
551bcc9
Documentation fixes and fix to a wrong class on invalid dates
esm7 Feb 8, 2023
c2efb51
Converted some CSS classes to data attributes
esm7 Mar 19, 2023
c266cb1
fix: Revert changes that were inconsistent with package.json versions
claremacrae Mar 19, 2023
ef23dc2
fix: Revert main.js added in c2efb51c7e4263e600ac3431e8ac7aec80e76e89.
claremacrae Mar 19, 2023
2744fa1
Merge remote-tracking branch 'upstream/main' into feat-themeability
esm7 Mar 22, 2023
af48568
Added 'normal' as the priority value if no priority field is present:
esm7 Mar 22, 2023
2bc8fbf
vault: Add link to the 'Styling of Queries' for smoke-testing.
claremacrae Mar 27, 2023
1e2a118
docs: Clarify placing of items on 3-line grid
claremacrae Mar 27, 2023
f5e8c29
docs: Add 'normal' priority to the styling docs
claremacrae Mar 27, 2023
65724e7
docs: Document that 'has:' selector needs 1.1.9 Obsidian installer
claremacrae Mar 27, 2023
7daaf11
vault: Document that 'has:' selector needs 1.1.9 Obsidian installer
claremacrae Mar 27, 2023
efb2783
docs: Add table of contents to styling.md
claremacrae Mar 27, 2023
086bf07
docs: Fix tiny typo.
claremacrae Mar 27, 2023
1f8ad60
docs: Fix pluralisation in styling.md
claremacrae Mar 29, 2023
8947322
test: Use whitespace to divide up a long test, for readability
claremacrae Mar 29, 2023
e2f554b
vault: Rename tasks-plugin-query-styling.css to clarify it's for smok…
claremacrae Mar 29, 2023
59ac05d
vault: Move Styling of Queries.md to 'Manual Testing' folder
claremacrae Mar 29, 2023
30f31e7
vault: Minor clarifications to styling smoke test instructions
claremacrae Mar 29, 2023
c32f2bb
Update styling.md
claremacrae Mar 29, 2023
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
387 changes: 382 additions & 5 deletions docs/advanced/styling.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* This file is only for use in smoke-testing the Tasks plugin, and not intended for use by users. */

.block-language-tasks:has(ul.plugin-tasks-query-result[data-task-group-by="priority"]) .tasks-group-heading {
color: red;
}

.block-language-tasks .tasks-layout-short-mode {
background-color: aqua;
}

ul.contains-task-list.tasks-layout-hide-priority {
color: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ heading includes Rendering of Task Blocks

---

### Styling of Rendered Task Blocks

- [ ] #task **check**: Open the file [[Styling of Queries]] and follow the steps there

---

### Create or edit Task modal

- This text should copied in to the task Description, after following steps below
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Styling of Queries

> [!Warning]
> These tests require the `.has` selector.
> The CSS `:has` selector is available with **Obsidian installer version 1.1.9 and newer**. You can run the Obsidian command `Show debug info` to see your current installer version.

---

To test styling of queries, follow these steps, viewing this file either in **Reading** Mode or **Live Preview** Mode:

- [ ] **1. Open the Obsidian settings of the Demo vault and under Appearance | CSS Snippets, turn on `tasks-plugin-smoke-test-query-styling`.**

- [ ] **2.** **Test 'group by' classes** - the following query result should have **red headings** named 'Priority 1: High' and 'Priority 4: Low'.

```tasks
path includes Styling of Queries
group by priority
```

- [ ] **3. Test 'group by' classes #2** - the following should have a **black** heading named 'No due date':

```tasks
path includes Styling of Queries
group by due
```

- [ ] **4. Test short mode classes** - the following should have an aqua background:

```tasks
path includes Styling of Queries
short mode
```

- [ ] **5. Test 'hidden' query classes** - the following lines (except the backlinks) should be colored **red**:

```tasks
path includes Styling of Queries
hide priority
```

- [ ] 6. Open the Obsidian settings of the Demo vault and under Appearance | CSS Snippets, turn **off** `tasks-plugin-smoke-test-query-styling`.

## Tasks for Reference

- [ ] #task Task with high priority ⏫
- [ ] #task Task with low priority 🔽
4 changes: 4 additions & 0 deletions src/InlineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class InlineRenderer {

public markdownPostProcessor = this._markdownPostProcessor.bind(this);

/**
* This renders a file's task list when rendered in Reading View, using roughly the same pipeline
* of QueryRenderer (e.g. it removes the global filter and handles other formatting).
*/
private async _markdownPostProcessor(element: HTMLElement, context: MarkdownPostProcessorContext): Promise<void> {
const { globalFilter } = getSettings();
const renderedElements = element.findAll('.task-list-item').filter((taskItem) => {
Expand Down
22 changes: 19 additions & 3 deletions src/QueryRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TaskModal } from './TaskModal';
import type { TasksEvents } from './TasksEvents';
import type { Task } from './Task';
import { DateFallback } from './DateFallback';
import { TaskLayout } from './TaskLayout';

export class QueryRenderer {
private readonly app: App;
Expand Down Expand Up @@ -188,8 +189,12 @@ class QueryRenderChild extends MarkdownRenderChild {
}): Promise<{ taskList: HTMLUListElement; tasksCount: number }> {
const tasksCount = tasks.length;

const layout = new TaskLayout(this.query.layoutOptions);
const taskList = content.createEl('ul');
taskList.addClasses(['contains-task-list', 'plugin-tasks-query-result']);
taskList.addClasses(layout.specificClasses);
const groupingAttribute = this.getGroupingAttribute();
if (groupingAttribute && groupingAttribute.length > 0) taskList.dataset.taskGroupBy = groupingAttribute;
for (let i = 0; i < tasksCount; i++) {
const task = tasks[i];
const isFilenameUnique = this.isFilenameUnique({ task });
Expand All @@ -199,6 +204,7 @@ class QueryRenderChild extends MarkdownRenderChild {
listIndex: i,
layoutOptions: this.query.layoutOptions,
isFilenameUnique,
taskLayout: layout,
});

// Remove all footnotes. They don't re-appear in another document.
Expand All @@ -207,16 +213,18 @@ class QueryRenderChild extends MarkdownRenderChild {

const shortMode = this.query.layoutOptions.shortMode;

const extrasSpan = listItem.createSpan('task-extras');

if (!this.query.layoutOptions.hideUrgency) {
this.addUrgency(listItem, task);
this.addUrgency(extrasSpan, task);
}

if (!this.query.layoutOptions.hideBacklinks) {
this.addBacklinks(listItem, task, shortMode, isFilenameUnique);
this.addBacklinks(extrasSpan, task, shortMode, isFilenameUnique);
}

if (!this.query.layoutOptions.hideEditButton) {
this.addEditButton(listItem, task);
this.addEditButton(extrasSpan, task);
}

taskList.appendChild(listItem);
Expand Down Expand Up @@ -353,4 +361,12 @@ class QueryRenderChild extends MarkdownRenderChild {

return allFilesWithSameName.length < 2;
}

private getGroupingAttribute() {
const groupingRules: string[] = [];
for (const group of this.query.grouping) {
groupingRules.push(group.property);
}
return groupingRules.join(',');
}
}
10 changes: 8 additions & 2 deletions src/TaskLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class TaskLayout {
'blockLink',
];
public layoutComponents: TaskLayoutComponent[];
public hiddenComponents: TaskLayoutComponent[] = [];
public options: LayoutOptions;
public specificClasses: string[] = [];

constructor(options?: LayoutOptions, components?: TaskLayoutComponent[]) {
if (options) {
Expand All @@ -59,21 +61,24 @@ export class TaskLayout {
} else {
this.layoutComponents = this.defaultLayout;
}

this.layoutComponents = this.applyOptions(this.options);
}

/**
* Return a new list of components with the given options applied.
*/
applyOptions(layoutOptions: LayoutOptions): TaskLayoutComponent[] {
// Remove a component from the taskComponents array if the given layoutOption criteria is met
// Remove a component from the taskComponents array if the given layoutOption criteria is met,
// and add to the layout's specific classes list the class that denotes that this component
// isn't in the layout
const removeIf = (
taskComponents: TaskLayoutComponent[],
shouldRemove: boolean,
componentToRemove: TaskLayoutComponent,
) => {
if (shouldRemove) {
this.specificClasses.push(`tasks-layout-hide-${componentToRemove}`);
this.hiddenComponents.push(componentToRemove);
return taskComponents.filter((element) => element != componentToRemove);
} else {
return taskComponents;
Expand All @@ -89,6 +94,7 @@ export class TaskLayout {
newComponents = removeIf(newComponents, layoutOptions.hideScheduledDate, 'scheduledDate');
newComponents = removeIf(newComponents, layoutOptions.hideDueDate, 'dueDate');
newComponents = removeIf(newComponents, layoutOptions.hideDoneDate, 'doneDate');
if (layoutOptions.shortMode) this.specificClasses.push('tasks-layout-short-mode');
return newComponents;
}
}
Loading