Skip to content

Commit

Permalink
Allow rich-text formatting on board column header (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acylation authored Nov 14, 2023
1 parent 7c1cfa0 commit 3f049f0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ui/views/Board/BoardView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@
onRecordUpdate={handleRecordUpdate(groupByField)}
onSortColumns={handleSortColumns}
{readonly}
richText={groupByField?.typeConfig?.richText ?? false}
/>
</BoardOptionsProvider>
2 changes: 2 additions & 0 deletions src/ui/views/Board/components/Board/Board.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
export let columns: Column[];
export let readonly: boolean;
export let richText: boolean;
export let onRecordClick: (record: DataRecord) => void;
export let onRecordUpdate: (column: string, record: DataRecord) => void;
export let onRecordAdd: (column: string) => void;
Expand Down Expand Up @@ -48,6 +49,7 @@
{#each columns as column (column.id)}
<BoardColumn
{readonly}
{richText}
name={column.id}
records={column.records}
{onRecordClick}
Expand Down
6 changes: 4 additions & 2 deletions src/ui/views/Board/components/Board/BoardColumn.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script lang="ts">
import { Button, Typography, Icon } from "obsidian-svelte";
import { Button, Icon } from "obsidian-svelte";
import { i18n } from "src/lib/stores/i18n";
import ColumnHeader from "./ColumnHeader.svelte";
import type { DataRecord, DataField } from "src/lib/dataframe/dataframe";
import CardGroup from "./CardList.svelte";
export let name: string;
export let records: DataRecord[];
export let readonly: boolean;
export let richText: boolean;
export let onDrop: (records: DataRecord[]) => void;
export let includeFields: DataField[];
Expand All @@ -16,7 +18,7 @@
</script>

<section data-id={name} class="projects--board--column">
<Typography variant="label" nomargin>{name}</Typography>
<ColumnHeader value={name} {richText} />
<CardGroup items={records} {onRecordClick} {onDrop} {includeFields} />
{#if !readonly}
<span>
Expand Down
60 changes: 60 additions & 0 deletions src/ui/views/Board/components/Board/ColumnHeader.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script lang="ts">
import { MarkdownRenderer } from "obsidian";
import { app, view } from "src/lib/stores/obsidian";
import { getContext } from "svelte";
export let value: string;
export let richText: boolean = false;
const sourcePath = getContext<string>("sourcePath") ?? "";
function useMarkdown(node: HTMLElement, value: string) {
MarkdownRenderer.renderMarkdown(value, node, sourcePath, $view);
return {
update(newValue: string) {
node.empty();
MarkdownRenderer.renderMarkdown(newValue, node, sourcePath, $view);
},
};
}
function handleClick(event: MouseEvent) {
const targetEl = event.target as HTMLElement;
const closestAnchor =
targetEl.tagName === "A" ? targetEl : targetEl.closest("a");
if (!closestAnchor) {
return;
}
if (closestAnchor.hasClass("internal-link")) {
event.preventDefault();
const href = closestAnchor.getAttr("href");
const newLeaf = event.button === 1 || event.ctrlKey || event.metaKey;
if (href) {
$app.workspace.openLinkText(href, sourcePath, newLeaf);
}
}
}
</script>

{#if richText}
<div use:useMarkdown={value} on:click={handleClick} on:keypress />
{:else}
<div>
{value}
</div>
{/if}

<style>
div :global(p:first-child) {
margin-top: 0;
}
div :global(p:last-child) {
margin-bottom: 0;
}
</style>

0 comments on commit 3f049f0

Please sign in to comment.