From 28966739f61222d83087355baf99413168ef5607 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 2 Oct 2023 20:44:51 +0200 Subject: [PATCH] feat: add step as slider param --- packages/codemirror/slider.mjs | 9 +++++---- packages/transpiler/transpiler.mjs | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/codemirror/slider.mjs b/packages/codemirror/slider.mjs index 47b686c8..62ec33c2 100644 --- a/packages/codemirror/slider.mjs +++ b/packages/codemirror/slider.mjs @@ -6,7 +6,7 @@ export let sliderValues = {}; const getSliderID = (from) => `slider_${from}`; export class SliderWidget extends WidgetType { - constructor(value, min, max, from, to, view) { + constructor(value, min, max, from, to, step, view) { super(); this.value = value; this.min = min; @@ -14,6 +14,7 @@ export class SliderWidget extends WidgetType { this.from = from; this.originalFrom = from; this.to = to; + this.step = step; this.view = view; } @@ -29,7 +30,7 @@ export class SliderWidget extends WidgetType { slider.type = 'range'; slider.min = this.min; slider.max = this.max; - slider.step = (this.max - this.min) / 1000; + slider.step = this.step ?? (this.max - this.min) / 1000; slider.originalValue = this.value; // to make sure the code stays in sync, let's save the original value // becuase .value automatically clamps values so it'll desync with the code @@ -66,9 +67,9 @@ export const updateWidgets = (view, widgets) => { }; function getWidgets(widgetConfigs, view) { - return widgetConfigs.map(({ from, to, value, min, max }) => { + return widgetConfigs.map(({ from, to, value, min, max, step }) => { return Decoration.widget({ - widget: new SliderWidget(value, min, max, from, to, view), + widget: new SliderWidget(value, min, max, from, to, step, view), side: 0, }).range(from /* , to */); }); diff --git a/packages/transpiler/transpiler.mjs b/packages/transpiler/transpiler.mjs index 6eac171f..256be1d2 100644 --- a/packages/transpiler/transpiler.mjs +++ b/packages/transpiler/transpiler.mjs @@ -43,6 +43,7 @@ export function transpiler(input, options = {}) { value: node.arguments[0].raw, // don't use value! min: node.arguments[1]?.value ?? 0, max: node.arguments[2]?.value ?? 1, + step: node.arguments[3]?.value, }); return this.replace(widgetWithLocation(node)); }