@gramlot/gramlot 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramlot/gramlot",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -123,6 +123,17 @@ const rangeParameters = {
123
123
  };
124
124
  function rangeEditor(vertical) {
125
125
  return Base => class extends Base {
126
+ #sourceContext;
127
+ #correcting = false;
128
+ setSourceContext(context) { this.#sourceContext = context; }
129
+ projectAttributes(attrs, adapt) {
130
+ const previous = this.parameters;
131
+ const rest = super.projectAttributes(attrs, adapt);
132
+ if (previous && ['min', 'max', 'step'].some(name => previous[name] !== this.parameters[name])) {
133
+ this.writeControlValue(this.parameters.value);
134
+ }
135
+ return rest;
136
+ }
126
137
  createControl() {
127
138
  const control = this.ownerDocument.createElement('input');
128
139
  control.type = 'range';
@@ -133,16 +144,24 @@ function rangeEditor(vertical) {
133
144
  return control;
134
145
  }
135
146
  readControlValue() { return this.control.valueAsNumber; }
136
- writeControlValue(value) { if (this.control.valueAsNumber !== value) this.control.value = String(value); }
147
+ writeControlValue(value) {
148
+ this.control.value = String(value);
149
+ const corrected = this.control.valueAsNumber;
150
+ if (!this.#correcting && Number.isFinite(value) && Number.isFinite(corrected) && corrected !== value) {
151
+ this.#correcting = true;
152
+ try { this.#sourceContext.writeParameter('value', corrected); }
153
+ finally { this.#correcting = false; }
154
+ }
155
+ }
137
156
  };
138
157
  }
139
158
  export const HorizontalSlider = defineComponent({
140
159
  name: 'horizontalSlider', tag: 'gramlot-horizontal-slider', base: NativeControl,
141
- mixins: [Labelbox, FieldState], parameters: rangeParameters, implementation: rangeEditor(false)
160
+ mixins: [Labelbox, FieldState], parameters: rangeParameters, sourceContext: true, implementation: rangeEditor(false)
142
161
  });
143
162
  export const VerticalSlider = defineComponent({
144
163
  name: 'verticalSlider', tag: 'gramlot-vertical-slider', base: NativeControl,
145
- mixins: [Labelbox, FieldState], parameters: rangeParameters, implementation: rangeEditor(true)
164
+ mixins: [Labelbox, FieldState], parameters: rangeParameters, sourceContext: true, implementation: rangeEditor(true)
146
165
  });
147
166
  export const NumberTextBox = defineComponent({
148
167
  name: 'numberTextBox', tag: 'gramlot-number-text-box', base: TypedEditor, mixins: [Labelbox, FieldState],