@spectrum-web-components/slider 0.12.6 → 0.12.8-express.6
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/custom-elements.json +6 -6
- package/package.json +7 -7
- package/sp-slider-handle.d.ts +6 -0
- package/sp-slider-handle.js +14 -0
- package/sp-slider-handle.js.map +1 -0
- package/sp-slider.d.ts +7 -0
- package/sp-slider.js +15 -0
- package/sp-slider.js.map +1 -0
- package/src/HandleController.d.ts +110 -0
- package/src/HandleController.js +470 -0
- package/src/HandleController.js.map +1 -0
- package/src/Slider.d.ts +68 -0
- package/src/Slider.js +370 -0
- package/src/Slider.js.map +1 -0
- package/src/SliderHandle.d.ts +57 -0
- package/src/SliderHandle.js +192 -0
- package/src/SliderHandle.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +15 -0
- package/src/index.js.map +1 -0
- package/src/slider.css.d.ts +2 -0
- package/src/slider.css.js +203 -0
- package/src/slider.css.js.map +1 -0
- package/src/spectrum-slider.css.d.ts +2 -0
- package/src/spectrum-slider.css.js +189 -0
- package/src/spectrum-slider.css.js.map +1 -0
- package/stories/slider.stories.js +699 -0
- package/stories/slider.stories.js.map +1 -0
- package/sync/sp-slider.js +14 -0
- package/sync/sp-slider.js.map +1 -0
- package/test/benchmark/test-basic.js +25 -0
- package/test/benchmark/test-basic.js.map +1 -0
- package/test/slider-editable-sync.test.js +147 -0
- package/test/slider-editable-sync.test.js.map +1 -0
- package/test/slider-editable.test.js +147 -0
- package/test/slider-editable.test.js.map +1 -0
- package/test/slider-handle-upgrade.test.js +38 -0
- package/test/slider-handle-upgrade.test.js.map +1 -0
- package/test/slider.test-vrt.js +15 -0
- package/test/slider.test-vrt.js.map +1 -0
- package/test/slider.test.js +842 -0
- package/test/slider.test.js.map +1 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { html } from '@spectrum-web-components/base';
|
|
13
|
+
import { classMap, ifDefined, styleMap, } from '@spectrum-web-components/base/src/directives.js';
|
|
14
|
+
import { SliderHandle, } from './SliderHandle.js';
|
|
15
|
+
export class HandleController {
|
|
16
|
+
constructor(host) {
|
|
17
|
+
this.handles = new Map();
|
|
18
|
+
this.model = [];
|
|
19
|
+
this.handleOrder = [];
|
|
20
|
+
this.handleOrientation = () => {
|
|
21
|
+
this.updateBoundingRect();
|
|
22
|
+
};
|
|
23
|
+
this.extractModelFromLightDom = () => {
|
|
24
|
+
let handles = [
|
|
25
|
+
...this.host.querySelectorAll('[slot="handle"]'),
|
|
26
|
+
];
|
|
27
|
+
if (handles.length === 0) {
|
|
28
|
+
handles = [this.host];
|
|
29
|
+
}
|
|
30
|
+
// extractModelFromLightDom depends on slotted handles already having been upgraded
|
|
31
|
+
if (handles.some((h) => this.waitForUpgrade(h))) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.handles = new Map();
|
|
35
|
+
this.handleOrder = [];
|
|
36
|
+
handles.forEach((handle, index) => {
|
|
37
|
+
var _a;
|
|
38
|
+
/* c8 ignore next */
|
|
39
|
+
if (!((_a = handle.handleName) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
40
|
+
handle.name = `handle${index + 1}`;
|
|
41
|
+
}
|
|
42
|
+
this.handles.set(handle.handleName, handle);
|
|
43
|
+
this.handleOrder.push(handle.handleName);
|
|
44
|
+
handle.handleController = this;
|
|
45
|
+
});
|
|
46
|
+
this.requestUpdate();
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Keep the slider value property in sync with the input element's value
|
|
50
|
+
*/
|
|
51
|
+
this.onInputChange = (event) => {
|
|
52
|
+
const input = event.target;
|
|
53
|
+
input.model.handle.value = input.valueAsNumber;
|
|
54
|
+
this.requestUpdate();
|
|
55
|
+
this.dispatchChangeEvent(input, input.model.handle);
|
|
56
|
+
};
|
|
57
|
+
this.onInputFocus = (event) => {
|
|
58
|
+
const input = event.target;
|
|
59
|
+
let isFocusVisible;
|
|
60
|
+
try {
|
|
61
|
+
isFocusVisible =
|
|
62
|
+
input.matches(':focus-visible') ||
|
|
63
|
+
this.host.matches('.focus-visible');
|
|
64
|
+
/* c8 ignore next 3 */
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
isFocusVisible = this.host.matches('.focus-visible');
|
|
68
|
+
}
|
|
69
|
+
input.model.handle.highlight = isFocusVisible;
|
|
70
|
+
this.requestUpdate();
|
|
71
|
+
};
|
|
72
|
+
this.onInputBlur = (event) => {
|
|
73
|
+
const input = event.target;
|
|
74
|
+
input.model.handle.highlight = false;
|
|
75
|
+
this.requestUpdate();
|
|
76
|
+
};
|
|
77
|
+
this.onInputKeydown = (event) => {
|
|
78
|
+
const input = event.target;
|
|
79
|
+
input.model.handle.highlight = true;
|
|
80
|
+
this.requestUpdate();
|
|
81
|
+
};
|
|
82
|
+
this.host = host;
|
|
83
|
+
}
|
|
84
|
+
get values() {
|
|
85
|
+
const result = {};
|
|
86
|
+
for (const model of this.handles.values()) {
|
|
87
|
+
result[model.handleName] = model.value;
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
get size() {
|
|
92
|
+
return this.handles.size;
|
|
93
|
+
}
|
|
94
|
+
inputForHandle(handle) {
|
|
95
|
+
if (this.handles.has(handle.handleName)) {
|
|
96
|
+
const { input } = this.getHandleElements(handle);
|
|
97
|
+
return input;
|
|
98
|
+
}
|
|
99
|
+
/* c8 ignore next 2 */
|
|
100
|
+
throw new Error(`No input for handle "${handle.name}"`);
|
|
101
|
+
}
|
|
102
|
+
requestUpdate() {
|
|
103
|
+
this.host.requestUpdate();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* It is possible for value attributes to be set programmatically. The <input>
|
|
107
|
+
* for a particular slider needs to have an opportunity to validate any such
|
|
108
|
+
* values
|
|
109
|
+
*
|
|
110
|
+
* @param handle Handle who's value needs validation
|
|
111
|
+
*/
|
|
112
|
+
setValueFromHandle(handle) {
|
|
113
|
+
const elements = this.getHandleElements(handle);
|
|
114
|
+
/* c8 ignore next */
|
|
115
|
+
if (!elements)
|
|
116
|
+
return;
|
|
117
|
+
const { input } = elements;
|
|
118
|
+
if (input.valueAsNumber === handle.value) {
|
|
119
|
+
if (handle.dragging) {
|
|
120
|
+
handle.dispatchInputEvent();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
input.valueAsNumber = handle.value;
|
|
125
|
+
handle.value = input.valueAsNumber;
|
|
126
|
+
this.requestUpdate();
|
|
127
|
+
}
|
|
128
|
+
handle.value = input.valueAsNumber;
|
|
129
|
+
}
|
|
130
|
+
handleHasChanged(handle) {
|
|
131
|
+
if (handle !== this.host) {
|
|
132
|
+
this.requestUpdate();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
formattedValueForHandle(model) {
|
|
136
|
+
var _a;
|
|
137
|
+
const { handle } = model;
|
|
138
|
+
const numberFormat = (_a = handle.numberFormat) !== null && _a !== void 0 ? _a : this.host.numberFormat;
|
|
139
|
+
return handle.getAriaHandleText(model.value, numberFormat);
|
|
140
|
+
}
|
|
141
|
+
get formattedValues() {
|
|
142
|
+
const result = new Map();
|
|
143
|
+
for (const model of this.model) {
|
|
144
|
+
result.set(model.name, this.formattedValueForHandle(model));
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
get focusElement() {
|
|
149
|
+
const { input } = this.getActiveHandleElements();
|
|
150
|
+
if (this.host.editable &&
|
|
151
|
+
!input.model.handle.dragging) {
|
|
152
|
+
return this.host.numberField;
|
|
153
|
+
}
|
|
154
|
+
return input;
|
|
155
|
+
}
|
|
156
|
+
hostConnected() {
|
|
157
|
+
if (!this.observer) {
|
|
158
|
+
this.observer = new MutationObserver(this.extractModelFromLightDom);
|
|
159
|
+
}
|
|
160
|
+
this.observer.observe(this.host, { subtree: true, childList: true });
|
|
161
|
+
this.extractModelFromLightDom();
|
|
162
|
+
if ('orientation' in screen) {
|
|
163
|
+
screen.orientation.addEventListener('change', this.handleOrientation);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
window.addEventListener('orientationchange', this.handleOrientation);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
hostDisconnected() {
|
|
170
|
+
this.observer.disconnect();
|
|
171
|
+
if ('orientation' in screen) {
|
|
172
|
+
screen.orientation.removeEventListener('change', this.handleOrientation);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
window.removeEventListener('orientationchange', this.handleOrientation);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
hostUpdate() {
|
|
179
|
+
this.updateModel();
|
|
180
|
+
}
|
|
181
|
+
// Since extractModelFromLightDom bails on the first un-upgraded handle,
|
|
182
|
+
// a maximum of one listener will be set up per extraction attempt.
|
|
183
|
+
waitForUpgrade(handle) {
|
|
184
|
+
if (handle instanceof SliderHandle) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
handle.addEventListener('sp-slider-handle-ready', () => this.extractModelFromLightDom(), { once: true, passive: true });
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
get activeHandle() {
|
|
191
|
+
return this.handleOrder[this.handleOrder.length - 1];
|
|
192
|
+
}
|
|
193
|
+
get activeHandleInputId() {
|
|
194
|
+
const active = this.activeHandle;
|
|
195
|
+
const index = this.model.findIndex((model) => model.name === active);
|
|
196
|
+
return `input-${index}`;
|
|
197
|
+
}
|
|
198
|
+
activateHandle(name) {
|
|
199
|
+
const index = this.handleOrder.findIndex((item) => item === name);
|
|
200
|
+
if (index >= 0) {
|
|
201
|
+
this.handleOrder.splice(index, 1);
|
|
202
|
+
}
|
|
203
|
+
this.handleOrder.push(name);
|
|
204
|
+
}
|
|
205
|
+
getActiveHandleElements() {
|
|
206
|
+
const name = this.activeHandle;
|
|
207
|
+
const handleSlider = this.handles.get(name);
|
|
208
|
+
const elements = this.getHandleElements(handleSlider);
|
|
209
|
+
return Object.assign({ model: handleSlider }, elements);
|
|
210
|
+
}
|
|
211
|
+
getHandleElements(sliderHandle) {
|
|
212
|
+
if (!this.handleRefMap) {
|
|
213
|
+
this.handleRefMap = new WeakMap();
|
|
214
|
+
const inputNodes = this.host.shadowRoot.querySelectorAll('.handle > input');
|
|
215
|
+
for (const inputNode of inputNodes) {
|
|
216
|
+
const input = inputNode;
|
|
217
|
+
const handle = input.parentElement;
|
|
218
|
+
const model = this.handles.get(handle.getAttribute('name'));
|
|
219
|
+
if (model) {
|
|
220
|
+
this.handleRefMap.set(model, { input, handle });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const components = this.handleRefMap.get(sliderHandle);
|
|
225
|
+
return components;
|
|
226
|
+
}
|
|
227
|
+
clearHandleComponentCache() {
|
|
228
|
+
delete this.handleRefMap;
|
|
229
|
+
}
|
|
230
|
+
get boundingClientRect() {
|
|
231
|
+
if (!this._boundingClientRect) {
|
|
232
|
+
this._boundingClientRect = this.host.track.getBoundingClientRect();
|
|
233
|
+
}
|
|
234
|
+
return this._boundingClientRect;
|
|
235
|
+
}
|
|
236
|
+
updateBoundingRect() {
|
|
237
|
+
delete this._boundingClientRect;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Return the `input` and `model` associated with the event and
|
|
241
|
+
* whether the `input` is a `resolvedInput` meaning it was acquired
|
|
242
|
+
* from the `model` rather than the event.
|
|
243
|
+
*/
|
|
244
|
+
extractDataFromEvent(event) {
|
|
245
|
+
if (!this._activePointerEventData) {
|
|
246
|
+
let input = event.target.querySelector(':scope > .input');
|
|
247
|
+
const resolvedInput = !input;
|
|
248
|
+
const model = input
|
|
249
|
+
? input.model
|
|
250
|
+
: this.model.find((item) => item.name === this.activeHandle);
|
|
251
|
+
if (!input && !!model) {
|
|
252
|
+
input = model.handle.focusElement;
|
|
253
|
+
}
|
|
254
|
+
this._activePointerEventData = {
|
|
255
|
+
input,
|
|
256
|
+
model,
|
|
257
|
+
resolvedInput,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return this._activePointerEventData;
|
|
261
|
+
}
|
|
262
|
+
handlePointerdown(event) {
|
|
263
|
+
const { resolvedInput, model } = this.extractDataFromEvent(event);
|
|
264
|
+
if (!model || this.host.disabled || event.button !== 0) {
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.host.track.setPointerCapture(event.pointerId);
|
|
269
|
+
this.updateBoundingRect();
|
|
270
|
+
this.host.labelEl.click();
|
|
271
|
+
this.draggingHandle = model.handle;
|
|
272
|
+
model.handle.dragging = true;
|
|
273
|
+
this.activateHandle(model.name);
|
|
274
|
+
if (resolvedInput) {
|
|
275
|
+
// When the input is resolved forward the pointer event to
|
|
276
|
+
// `handlePointermove` in order to update the value/UI becuase
|
|
277
|
+
// the pointer event was on the track not a handle
|
|
278
|
+
this.handlePointermove(event);
|
|
279
|
+
}
|
|
280
|
+
this.requestUpdate();
|
|
281
|
+
}
|
|
282
|
+
handlePointerup(event) {
|
|
283
|
+
const { input, model } = this.extractDataFromEvent(event);
|
|
284
|
+
delete this._activePointerEventData;
|
|
285
|
+
if (!model)
|
|
286
|
+
return;
|
|
287
|
+
this.host.labelEl.click();
|
|
288
|
+
model.handle.highlight = false;
|
|
289
|
+
delete this.draggingHandle;
|
|
290
|
+
model.handle.dragging = false;
|
|
291
|
+
this.requestUpdate();
|
|
292
|
+
this.host.track.releasePointerCapture(event.pointerId);
|
|
293
|
+
this.dispatchChangeEvent(input, model.handle);
|
|
294
|
+
}
|
|
295
|
+
handlePointermove(event) {
|
|
296
|
+
const { input, model } = this.extractDataFromEvent(event);
|
|
297
|
+
if (!model)
|
|
298
|
+
return;
|
|
299
|
+
/* c8 ignore next 3 */
|
|
300
|
+
if (!this.draggingHandle) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
event.stopPropagation();
|
|
304
|
+
input.value = this.calculateHandlePosition(event, model).toString();
|
|
305
|
+
model.handle.value = parseFloat(input.value);
|
|
306
|
+
this.requestUpdate();
|
|
307
|
+
}
|
|
308
|
+
dispatchChangeEvent(input, handle) {
|
|
309
|
+
input.valueAsNumber = handle.value;
|
|
310
|
+
const changeEvent = new Event('change', {
|
|
311
|
+
bubbles: true,
|
|
312
|
+
composed: true,
|
|
313
|
+
});
|
|
314
|
+
handle.dispatchEvent(changeEvent);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Returns the value under the cursor
|
|
318
|
+
* @param: PointerEvent on slider
|
|
319
|
+
* @return: Slider value that correlates to the position under the pointer
|
|
320
|
+
*/
|
|
321
|
+
calculateHandlePosition(event, model) {
|
|
322
|
+
const rect = this.boundingClientRect;
|
|
323
|
+
const minOffset = rect.left;
|
|
324
|
+
const offset = event.clientX;
|
|
325
|
+
const size = rect.width;
|
|
326
|
+
const normalized = (offset - minOffset) / size;
|
|
327
|
+
const value = model.normalization.fromNormalized(normalized, model.range.min, model.range.max);
|
|
328
|
+
/* c8 ignore next */
|
|
329
|
+
return this.host.isLTR ? value : model.range.max - value;
|
|
330
|
+
}
|
|
331
|
+
renderHandle(model, index, zIndex, isMultiHandle) {
|
|
332
|
+
var _a;
|
|
333
|
+
const classes = {
|
|
334
|
+
handle: true,
|
|
335
|
+
dragging: ((_a = this.draggingHandle) === null || _a === void 0 ? void 0 : _a.handleName) === model.name,
|
|
336
|
+
'handle-highlight': model.highlight,
|
|
337
|
+
};
|
|
338
|
+
const style = {
|
|
339
|
+
[this.host.isLTR ? 'left' : 'right']: `${model.normalizedValue * 100}%`,
|
|
340
|
+
'z-index': zIndex.toString(),
|
|
341
|
+
// Allow setting background per-handle
|
|
342
|
+
'background-color': `var(--spectrum-slider-handle-background-color-${index}, var(--spectrum-slider-handle-default-background-color))`,
|
|
343
|
+
'border-color': `var(--spectrum-slider-handle-border-color-${index}, var(-spectrum-slider-handle-default-border-color))`,
|
|
344
|
+
};
|
|
345
|
+
const ariaLabelledBy = isMultiHandle ? `label input-${index}` : 'label';
|
|
346
|
+
return html `
|
|
347
|
+
<div
|
|
348
|
+
class=${classMap(classes)}
|
|
349
|
+
name=${model.name}
|
|
350
|
+
style=${styleMap(style)}
|
|
351
|
+
role="presentation"
|
|
352
|
+
>
|
|
353
|
+
<input
|
|
354
|
+
type="range"
|
|
355
|
+
class="input"
|
|
356
|
+
id="input-${index}"
|
|
357
|
+
min=${model.clamp.min}
|
|
358
|
+
max=${model.clamp.max}
|
|
359
|
+
step=${model.step}
|
|
360
|
+
value=${model.value}
|
|
361
|
+
aria-disabled=${ifDefined(this.host.disabled ? 'true' : undefined)}
|
|
362
|
+
tabindex=${ifDefined(this.host.editable ? -1 : undefined)}
|
|
363
|
+
aria-label=${ifDefined(model.ariaLabel)}
|
|
364
|
+
aria-labelledby=${ariaLabelledBy}
|
|
365
|
+
aria-valuetext=${this.formattedValueForHandle(model)}
|
|
366
|
+
@change=${this.onInputChange}
|
|
367
|
+
@focus=${this.onInputFocus}
|
|
368
|
+
@blur=${this.onInputBlur}
|
|
369
|
+
@keydown=${this.onInputKeydown}
|
|
370
|
+
.model=${model}
|
|
371
|
+
/>
|
|
372
|
+
</div>
|
|
373
|
+
`;
|
|
374
|
+
}
|
|
375
|
+
render() {
|
|
376
|
+
this.clearHandleComponentCache();
|
|
377
|
+
return this.model.map((model, index) => {
|
|
378
|
+
const zIndex = this.handleOrder.indexOf(model.name) + 1;
|
|
379
|
+
return this.renderHandle(model, index, zIndex, this.model.length > 1);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Returns a list of track segment [start, end] tuples where the values are
|
|
384
|
+
* normalized to be between 0 and 1.
|
|
385
|
+
* @returns A list of track segment tuples [start, end]
|
|
386
|
+
*/
|
|
387
|
+
trackSegments() {
|
|
388
|
+
const values = this.model.map((model) => model.normalizedValue);
|
|
389
|
+
values.sort((a, b) => a - b);
|
|
390
|
+
// The first segment always starts at 0
|
|
391
|
+
values.unshift(0);
|
|
392
|
+
return values.map((value, index, array) => {
|
|
393
|
+
var _a;
|
|
394
|
+
return [
|
|
395
|
+
value,
|
|
396
|
+
(_a = array[index + 1]) !== null && _a !== void 0 ? _a : 1,
|
|
397
|
+
];
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
updateModel() {
|
|
401
|
+
const handles = [...this.handles.values()];
|
|
402
|
+
const getRangeAndClamp = (index) => {
|
|
403
|
+
const handle = handles[index];
|
|
404
|
+
const previous = handles[index - 1];
|
|
405
|
+
const next = handles[index + 1];
|
|
406
|
+
const min = typeof handle.min === 'number'
|
|
407
|
+
? handle.min
|
|
408
|
+
: this.host.min;
|
|
409
|
+
const max = typeof handle.max === 'number'
|
|
410
|
+
? handle.max
|
|
411
|
+
: this.host.max;
|
|
412
|
+
const result = {
|
|
413
|
+
range: { min: min, max: max },
|
|
414
|
+
clamp: { min: min, max: max },
|
|
415
|
+
};
|
|
416
|
+
if (handle.min === 'previous') {
|
|
417
|
+
if (previous) {
|
|
418
|
+
for (let j = index - 1; j >= 0; j--) {
|
|
419
|
+
const item = handles[j];
|
|
420
|
+
if (typeof item.min === 'number') {
|
|
421
|
+
result.range.min = item.min;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
result.clamp.min = Math.max(previous.value, result.range.min);
|
|
426
|
+
/* c8 ignore next 5 */
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
console.warn('First slider handle cannot have attribute min="previous"');
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (handle.max === 'next') {
|
|
433
|
+
if (next) {
|
|
434
|
+
for (let j = index + 1; j < handles.length; j++) {
|
|
435
|
+
const item = handles[j];
|
|
436
|
+
if (typeof item.max === 'number') {
|
|
437
|
+
result.range.max = item.max;
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
result.clamp.max = Math.min(next.value, result.range.max);
|
|
442
|
+
/* c8 ignore next 5 */
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
console.warn('Last slider handle cannot have attribute max="next"');
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return result;
|
|
449
|
+
};
|
|
450
|
+
const modelValues = handles.map((handle, index) => {
|
|
451
|
+
var _a;
|
|
452
|
+
const rangeAndClamp = getRangeAndClamp(index);
|
|
453
|
+
const { toNormalized } = handle.normalization;
|
|
454
|
+
const clampedValue = Math.max(Math.min(handle.value, rangeAndClamp.clamp.max), rangeAndClamp.clamp.min);
|
|
455
|
+
const normalizedValue = toNormalized(clampedValue, rangeAndClamp.range.min, rangeAndClamp.range.max);
|
|
456
|
+
const model = Object.assign({ name: handle.handleName, value: clampedValue, normalizedValue, highlight: handle.highlight, step: (_a = handle.step) !== null && _a !== void 0 ? _a : this.host.step, normalization: handle.normalization, handle, ariaLabel: handle !== this.host && (handle === null || handle === void 0 ? void 0 : handle.label.length) > 0
|
|
457
|
+
? handle.label
|
|
458
|
+
: undefined }, rangeAndClamp);
|
|
459
|
+
return model;
|
|
460
|
+
});
|
|
461
|
+
this.model = modelValues;
|
|
462
|
+
}
|
|
463
|
+
async handleUpdatesComplete() {
|
|
464
|
+
const updates = [...this.handles.values()]
|
|
465
|
+
.filter((handle) => handle !== this.host)
|
|
466
|
+
.map((handle) => handle.updateComplete);
|
|
467
|
+
await Promise.all(updates);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
//# sourceMappingURL=HandleController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandleController.js","sourceRoot":"","sources":["HandleController.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AACrE,OAAO,EACH,QAAQ,EACR,SAAS,EACT,QAAQ,GACX,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EAEH,YAAY,GAEf,MAAM,mBAAmB,CAAC;AAwC3B,MAAM,OAAO,gBAAgB;IASzB,YAAY,IAAY;QANhB,YAAO,GAA8B,IAAI,GAAG,EAAE,CAAC;QAC/C,UAAK,GAAiB,EAAE,CAAC;QACzB,gBAAW,GAAa,EAAE,CAAC;QAyFzB,sBAAiB,GAAG,GAAS,EAAE;YACrC,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC9B,CAAC,CAAC;QAsDM,6BAAwB,GAAG,GAAS,EAAE;YAC1C,IAAI,OAAO,GAAG;gBACV,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC;aACjC,CAAC;YACpB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACtB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAoB,CAAC,CAAC;aACzC;YACD,mFAAmF;YACnF,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC7C,OAAO;aACV;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;YACtB,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;;gBAC9B,oBAAoB;gBACpB,IAAI,CAAC,CAAA,MAAA,MAAM,CAAC,UAAU,0CAAE,MAAM,CAAA,EAAE;oBAC5B,MAAM,CAAC,IAAI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,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAC9B,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;aACrC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC;aACxC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QAC5C,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["/*\nCopyright 2021 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport {\n classMap,\n ifDefined,\n styleMap,\n} from '@spectrum-web-components/base/src/directives.js';\nimport { Slider } from './Slider.js';\nimport {\n Controller,\n SliderHandle,\n SliderNormalization,\n} from './SliderHandle.js';\n\ninterface HandleReference {\n handle: HTMLElement;\n input: HTMLInputElement;\n}\n\ninterface HandleComponents extends HandleReference {\n model: SliderHandle;\n}\n\ninterface RangeAndClamp {\n range: { min: number; max: number };\n clamp: { min: number; max: number };\n}\ninterface ModelValue extends RangeAndClamp {\n name: string;\n value: number;\n normalizedValue: number;\n step: number;\n highlight: boolean;\n ariaLabel?: string;\n normalization: SliderNormalization;\n handle: SliderHandle;\n}\n\ninterface InputWithModel extends HTMLInputElement {\n model: ModelValue;\n}\n\ninterface DataFromPointerEvent {\n resolvedInput: boolean;\n input: InputWithModel;\n model?: ModelValue;\n}\n\nexport interface HandleValueDictionary {\n [key: string]: number;\n}\n\nexport class HandleController implements Controller {\n private observer!: MutationObserver;\n private host!: Slider;\n private handles: Map<string, SliderHandle> = new Map();\n private model: ModelValue[] = [];\n private handleOrder: string[] = [];\n private draggingHandle?: SliderHandle;\n private handleRefMap?: WeakMap<SliderHandle, HandleReference>;\n\n constructor(host: Slider) {\n this.host = host;\n }\n\n public get values(): HandleValueDictionary {\n const result: HandleValueDictionary = {};\n for (const model of this.handles.values()) {\n result[model.handleName] = model.value;\n }\n return result;\n }\n\n public get size(): number {\n return this.handles.size;\n }\n\n public inputForHandle(handle: SliderHandle): HTMLInputElement | undefined {\n if (this.handles.has(handle.handleName)) {\n const { input } = this.getHandleElements(handle);\n return input;\n }\n /* c8 ignore next 2 */\n throw new Error(`No input for handle \"${handle.name}\"`);\n }\n\n public requestUpdate(): void {\n this.host.requestUpdate();\n }\n\n /**\n * It is possible for value attributes to be set programmatically. The <input>\n * for a particular slider needs to have an opportunity to validate any such\n * values\n *\n * @param handle Handle who's value needs validation\n */\n public setValueFromHandle(handle: SliderHandle): void {\n const elements = this.getHandleElements(handle);\n /* c8 ignore next */\n if (!elements) return;\n\n const { input } = elements;\n if (input.valueAsNumber === handle.value) {\n if (handle.dragging) {\n handle.dispatchInputEvent();\n }\n } else {\n input.valueAsNumber = handle.value;\n handle.value = input.valueAsNumber;\n this.requestUpdate();\n }\n handle.value = input.valueAsNumber;\n }\n\n public handleHasChanged(handle: SliderHandle): void {\n if (handle !== this.host) {\n this.requestUpdate();\n }\n }\n\n public formattedValueForHandle(model: ModelValue): string {\n const { handle } = model;\n const numberFormat = handle.numberFormat ?? this.host.numberFormat;\n return handle.getAriaHandleText(model.value, numberFormat);\n }\n\n public get formattedValues(): Map<string, string> {\n const result = new Map<string, string>();\n for (const model of this.model) {\n result.set(model.name, this.formattedValueForHandle(model));\n }\n return result;\n }\n\n public get focusElement(): HTMLElement {\n const { input } = this.getActiveHandleElements();\n if (\n this.host.editable &&\n !(input as InputWithModel).model.handle.dragging\n ) {\n return this.host.numberField;\n }\n return input;\n }\n\n protected handleOrientation = (): void => {\n this.updateBoundingRect();\n };\n\n public hostConnected(): void {\n if (!this.observer) {\n this.observer = new MutationObserver(this.extractModelFromLightDom);\n }\n this.observer.observe(this.host, { subtree: true, childList: true });\n this.extractModelFromLightDom();\n if ('orientation' in screen) {\n screen.orientation.addEventListener(\n 'change',\n this.handleOrientation\n );\n } else {\n window.addEventListener(\n 'orientationchange',\n this.handleOrientation\n );\n }\n }\n\n public hostDisconnected(): void {\n this.observer.disconnect();\n if ('orientation' in screen) {\n screen.orientation.removeEventListener(\n 'change',\n this.handleOrientation\n );\n } else {\n window.removeEventListener(\n 'orientationchange',\n this.handleOrientation\n );\n }\n }\n\n public hostUpdate(): void {\n this.updateModel();\n }\n\n // Since extractModelFromLightDom bails on the first un-upgraded handle,\n // a maximum of one listener will be set up per extraction attempt.\n private waitForUpgrade(handle: HTMLElement): boolean {\n if (handle instanceof SliderHandle) {\n return false;\n }\n handle.addEventListener(\n 'sp-slider-handle-ready',\n () => this.extractModelFromLightDom(),\n { once: true, passive: true }\n );\n return true;\n }\n\n private extractModelFromLightDom = (): void => {\n let handles = [\n ...this.host.querySelectorAll('[slot=\"handle\"]'),\n ] as SliderHandle[];\n if (handles.length === 0) {\n handles = [this.host as SliderHandle];\n }\n // extractModelFromLightDom depends on slotted handles already having been upgraded\n if (handles.some((h) => this.waitForUpgrade(h))) {\n return;\n }\n this.handles = new Map();\n this.handleOrder = [];\n handles.forEach((handle, index) => {\n /* c8 ignore next */\n if (!handle.handleName?.length) {\n handle.name = `handle${index + 1}`;\n }\n this.handles.set(handle.handleName, handle);\n this.handleOrder.push(handle.handleName);\n handle.handleController = this;\n });\n this.requestUpdate();\n };\n\n public get activeHandle(): string {\n return this.handleOrder[this.handleOrder.length - 1];\n }\n\n public get activeHandleInputId(): string {\n const active = this.activeHandle;\n const index = this.model.findIndex((model) => model.name === active);\n return `input-${index}`;\n }\n\n public activateHandle(name: string): void {\n const index = this.handleOrder.findIndex((item) => item === name);\n if (index >= 0) {\n this.handleOrder.splice(index, 1);\n }\n this.handleOrder.push(name);\n }\n\n private getActiveHandleElements(): HandleComponents {\n const name = this.activeHandle;\n const handleSlider = this.handles.get(name) as SliderHandle;\n const elements = this.getHandleElements(\n handleSlider\n ) as HandleReference;\n return { model: handleSlider, ...elements };\n }\n\n private getHandleElements(sliderHandle: SliderHandle): HandleReference {\n if (!this.handleRefMap) {\n this.handleRefMap = new WeakMap();\n\n const inputNodes =\n this.host.shadowRoot.querySelectorAll('.handle > input');\n for (const inputNode of inputNodes) {\n const input = inputNode as HTMLInputElement;\n const handle = input.parentElement as HTMLElement;\n const model = this.handles.get(\n handle.getAttribute('name') as string\n );\n if (model) {\n this.handleRefMap.set(model, { input, handle });\n }\n }\n }\n\n const components = this.handleRefMap.get(\n sliderHandle\n ) as HandleReference;\n return components;\n }\n\n private clearHandleComponentCache(): void {\n delete this.handleRefMap;\n }\n\n private _boundingClientRect?: DOMRect;\n\n private get boundingClientRect(): DOMRect {\n if (!this._boundingClientRect) {\n this._boundingClientRect = this.host.track.getBoundingClientRect();\n }\n return this._boundingClientRect;\n }\n\n private updateBoundingRect(): void {\n delete this._boundingClientRect;\n }\n\n /**\n * Return the `input` and `model` associated with the event and\n * whether the `input` is a `resolvedInput` meaning it was acquired\n * from the `model` rather than the event.\n */\n protected extractDataFromEvent(event: PointerEvent): DataFromPointerEvent {\n if (!this._activePointerEventData) {\n let input = (event.target as Element).querySelector(\n ':scope > .input'\n ) as InputWithModel;\n const resolvedInput = !input;\n const model = input\n ? input.model\n : this.model.find((item) => item.name === this.activeHandle);\n if (!input && !!model) {\n input = model.handle.focusElement as InputWithModel;\n }\n this._activePointerEventData = {\n input,\n model,\n resolvedInput,\n };\n }\n return this._activePointerEventData;\n }\n\n private _activePointerEventData!: DataFromPointerEvent | undefined;\n\n public handlePointerdown(event: PointerEvent): void {\n const { resolvedInput, model } = this.extractDataFromEvent(event);\n if (!model || this.host.disabled || event.button !== 0) {\n event.preventDefault();\n return;\n }\n this.host.track.setPointerCapture(event.pointerId);\n this.updateBoundingRect();\n this.host.labelEl.click();\n this.draggingHandle = model.handle;\n model.handle.dragging = true;\n this.activateHandle(model.name);\n if (resolvedInput) {\n // When the input is resolved forward the pointer event to\n // `handlePointermove` in order to update the value/UI becuase\n // the pointer event was on the track not a handle\n this.handlePointermove(event);\n }\n this.requestUpdate();\n }\n\n public handlePointerup(event: PointerEvent): void {\n const { input, model } = this.extractDataFromEvent(event);\n delete this._activePointerEventData;\n if (!model) return;\n this.host.labelEl.click();\n model.handle.highlight = false;\n delete this.draggingHandle;\n model.handle.dragging = false;\n this.requestUpdate();\n this.host.track.releasePointerCapture(event.pointerId);\n this.dispatchChangeEvent(input, model.handle);\n }\n\n public handlePointermove(event: PointerEvent): void {\n const { input, model } = this.extractDataFromEvent(event);\n if (!model) return;\n /* c8 ignore next 3 */\n if (!this.draggingHandle) {\n return;\n }\n event.stopPropagation();\n input.value = this.calculateHandlePosition(event, model).toString();\n model.handle.value = parseFloat(input.value);\n this.requestUpdate();\n }\n\n /**\n * Keep the slider value property in sync with the input element's value\n */\n private onInputChange = (event: Event): void => {\n const input = event.target as InputWithModel;\n input.model.handle.value = input.valueAsNumber;\n\n this.requestUpdate();\n this.dispatchChangeEvent(input, input.model.handle);\n };\n\n private onInputFocus = (event: Event): void => {\n const input = event.target as InputWithModel;\n let isFocusVisible;\n try {\n isFocusVisible =\n input.matches(':focus-visible') ||\n this.host.matches('.focus-visible');\n /* c8 ignore next 3 */\n } catch (error) {\n isFocusVisible = this.host.matches('.focus-visible');\n }\n input.model.handle.highlight = isFocusVisible;\n this.requestUpdate();\n };\n\n private onInputBlur = (event: Event): void => {\n const input = event.target as InputWithModel;\n input.model.handle.highlight = false;\n this.requestUpdate();\n };\n\n private onInputKeydown = (event: Event): void => {\n const input = event.target as InputWithModel;\n input.model.handle.highlight = true;\n this.requestUpdate();\n };\n\n private dispatchChangeEvent(\n input: HTMLInputElement,\n handle: SliderHandle\n ): void {\n input.valueAsNumber = handle.value;\n\n const changeEvent = new Event('change', {\n bubbles: true,\n composed: true,\n });\n\n handle.dispatchEvent(changeEvent);\n }\n\n /**\n * Returns the value under the cursor\n * @param: PointerEvent on slider\n * @return: Slider value that correlates to the position under the pointer\n */\n private calculateHandlePosition(\n event: PointerEvent | MouseEvent,\n model: ModelValue\n ): number {\n const rect = this.boundingClientRect;\n const minOffset = rect.left;\n const offset = event.clientX;\n const size = rect.width;\n\n const normalized = (offset - minOffset) / size;\n const value = model.normalization.fromNormalized(\n normalized,\n model.range.min,\n model.range.max\n );\n\n /* c8 ignore next */\n return this.host.isLTR ? value : model.range.max - value;\n }\n\n public renderHandle(\n model: ModelValue,\n index: number,\n zIndex: number,\n isMultiHandle: boolean\n ): TemplateResult {\n const classes = {\n handle: true,\n dragging: this.draggingHandle?.handleName === model.name,\n 'handle-highlight': model.highlight,\n };\n const style = {\n [this.host.isLTR ? 'left' : 'right']: `${\n model.normalizedValue * 100\n }%`,\n 'z-index': zIndex.toString(),\n // Allow setting background per-handle\n 'background-color': `var(--spectrum-slider-handle-background-color-${index}, var(--spectrum-slider-handle-default-background-color))`,\n 'border-color': `var(--spectrum-slider-handle-border-color-${index}, var(-spectrum-slider-handle-default-border-color))`,\n };\n const ariaLabelledBy = isMultiHandle ? `label input-${index}` : 'label';\n return html`\n <div\n class=${classMap(classes)}\n name=${model.name}\n style=${styleMap(style)}\n role=\"presentation\"\n >\n <input\n type=\"range\"\n class=\"input\"\n id=\"input-${index}\"\n min=${model.clamp.min}\n max=${model.clamp.max}\n step=${model.step}\n value=${model.value}\n aria-disabled=${ifDefined(\n this.host.disabled ? 'true' : undefined\n )}\n tabindex=${ifDefined(this.host.editable ? -1 : undefined)}\n aria-label=${ifDefined(model.ariaLabel)}\n aria-labelledby=${ariaLabelledBy}\n aria-valuetext=${this.formattedValueForHandle(model)}\n @change=${this.onInputChange}\n @focus=${this.onInputFocus}\n @blur=${this.onInputBlur}\n @keydown=${this.onInputKeydown}\n .model=${model}\n />\n </div>\n `;\n }\n\n public render(): TemplateResult[] {\n this.clearHandleComponentCache();\n return this.model.map((model, index) => {\n const zIndex = this.handleOrder.indexOf(model.name) + 1;\n return this.renderHandle(\n model,\n index,\n zIndex,\n this.model.length > 1\n );\n });\n }\n\n /**\n * Returns a list of track segment [start, end] tuples where the values are\n * normalized to be between 0 and 1.\n * @returns A list of track segment tuples [start, end]\n */\n public trackSegments(): [number, number][] {\n const values = this.model.map((model) => model.normalizedValue);\n values.sort((a, b) => a - b);\n\n // The first segment always starts at 0\n values.unshift(0);\n return values.map((value, index, array) => [\n value,\n array[index + 1] ?? 1,\n ]);\n }\n\n private updateModel(): void {\n const handles = [...this.handles.values()];\n\n const getRangeAndClamp = (index: number): RangeAndClamp => {\n const handle = handles[index];\n const previous = handles[index - 1];\n const next = handles[index + 1];\n\n const min =\n typeof handle.min === 'number'\n ? handle.min\n : (this.host.min as number);\n const max =\n typeof handle.max === 'number'\n ? handle.max\n : (this.host.max as number);\n\n const result: RangeAndClamp = {\n range: { min: min, max: max },\n clamp: { min: min, max: max },\n };\n\n if (handle.min === 'previous') {\n if (previous) {\n for (let j = index - 1; j >= 0; j--) {\n const item = handles[j];\n if (typeof item.min === 'number') {\n result.range.min = item.min;\n break;\n }\n }\n result.clamp.min = Math.max(\n previous.value,\n result.range.min\n );\n /* c8 ignore next 5 */\n } else {\n console.warn(\n 'First slider handle cannot have attribute min=\"previous\"'\n );\n }\n }\n if (handle.max === 'next') {\n if (next) {\n for (let j = index + 1; j < handles.length; j++) {\n const item = handles[j];\n if (typeof item.max === 'number') {\n result.range.max = item.max;\n break;\n }\n }\n result.clamp.max = Math.min(next.value, result.range.max);\n /* c8 ignore next 5 */\n } else {\n console.warn(\n 'Last slider handle cannot have attribute max=\"next\"'\n );\n }\n }\n return result;\n };\n\n const modelValues = handles.map((handle, index) => {\n const rangeAndClamp = getRangeAndClamp(index);\n const { toNormalized } = handle.normalization;\n const clampedValue = Math.max(\n Math.min(handle.value, rangeAndClamp.clamp.max),\n rangeAndClamp.clamp.min\n );\n const normalizedValue = toNormalized(\n clampedValue,\n rangeAndClamp.range.min,\n rangeAndClamp.range.max\n );\n const model = {\n name: handle.handleName,\n value: clampedValue,\n normalizedValue,\n highlight: handle.highlight,\n step: handle.step ?? this.host.step,\n normalization: handle.normalization,\n handle,\n ariaLabel:\n handle !== this.host && handle?.label.length > 0\n ? handle.label\n : undefined,\n ...rangeAndClamp,\n };\n return model;\n });\n\n this.model = modelValues;\n }\n\n public async handleUpdatesComplete(): Promise<void> {\n const updates = [...this.handles.values()]\n .filter((handle) => handle !== this.host)\n .map((handle) => handle.updateComplete);\n await Promise.all(updates);\n }\n}\n"]}
|
package/src/Slider.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CSSResultArray, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import '@spectrum-web-components/field-label/sp-field-label.js';
|
|
3
|
+
import type { NumberField } from '@spectrum-web-components/number-field';
|
|
4
|
+
import { HandleController, HandleValueDictionary } from './HandleController.js';
|
|
5
|
+
import { SliderHandle } from './SliderHandle.js';
|
|
6
|
+
export declare const variants: string[];
|
|
7
|
+
declare const Slider_base: typeof SliderHandle & {
|
|
8
|
+
new (...args: any[]): import("@spectrum-web-components/shared/src/observe-slot-text.js").SlotTextObservingInterface;
|
|
9
|
+
prototype: import("@spectrum-web-components/shared/src/observe-slot-text.js").SlotTextObservingInterface;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @element sp-slider
|
|
13
|
+
*
|
|
14
|
+
* @slot - text label for the Slider
|
|
15
|
+
*/
|
|
16
|
+
export declare class Slider extends Slider_base {
|
|
17
|
+
static get styles(): CSSResultArray;
|
|
18
|
+
handleController: HandleController;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to display a Number Field along side the slider UI
|
|
21
|
+
*/
|
|
22
|
+
get editable(): boolean;
|
|
23
|
+
set editable(editable: boolean);
|
|
24
|
+
private _editable;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the stepper UI of the Number Field is hidden or not
|
|
27
|
+
*/
|
|
28
|
+
hideStepper: boolean;
|
|
29
|
+
type: string;
|
|
30
|
+
set variant(variant: string);
|
|
31
|
+
get variant(): string;
|
|
32
|
+
get values(): HandleValueDictionary;
|
|
33
|
+
get handleName(): string;
|
|
34
|
+
private _variant;
|
|
35
|
+
getAriaValueText: (values: Map<string, string>) => string;
|
|
36
|
+
get ariaValueText(): string;
|
|
37
|
+
labelVisibility?: 'text' | 'value' | 'none';
|
|
38
|
+
min: number;
|
|
39
|
+
max: number;
|
|
40
|
+
step: number;
|
|
41
|
+
tickStep: number;
|
|
42
|
+
tickLabels: boolean;
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
labelEl: HTMLLabelElement;
|
|
45
|
+
numberField: NumberField;
|
|
46
|
+
track: HTMLDivElement;
|
|
47
|
+
get numberFormat(): Intl.NumberFormat;
|
|
48
|
+
get focusElement(): HTMLElement;
|
|
49
|
+
protected handleLabelClick(event: Event): void;
|
|
50
|
+
protected render(): TemplateResult;
|
|
51
|
+
connectedCallback(): void;
|
|
52
|
+
disconnectedCallback(): void;
|
|
53
|
+
update(changedProperties: Map<string, boolean>): void;
|
|
54
|
+
private renderLabel;
|
|
55
|
+
private renderRamp;
|
|
56
|
+
private renderTicks;
|
|
57
|
+
private renderTrackSegment;
|
|
58
|
+
private renderTrack;
|
|
59
|
+
protected handlePointerdown(event: PointerEvent): void;
|
|
60
|
+
protected handlePointermove(event: PointerEvent): void;
|
|
61
|
+
protected handlePointerup(event: PointerEvent): void;
|
|
62
|
+
private handleNumberInput;
|
|
63
|
+
private handleNumberChange;
|
|
64
|
+
private trackSegmentStyles;
|
|
65
|
+
private _numberFieldInput;
|
|
66
|
+
protected getUpdateComplete(): Promise<boolean>;
|
|
67
|
+
}
|
|
68
|
+
export {};
|