Skip to content

Commit 3ffcdaa

Browse files
committed
readd list input and start of changelog
1 parent 86bd31a commit 3ffcdaa

File tree

4 files changed

+135
-1
lines changed

4 files changed

+135
-1
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Obsidian Meta Bind Changelog
22

3+
4+
# Unreleased
5+
6+
Breaking Changes
7+
8+
- Renamed all CSS variables to start with `mb-` for consistency
9+
10+
New Features
11+
12+
- View Fields can now render as plain text or as markdown e.g.
13+
- `VIEW[{a} * {b}]` or `VIEW[{a} * {b}][math]` this does math as before
14+
- `VIEW[this is plain text][text]` this renders as plain text
15+
- `VIEW[this is **markdown**][text(renderMarkdown)]` this renders as markdown
16+
- `VIEW[this is hidden][text(hidden)]` this does not render
17+
- View Fields can now save their computed value to another frontmatter property
18+
- `VIEW[{a} * {b}][math:c]` will save `a * b` in `c`
19+
- Meta Bind Table, a way to build an expandable table from an array of objects where each cell is an input or view field
20+
- currently only accessible via the JavaScript API
21+
- New Input Field type `listSuggester` a list where new items are added with a suggester
22+
- New argument for `suggester`, `useLinks(true | false)` that can be used to turn off the usage of links
23+
- New `stepSize` argument for `slider` and `progressBar`, thanks @dbarenholz
24+
- New `limit` argument for `text` and `textArea`, thanks @dbarenholz
25+
26+
Changes
27+
- Rewrote all Input Fields to fix Input Fields sometimes overriding frontmatter when changing the frontmatter manually in edit mode
28+
329
# 0.6.3
430

531
Bug Fixes

src/inputFields/_new/NewInputFieldFactory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { EditorIPF } from './fields/Editor/EditorIPF';
1515
import { ProgressBarIPF } from './fields/ProgressBar/ProgressBarIPF';
1616
import { InlineSelectIPF } from './fields/InlineSelect/InlineSelectIPF';
1717
import { ImageSuggesterIPF } from './fields/ImageSuggester/ImageSuggesterIPF';
18+
import { ListIPF } from './fields/List/ListIPF';
1819

1920
export type NewInputField =
2021
| ToggleIPF
@@ -29,7 +30,8 @@ export type NewInputField =
2930
| EditorIPF
3031
| ProgressBarIPF
3132
| InlineSelectIPF
32-
| ImageSuggesterIPF;
33+
| ImageSuggesterIPF
34+
| ListIPF;
3335

3436
export class NewInputFieldFactory {
3537
plugin: IPlugin;
@@ -77,6 +79,8 @@ export class NewInputFieldFactory {
7779
return new InlineSelectIPF(renderChild);
7880
} else if (type === InputFieldType.IMAGE_SUGGESTER) {
7981
return new ImageSuggesterIPF(renderChild);
82+
} else if (type === InputFieldType.LIST) {
83+
return new ListIPF(renderChild);
8084
}
8185

8286
return undefined;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<script lang='ts'>
2+
import { MBLiteral } from '../../../../utils/Utils';
3+
import {
4+
OptionInputFieldArgument
5+
} from '../../../../fieldArguments/inputFieldArguments/arguments/OptionInputFieldArgument';
6+
import { Button, TextInput } from 'obsidian-svelte';
7+
import Icon from '../../../../utils/Icon.svelte';
8+
9+
export let value: MBLiteral[];
10+
export let limit: number | undefined;
11+
export let placeholder: string;
12+
export let onValueChange: (value: MBLiteral[]) => void;
13+
14+
let addValue: string = '';
15+
16+
export function setValue(v: MBLiteral[]): void {
17+
value = v;
18+
}
19+
20+
function add() {
21+
value.push(addValue);
22+
// call with copy of array
23+
onValueChange(value);
24+
addValue = '';
25+
// tell svelte to update
26+
value = value;
27+
}
28+
29+
function remove(i: number) {
30+
value.splice(i, 1);
31+
// call with copy of array
32+
onValueChange(value);
33+
// tell svelte to update
34+
value = value;
35+
}
36+
37+
function getLimitString(length: number, limit: number) {
38+
const limitStr = limit.toString();
39+
const lengthStr = length.toString().padStart(limitStr.length, '0');
40+
return `${lengthStr}/${limitStr}`;
41+
}
42+
</script>
43+
44+
<div class='mb-list-items'>
45+
{#each value as entry, i}
46+
<div class='mb-list-item'>
47+
<span>{entry}</span>
48+
<Button on:click={() => remove(i)}>
49+
<Icon iconName='x' />
50+
</Button>
51+
</div>
52+
{:else}
53+
<span class='mb-list-empty'>Empty</span>
54+
{/each}
55+
</div>
56+
<div class='mb-list-input'>
57+
<input type='text' tabindex='0' placeholder={placeholder} bind:value={addValue} maxlength={limit}>
58+
{#if limit !== undefined}
59+
<span class={`mb-content-limit-indicator ${value.length > limit ? 'mb-content-limit-indicator-overflow' : ''}`} >{getLimitString(value.length, limit)}</span>
60+
{/if}
61+
<Button on:click={() => add()} disabled={!addValue}>
62+
<Icon iconName='plus' />
63+
</Button>
64+
</div>
65+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { NewAbstractInputField } from '../../NewAbstractInputField';
2+
import { type MBLiteral, parseUnknownToLiteralArray } from '../../../../utils/Utils';
3+
import { type InputFieldMDRC } from '../../../../renderChildren/InputFieldMDRC';
4+
import { InputFieldArgumentType } from '../../../../parsers/inputFieldParser/InputFieldConfigs';
5+
import { type SvelteComponent } from 'svelte';
6+
import ListComponent from './ListComponent.svelte';
7+
8+
export class ListIPF extends NewAbstractInputField<MBLiteral[], MBLiteral[]> {
9+
constructor(renderChild: InputFieldMDRC) {
10+
super(renderChild);
11+
}
12+
13+
protected filterValue(value: unknown): MBLiteral[] | undefined {
14+
return parseUnknownToLiteralArray(value);
15+
}
16+
17+
protected getFallbackDefaultValue(): MBLiteral[] {
18+
return [];
19+
}
20+
21+
protected getSvelteComponent(): typeof SvelteComponent {
22+
return ListComponent;
23+
}
24+
25+
protected rawMapValue(value: MBLiteral[]): MBLiteral[] {
26+
return value;
27+
}
28+
29+
protected rawReverseMapValue(value: MBLiteral[]): MBLiteral[] | undefined {
30+
return value;
31+
}
32+
33+
protected getMountArgs(): Record<string, unknown> {
34+
return {
35+
placeholder: this.renderChild.getArgument(InputFieldArgumentType.PLACEHOLDER)?.value ?? 'New Entry...',
36+
limit: this.renderChild.getArgument(InputFieldArgumentType.LIMIT)?.value,
37+
};
38+
}
39+
}

0 commit comments

Comments
 (0)