Skip to content

Commit 1461bca

Browse files
committed
proof of concept #475
1 parent 9a9e397 commit 1461bca

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

exampleVault/Input Fields/Inline Select.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
select: b
33
select2: 1
44
select3: 2 hours
5-
select4:
5+
select4:
66
---
77

88
```meta-bind

packages/core/src/fields/inputFields/AbstractInputField.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export abstract class AbstractInputField<
1818
readonly inputSignal: MappedSignal<unknown, MetadataValueType>;
1919

2020
private metadataSubscription?: MetadataSubscription;
21+
private mountTarget?: HTMLElement;
2122

2223
constructor(mountable: InputFieldMountable) {
2324
super();
@@ -27,7 +28,11 @@ export abstract class AbstractInputField<
2728
this.svelteWrapper = new InputFieldSvelteWrapper<ComponentValueType, SvelteExports>(
2829
this.plugin,
2930
this.getSvelteComponent(),
30-
value => this.notifySubscription(this.mapValue(value)),
31+
value => {
32+
const mappedValue = this.mapValue(value);
33+
this.updateDataAttributes(value, mappedValue);
34+
this.notifySubscription(mappedValue);
35+
},
3136
);
3237

3338
this.inputSignal = new MappedSignal<unknown, MetadataValueType>(
@@ -129,15 +134,32 @@ export abstract class AbstractInputField<
129134
}
130135
}
131136

137+
private updateDataAttributes(internalValue: ComponentValueType, metadataValue: MetadataValueType): void {
138+
if (this.mountTarget) {
139+
this.mountTarget.dataset.internalValue = JSON.stringify(internalValue);
140+
this.mountTarget.dataset.metadataValue = JSON.stringify(metadataValue);
141+
}
142+
}
143+
132144
protected getMountArgs(): Record<string, unknown> {
133145
return {};
134146
}
135147

136148
protected onMount(targetEl: HTMLElement): void {
149+
this.mountTarget = targetEl;
150+
151+
// listener to update the svelte component
137152
this.inputSignal.registerListener({
138153
callback: value => this.svelteWrapper.setValue(this.reverseMapValue(value)),
139154
});
140155

156+
// listener to update data attributes on the target element
157+
this.inputSignal.registerListener({
158+
callback: value => {
159+
this.updateDataAttributes(this.reverseMapValue(value), value);
160+
},
161+
});
162+
141163
const bindTarget = this.mountable.getBindTarget();
142164

143165
if (bindTarget) {
@@ -153,6 +175,8 @@ export abstract class AbstractInputField<
153175
}
154176

155177
protected onUnmount(): void {
178+
this.mountTarget = undefined;
179+
156180
this.inputSignal.unregisterAllListeners();
157181
this.metadataSubscription?.unsubscribe();
158182

packages/core/src/fields/inputFields/fields/ProgressBar/ProgressBarComponent.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@
125125
aria-valuemin={props.minValue}
126126
aria-valuemax={props.maxValue}
127127
aria-valuenow={value}
128-
aria-label={value}
128+
aria-label={value.toString()}
129129
tabindex="0"
130130
></div>
131-
{#if props.addLabels}
132-
<span class="mb-progress-bar-value">{value}</span>
133-
<span class="mb-progress-bar-label-left">{props.minValue}</span>
134-
<span class="mb-progress-bar-label-right">{props.maxValue}</span>
135-
{/if}
131+
{#if props.addLabels}
132+
<span class="mb-progress-bar-value">{value}</span>
133+
<span class="mb-progress-bar-label-left">{props.minValue}</span>
134+
<span class="mb-progress-bar-label-right">{props.maxValue}</span>
135+
{/if}
136136
</div>

packages/core/src/fields/inputFields/fields/ProgressBar/ProgressBarIPF.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class ProgressBarIPF extends AbstractInputField<number, number> {
5454
minValue: this.minValue,
5555
maxValue: this.maxValue,
5656
stepSize: this.stepSize,
57-
addLabels: (this.mountable.getArgument(InputFieldArgumentType.ADD_LABELS)?.value ?? true) === true ,
57+
addLabels: (this.mountable.getArgument(InputFieldArgumentType.ADD_LABELS)?.value ?? true) === true,
5858
};
5959
}
6060
}

0 commit comments

Comments
 (0)