2022-11-08 04:45:18 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import type { StatusBarItem } from "./Settings";
|
2022-12-06 15:12:59 +00:00
|
|
|
import { MetricType, MetricCounter, BLANK_SB_ITEM, DEFAULT_SETTINGS } from "./Settings";
|
2022-11-08 04:45:18 +00:00
|
|
|
import type BetterWordCount from "src/main";
|
|
|
|
|
|
|
|
export let plugin: BetterWordCount;
|
|
|
|
const { settings } = plugin;
|
|
|
|
|
|
|
|
let statusItems: StatusBarItem[] = [...plugin.settings.statusBar];
|
2022-12-06 15:12:59 +00:00
|
|
|
let altSItems: StatusBarItem[] = [...plugin.settings.altBar];
|
2022-11-08 04:45:18 +00:00
|
|
|
|
2022-12-06 15:12:59 +00:00
|
|
|
function metricToString(metric: Metric): string {
|
|
|
|
if (metric.type === MetricType.file) {
|
|
|
|
switch (metric.counter) {
|
|
|
|
case MetricCounter.words:
|
|
|
|
return "Words in Note"
|
|
|
|
case MetricCounter.characters:
|
|
|
|
return "Chars in Note"
|
|
|
|
case MetricCounter.sentences:
|
|
|
|
return "Sentences in Note"
|
|
|
|
case MetricCounter.files:
|
|
|
|
return "Total Notes"
|
|
|
|
}
|
|
|
|
} else if (metric.type === MetricType.daily) {
|
|
|
|
switch (metric.counter) {
|
|
|
|
case MetricCounter.words:
|
|
|
|
return "Daily Words"
|
|
|
|
case MetricCounter.characters:
|
|
|
|
return "Daily Chars"
|
|
|
|
case MetricCounter.sentences:
|
|
|
|
return "Daily Sentences"
|
|
|
|
case MetricCounter.files:
|
|
|
|
return "Total Notes"
|
|
|
|
}
|
|
|
|
} else if (metric.type === MetricType.total) {
|
|
|
|
switch (metric.counter) {
|
|
|
|
case MetricCounter.words:
|
|
|
|
return "Total Words"
|
|
|
|
case MetricCounter.characters:
|
|
|
|
return "Total Chars"
|
|
|
|
case MetricCounter.sentences:
|
|
|
|
return "Total Sentences"
|
|
|
|
case MetricCounter.files:
|
|
|
|
return "Total Notes"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "Select Options"
|
2022-11-08 04:45:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function swapStatusBarItems(i: number, j: number, arr: StatusBarItem[]) {
|
|
|
|
const max = arr.length - 1;
|
|
|
|
if (i < 0 || i > max || j < 0 || j > max) return arr;
|
|
|
|
const tmp = arr[i];
|
|
|
|
arr[i] = arr[j];
|
|
|
|
arr[j] = tmp;
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function update(statusItems: StatusBarItem[]) {
|
|
|
|
plugin.settings.statusBar = statusItems.filter((item) => {
|
2022-12-06 15:12:59 +00:00
|
|
|
if (metricToString(item.metric) !== "Select Options") {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateAlt(altSItems: StatusBarItem[]) {
|
|
|
|
plugin.settings.altBar = altSItems.filter((item) => {
|
|
|
|
if (metricToString(item.metric) !== "Select Options") {
|
2022-11-08 04:45:18 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
});
|
2022-12-06 15:12:59 +00:00
|
|
|
|
2022-11-08 04:45:18 +00:00
|
|
|
await plugin.saveSettings();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div>
|
2022-12-06 15:12:59 +00:00
|
|
|
<h4>Markdown Status Bar</h4>
|
|
|
|
<p>Here you can customize what statistics are displayed on the status bar when editing a markdown note.</p>
|
2022-11-08 04:45:18 +00:00
|
|
|
<div class="bwc-sb-buttons">
|
|
|
|
<button
|
|
|
|
aria-label="Add New Status Bar Item"
|
2022-12-06 15:12:59 +00:00
|
|
|
on:click={async () => (statusItems = [...statusItems, JSON.parse(JSON.stringify(BLANK_SB_ITEM))])}
|
2022-11-08 04:45:18 +00:00
|
|
|
>
|
|
|
|
<div class="icon">
|
|
|
|
Add Item
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
aria-label="Reset Status Bar to Default"
|
|
|
|
on:click={async () => {
|
2022-12-06 15:12:59 +00:00
|
|
|
statusItems = [
|
|
|
|
{
|
|
|
|
prefix: "",
|
|
|
|
suffix: " words",
|
|
|
|
metric: {
|
|
|
|
type: MetricType.file,
|
|
|
|
counter: MetricCounter.words,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prefix: " ",
|
|
|
|
suffix: " characters",
|
|
|
|
metric: {
|
|
|
|
type: MetricType.file,
|
|
|
|
counter: MetricCounter.characters,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
await update(statusItems);
|
|
|
|
}}
|
2022-11-08 04:45:18 +00:00
|
|
|
>
|
|
|
|
<div class="icon">
|
|
|
|
Reset
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{#each statusItems as item, i}
|
|
|
|
<details class="bwc-sb-item-setting">
|
|
|
|
<summary>
|
|
|
|
<span class="bwc-sb-item-text">
|
2022-12-06 15:12:59 +00:00
|
|
|
{metricToString(item.metric)}
|
2022-11-08 04:45:18 +00:00
|
|
|
</span>
|
|
|
|
<span class="bwc-sb-buttons">
|
|
|
|
{#if i !== 0}
|
|
|
|
<button
|
|
|
|
aria-label="Move Status Bar Item Up"
|
|
|
|
on:click={async () => {
|
|
|
|
statusItems = swapStatusBarItems(i, i-1, statusItems);
|
|
|
|
await update(statusItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
↑
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
{#if i !== statusItems.length - 1}
|
|
|
|
<button
|
|
|
|
aria-label="Move Status Bar Item Down"
|
|
|
|
on:click={async () => {
|
|
|
|
statusItems = swapStatusBarItems(i, i+1, statusItems);
|
|
|
|
await update(statusItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
↓
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
<button
|
|
|
|
aria-label="Remove Status Bar Item"
|
|
|
|
on:click={async () => {
|
|
|
|
statusItems = statusItems.filter((item, j) => i !== j);
|
|
|
|
await update(statusItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
X
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</summary>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
2022-12-06 15:12:59 +00:00
|
|
|
<div class="setting-item-name">Metric Counter</div>
|
2022-11-08 04:45:18 +00:00
|
|
|
<div class="setting-item-description">
|
2022-12-06 15:12:59 +00:00
|
|
|
Select the counter to display, e.g. words, characters.
|
2022-11-08 04:45:18 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<select
|
|
|
|
class="dropdown"
|
2022-12-06 15:12:59 +00:00
|
|
|
value={item.metric.counter}
|
2022-11-08 04:45:18 +00:00
|
|
|
on:change={async (e) => {
|
|
|
|
const {value} = e.target;
|
2022-12-06 15:12:59 +00:00
|
|
|
item.metric.counter = MetricCounter[MetricCounter[value]];
|
2022-11-08 04:45:18 +00:00
|
|
|
await update(statusItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value>Select Option</option>
|
2022-12-06 15:12:59 +00:00
|
|
|
<option value={MetricCounter.words}>Words</option>
|
|
|
|
<option value={MetricCounter.characters}>Characters</option>
|
|
|
|
<option value={MetricCounter.sentences}>Sentences</option>
|
|
|
|
<option value={MetricCounter.files}>Files</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Metric Type</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
Select the type of metric that you want displayed.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<select
|
|
|
|
class="dropdown"
|
|
|
|
value={item.metric.type}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const {value} = e.target;
|
|
|
|
item.metric.type = MetricType[MetricType[value]];
|
|
|
|
await update(statusItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value>Select Option</option>
|
|
|
|
<option value={MetricType.file}>Current Note</option>
|
|
|
|
<option value={MetricType.daily}>Daily Metric</option>
|
|
|
|
<option value={MetricType.total}>Total in Vault</option>
|
2022-11-10 15:23:23 +00:00
|
|
|
</select>
|
2022-11-08 04:45:18 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Prefix Text</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
This is the text that is placed before the count.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="prefix"
|
|
|
|
value={item.prefix}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const { value } = e.target;
|
|
|
|
item.prefix = value;
|
|
|
|
await update(statusItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Suffix Text</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
This is the text that is placed after the count.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="suffix"
|
|
|
|
value={item.suffix}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const { value } = e.target;
|
|
|
|
item.suffix = value;
|
|
|
|
await update(statusItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
{/each}
|
2022-12-06 15:12:59 +00:00
|
|
|
<h4>Alternative Status Bar</h4>
|
|
|
|
<p>Here you can customize what statistics are displayed on the status bar when not editing a markdown file.</p>
|
|
|
|
<div class="bwc-sb-buttons">
|
|
|
|
<button
|
|
|
|
aria-label="Add New Status Bar Item"
|
|
|
|
on:click={async () => (altSItems = [...altSItems, JSON.parse(JSON.stringify(BLANK_SB_ITEM))])}
|
|
|
|
>
|
|
|
|
<div class="icon">
|
|
|
|
Add Item
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
aria-label="Reset Status Bar to Default"
|
|
|
|
on:click={async () => {
|
|
|
|
altSItems = [
|
|
|
|
{
|
|
|
|
prefix: "",
|
|
|
|
suffix: " files",
|
|
|
|
metric: {
|
|
|
|
type: MetricType.total,
|
|
|
|
counter: MetricCounter.files,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
await update(statusItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div class="icon">
|
|
|
|
Reset
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{#each altSItems as item, i}
|
|
|
|
<details class="bwc-sb-item-setting">
|
|
|
|
<summary>
|
|
|
|
<span class="bwc-sb-item-text">
|
|
|
|
{metricToString(item.metric)}
|
|
|
|
</span>
|
|
|
|
<span class="bwc-sb-buttons">
|
|
|
|
{#if i !== 0}
|
|
|
|
<button
|
|
|
|
aria-label="Move Status Bar Item Up"
|
|
|
|
on:click={async () => {
|
|
|
|
altSItems = swapStatusBarItems(i, i-1, altSItems);
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
↑
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
{#if i !== altSItems.length - 1}
|
|
|
|
<button
|
|
|
|
aria-label="Move Status Bar Item Down"
|
|
|
|
on:click={async () => {
|
|
|
|
altSItems = swapStatusBarItems(i, i+1, altSItems);
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
↓
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
<button
|
|
|
|
aria-label="Remove Status Bar Item"
|
|
|
|
on:click={async () => {
|
|
|
|
altSItems = altSItems.filter((item, j) => i !== j);
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
X
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</summary>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Metric Counter</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
Select the counter to display, e.g. words, characters.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<select
|
|
|
|
class="dropdown"
|
|
|
|
value={item.metric.counter}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const {value} = e.target;
|
|
|
|
item.metric.counter = MetricCounter[MetricCounter[value]];
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value>Select Option</option>
|
|
|
|
<option value={MetricCounter.words}>Words</option>
|
|
|
|
<option value={MetricCounter.characters}>Characters</option>
|
|
|
|
<option value={MetricCounter.sentences}>Sentences</option>
|
|
|
|
<option value={MetricCounter.files}>Files</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Metric Type</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
Select the type of metric that you want displayed.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<select
|
|
|
|
class="dropdown"
|
|
|
|
value={item.metric.type}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const {value} = e.target;
|
|
|
|
item.metric.type = MetricType[MetricType[value]];
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value>Select Option</option>
|
|
|
|
<option value={MetricType.file}>Current Note</option>
|
|
|
|
<option value={MetricType.daily}>Daily Metric</option>
|
|
|
|
<option value={MetricType.total}>Total in Vault</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Prefix Text</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
This is the text that is placed before the count.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="prefix"
|
|
|
|
value={item.prefix}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const { value } = e.target;
|
|
|
|
item.prefix = value;
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item">
|
|
|
|
<div class="setting-item-info">
|
|
|
|
<div class="setting-item-name">Suffix Text</div>
|
|
|
|
<div class="setting-item-description">
|
|
|
|
This is the text that is placed after the count.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="setting-item-control">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="suffix"
|
|
|
|
value={item.suffix}
|
|
|
|
on:change={async (e) => {
|
|
|
|
const { value } = e.target;
|
|
|
|
item.suffix = value;
|
|
|
|
await updateAlt(altSItems);
|
|
|
|
await plugin.saveSettings();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
{/each}
|
2022-11-08 04:45:18 +00:00
|
|
|
</div>
|