@spectrum-web-components/slider 0.12.14 → 0.12.15-devmode.0
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 +40 -15
- package/sp-slider-handle.dev.js +3 -0
- package/sp-slider-handle.dev.js.map +7 -0
- package/sp-slider-handle.js +3 -14
- package/sp-slider-handle.js.map +7 -1
- package/sp-slider.dev.js +4 -0
- package/sp-slider.dev.js.map +7 -0
- package/sp-slider.js +4 -15
- package/sp-slider.js.map +7 -1
- package/src/HandleController.dev.js +434 -0
- package/src/HandleController.dev.js.map +7 -0
- package/src/HandleController.js +402 -453
- package/src/HandleController.js.map +7 -1
- package/src/Slider.dev.js +367 -0
- package/src/Slider.dev.js.map +7 -0
- package/src/Slider.js +280 -304
- package/src/Slider.js.map +7 -1
- package/src/SliderHandle.dev.js +184 -0
- package/src/SliderHandle.dev.js.map +7 -0
- package/src/SliderHandle.js +171 -179
- package/src/SliderHandle.js.map +7 -1
- package/src/index.dev.js +4 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +4 -15
- package/src/index.js.map +7 -1
- package/src/slider.css.dev.js +234 -0
- package/src/slider.css.dev.js.map +7 -0
- package/src/slider.css.js +3 -14
- package/src/slider.css.js.map +7 -1
- package/src/spectrum-slider.css.dev.js +216 -0
- package/src/spectrum-slider.css.dev.js.map +7 -0
- package/src/spectrum-slider.css.js +3 -14
- package/src/spectrum-slider.css.js.map +7 -1
- package/stories/slider.stories.js +224 -269
- package/stories/slider.stories.js.map +7 -1
- package/sync/sp-slider.dev.js +3 -0
- package/sync/sp-slider.dev.js.map +7 -0
- package/sync/sp-slider.js +3 -14
- package/sync/sp-slider.js.map +7 -1
- package/test/benchmark/test-basic.js +5 -16
- package/test/benchmark/test-basic.js.map +7 -1
- package/test/slider-editable-sync.test.js +132 -144
- package/test/slider-editable-sync.test.js.map +7 -1
- package/test/slider-editable.test.js +151 -159
- package/test/slider-editable.test.js.map +7 -1
- package/test/slider-handle-upgrade.test.js +10 -21
- package/test/slider-handle-upgrade.test.js.map +7 -1
- package/test/slider.test-vrt.js +4 -15
- package/test/slider.test-vrt.js.map +7 -1
- package/test/slider.test.js +686 -700
- package/test/slider.test.js.map +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/slider",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.15-devmode.0+07474d44f",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,15 +20,40 @@
|
|
|
20
20
|
"module": "./src/index.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
26
|
-
"./
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"./
|
|
31
|
-
|
|
28
|
+
"./src/HandleController.js": {
|
|
29
|
+
"development": "./src/HandleController.dev.js",
|
|
30
|
+
"default": "./src/HandleController.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/Slider.js": {
|
|
33
|
+
"development": "./src/Slider.dev.js",
|
|
34
|
+
"default": "./src/Slider.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/SliderHandle.js": {
|
|
37
|
+
"development": "./src/SliderHandle.dev.js",
|
|
38
|
+
"default": "./src/SliderHandle.js"
|
|
39
|
+
},
|
|
40
|
+
"./src/index.js": {
|
|
41
|
+
"development": "./src/index.dev.js",
|
|
42
|
+
"default": "./src/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./src/slider.css.js": "./src/slider.css.js",
|
|
45
|
+
"./sp-slider.js": {
|
|
46
|
+
"development": "./sp-slider.dev.js",
|
|
47
|
+
"default": "./sp-slider.js"
|
|
48
|
+
},
|
|
49
|
+
"./sp-slider-handle.js": {
|
|
50
|
+
"development": "./sp-slider-handle.dev.js",
|
|
51
|
+
"default": "./sp-slider-handle.js"
|
|
52
|
+
},
|
|
53
|
+
"./sync/sp-slider.js": {
|
|
54
|
+
"development": "./sync/sp-slider.dev.js",
|
|
55
|
+
"default": "./sync/sp-slider.js"
|
|
56
|
+
}
|
|
32
57
|
},
|
|
33
58
|
"scripts": {
|
|
34
59
|
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
@@ -50,11 +75,11 @@
|
|
|
50
75
|
"dependencies": {
|
|
51
76
|
"@internationalized/number": "^3.1.0",
|
|
52
77
|
"@lit-labs/observers": "^1.0.1",
|
|
53
|
-
"@spectrum-web-components/base": "^0.5.
|
|
54
|
-
"@spectrum-web-components/field-label": "^0.7.
|
|
55
|
-
"@spectrum-web-components/number-field": "^0.4.0",
|
|
56
|
-
"@spectrum-web-components/shared": "^0.14.
|
|
57
|
-
"@spectrum-web-components/theme": "^0.12.0",
|
|
78
|
+
"@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
|
|
79
|
+
"@spectrum-web-components/field-label": "^0.7.14-devmode.0+07474d44f",
|
|
80
|
+
"@spectrum-web-components/number-field": "^0.4.1-devmode.0+07474d44f",
|
|
81
|
+
"@spectrum-web-components/shared": "^0.14.5-devmode.0+07474d44f",
|
|
82
|
+
"@spectrum-web-components/theme": "^0.12.1-devmode.0+07474d44f",
|
|
58
83
|
"tslib": "^2.0.0"
|
|
59
84
|
},
|
|
60
85
|
"devDependencies": {
|
|
@@ -66,5 +91,5 @@
|
|
|
66
91
|
"./sp-*.js",
|
|
67
92
|
"./sync/sp-*.js"
|
|
68
93
|
],
|
|
69
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
|
|
70
95
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-slider-handle.ts"],
|
|
4
|
+
"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 { SliderHandle } from './src/SliderHandle.dev.js'\n\ncustomElements.define('sp-slider-handle', SliderHandle);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-slider-handle': SliderHandle;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,eAAe,OAAO,oBAAoB,YAAY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-slider-handle.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { SliderHandle } from './src/SliderHandle.js';
|
|
13
|
-
customElements.define('sp-slider-handle', SliderHandle);
|
|
14
|
-
//# sourceMappingURL=sp-slider-handle.js.map
|
|
1
|
+
import { SliderHandle } from "./src/SliderHandle.js";
|
|
2
|
+
customElements.define("sp-slider-handle", SliderHandle);
|
|
3
|
+
//# sourceMappingURL=sp-slider-handle.js.map
|
package/sp-slider-handle.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-slider-handle.ts"],
|
|
4
|
+
"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 { SliderHandle } from './src/SliderHandle.js';\n\ncustomElements.define('sp-slider-handle', SliderHandle);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-slider-handle': SliderHandle;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,eAAe,OAAO,oBAAoB,YAAY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-slider.dev.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-slider.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 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 './sp-slider-handle.dev.js' // codify sp-slider's implicit dependency on sp-slider-handle\nimport { Slider } from './src/Slider.dev.js'\n\ncustomElements.define('sp-slider', Slider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-slider': Slider;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AACA;AAEA,eAAe,OAAO,aAAa,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-slider.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 './sp-slider-handle.js'; // codify sp-slider's implicit dependency on sp-slider-handle
|
|
13
|
-
import { Slider } from './src/Slider.js';
|
|
14
|
-
customElements.define('sp-slider', Slider);
|
|
15
|
-
//# sourceMappingURL=sp-slider.js.map
|
|
1
|
+
import "./sp-slider-handle.js";
|
|
2
|
+
import { Slider } from "./src/Slider.js";
|
|
3
|
+
customElements.define("sp-slider", Slider);
|
|
4
|
+
//# sourceMappingURL=sp-slider.js.map
|
package/sp-slider.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-slider.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 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 './sp-slider-handle.js'; // codify sp-slider's implicit dependency on sp-slider-handle\nimport { Slider } from './src/Slider.js';\n\ncustomElements.define('sp-slider', Slider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-slider': Slider;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AACA;AAEA,eAAe,OAAO,aAAa,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { html } from "@spectrum-web-components/base";
|
|
2
|
+
import {
|
|
3
|
+
classMap,
|
|
4
|
+
ifDefined,
|
|
5
|
+
styleMap
|
|
6
|
+
} from "@spectrum-web-components/base/src/directives.js";
|
|
7
|
+
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
8
|
+
import {
|
|
9
|
+
SliderHandle
|
|
10
|
+
} from "./SliderHandle.dev.js";
|
|
11
|
+
export class HandleController {
|
|
12
|
+
constructor(host) {
|
|
13
|
+
this.handles = /* @__PURE__ */ new Map();
|
|
14
|
+
this.model = [];
|
|
15
|
+
this.handleOrder = [];
|
|
16
|
+
this.handleOrientation = () => {
|
|
17
|
+
this.updateBoundingRect();
|
|
18
|
+
};
|
|
19
|
+
this.extractModelFromLightDom = () => {
|
|
20
|
+
let handles = [
|
|
21
|
+
...this.host.querySelectorAll('[slot="handle"]')
|
|
22
|
+
];
|
|
23
|
+
if (handles.length === 0) {
|
|
24
|
+
handles = [this.host];
|
|
25
|
+
}
|
|
26
|
+
if (handles.some((h) => this.waitForUpgrade(h))) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.handles = /* @__PURE__ */ new Map();
|
|
30
|
+
this.handleOrder = [];
|
|
31
|
+
handles.forEach((handle, index) => {
|
|
32
|
+
var _a;
|
|
33
|
+
if (!((_a = handle.handleName) == null ? void 0 : _a.length)) {
|
|
34
|
+
handle.name = `handle${index + 1}`;
|
|
35
|
+
}
|
|
36
|
+
this.handles.set(handle.handleName, handle);
|
|
37
|
+
this.handleOrder.push(handle.handleName);
|
|
38
|
+
handle.handleController = this;
|
|
39
|
+
});
|
|
40
|
+
this.requestUpdate();
|
|
41
|
+
};
|
|
42
|
+
this.onInputChange = (event) => {
|
|
43
|
+
const input = event.target;
|
|
44
|
+
input.model.handle.value = input.valueAsNumber;
|
|
45
|
+
this.requestUpdate();
|
|
46
|
+
this.dispatchChangeEvent(input, input.model.handle);
|
|
47
|
+
};
|
|
48
|
+
this.onInputFocus = (event) => {
|
|
49
|
+
const input = event.target;
|
|
50
|
+
let isFocusVisible;
|
|
51
|
+
try {
|
|
52
|
+
isFocusVisible = input.matches(":focus-visible") || this.host.matches(".focus-visible");
|
|
53
|
+
} catch (error) {
|
|
54
|
+
isFocusVisible = this.host.matches(".focus-visible");
|
|
55
|
+
}
|
|
56
|
+
input.model.handle.highlight = isFocusVisible;
|
|
57
|
+
this.requestUpdate();
|
|
58
|
+
};
|
|
59
|
+
this.onInputBlur = (event) => {
|
|
60
|
+
const input = event.target;
|
|
61
|
+
input.model.handle.highlight = false;
|
|
62
|
+
this.requestUpdate();
|
|
63
|
+
};
|
|
64
|
+
this.onInputKeydown = (event) => {
|
|
65
|
+
const input = event.target;
|
|
66
|
+
input.model.handle.highlight = true;
|
|
67
|
+
this.requestUpdate();
|
|
68
|
+
};
|
|
69
|
+
this.host = host;
|
|
70
|
+
new MutationController(this.host, {
|
|
71
|
+
config: {
|
|
72
|
+
subtree: true,
|
|
73
|
+
childList: true
|
|
74
|
+
},
|
|
75
|
+
callback: () => {
|
|
76
|
+
this.extractModelFromLightDom();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.extractModelFromLightDom();
|
|
80
|
+
}
|
|
81
|
+
get values() {
|
|
82
|
+
const result = {};
|
|
83
|
+
for (const model of this.handles.values()) {
|
|
84
|
+
result[model.handleName] = model.value;
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
get size() {
|
|
89
|
+
return this.handles.size;
|
|
90
|
+
}
|
|
91
|
+
inputForHandle(handle) {
|
|
92
|
+
if (this.handles.has(handle.handleName)) {
|
|
93
|
+
const { input } = this.getHandleElements(handle);
|
|
94
|
+
return input;
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`No input for handle "${handle.name}"`);
|
|
97
|
+
}
|
|
98
|
+
requestUpdate() {
|
|
99
|
+
if (this.host.hasUpdated) {
|
|
100
|
+
this.host.requestUpdate();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
setValueFromHandle(handle) {
|
|
104
|
+
const elements = this.getHandleElements(handle);
|
|
105
|
+
if (!elements)
|
|
106
|
+
return;
|
|
107
|
+
const { input } = elements;
|
|
108
|
+
if (input.valueAsNumber === handle.value) {
|
|
109
|
+
if (handle.dragging) {
|
|
110
|
+
handle.dispatchInputEvent();
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
input.valueAsNumber = handle.value;
|
|
114
|
+
this.requestUpdate();
|
|
115
|
+
}
|
|
116
|
+
handle.value = input.valueAsNumber;
|
|
117
|
+
}
|
|
118
|
+
handleHasChanged(handle) {
|
|
119
|
+
if (handle !== this.host) {
|
|
120
|
+
this.requestUpdate();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
formattedValueForHandle(model) {
|
|
124
|
+
var _a;
|
|
125
|
+
const { handle } = model;
|
|
126
|
+
const numberFormat = (_a = handle.numberFormat) != null ? _a : this.host.numberFormat;
|
|
127
|
+
return handle.getAriaHandleText(model.value, numberFormat);
|
|
128
|
+
}
|
|
129
|
+
get formattedValues() {
|
|
130
|
+
const result = /* @__PURE__ */ new Map();
|
|
131
|
+
for (const model of this.model) {
|
|
132
|
+
result.set(model.name, this.formattedValueForHandle(model));
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
get focusElement() {
|
|
137
|
+
const { input } = this.getActiveHandleElements();
|
|
138
|
+
if (this.host.editable && !input.model.handle.dragging) {
|
|
139
|
+
return this.host.numberField;
|
|
140
|
+
}
|
|
141
|
+
return input;
|
|
142
|
+
}
|
|
143
|
+
hostConnected() {
|
|
144
|
+
if ("orientation" in screen) {
|
|
145
|
+
screen.orientation.addEventListener("change", this.handleOrientation);
|
|
146
|
+
} else {
|
|
147
|
+
window.addEventListener("orientationchange", this.handleOrientation);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
hostDisconnected() {
|
|
151
|
+
if ("orientation" in screen) {
|
|
152
|
+
screen.orientation.removeEventListener("change", this.handleOrientation);
|
|
153
|
+
} else {
|
|
154
|
+
window.removeEventListener("orientationchange", this.handleOrientation);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
hostUpdate() {
|
|
158
|
+
this.updateModel();
|
|
159
|
+
}
|
|
160
|
+
waitForUpgrade(handle) {
|
|
161
|
+
if (handle instanceof SliderHandle) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
handle.addEventListener("sp-slider-handle-ready", () => this.extractModelFromLightDom(), { once: true, passive: true });
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
get activeHandle() {
|
|
168
|
+
return this.handleOrder[this.handleOrder.length - 1];
|
|
169
|
+
}
|
|
170
|
+
get activeHandleInputId() {
|
|
171
|
+
const active = this.activeHandle;
|
|
172
|
+
const index = this.model.findIndex((model) => model.name === active);
|
|
173
|
+
return `input-${index}`;
|
|
174
|
+
}
|
|
175
|
+
activateHandle(name) {
|
|
176
|
+
const index = this.handleOrder.findIndex((item) => item === name);
|
|
177
|
+
if (index >= 0) {
|
|
178
|
+
this.handleOrder.splice(index, 1);
|
|
179
|
+
}
|
|
180
|
+
this.handleOrder.push(name);
|
|
181
|
+
}
|
|
182
|
+
getActiveHandleElements() {
|
|
183
|
+
const name = this.activeHandle;
|
|
184
|
+
const handleSlider = this.handles.get(name);
|
|
185
|
+
const elements = this.getHandleElements(handleSlider);
|
|
186
|
+
return { model: handleSlider, ...elements };
|
|
187
|
+
}
|
|
188
|
+
getHandleElements(sliderHandle) {
|
|
189
|
+
if (!this.handleRefMap) {
|
|
190
|
+
this.handleRefMap = /* @__PURE__ */ new WeakMap();
|
|
191
|
+
const inputNodes = this.host.shadowRoot.querySelectorAll(".handle > input");
|
|
192
|
+
for (const inputNode of inputNodes) {
|
|
193
|
+
const input = inputNode;
|
|
194
|
+
const handle = input.parentElement;
|
|
195
|
+
const model = this.handles.get(handle.getAttribute("name"));
|
|
196
|
+
if (model) {
|
|
197
|
+
this.handleRefMap.set(model, { input, handle });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const components = this.handleRefMap.get(sliderHandle);
|
|
202
|
+
return components;
|
|
203
|
+
}
|
|
204
|
+
clearHandleComponentCache() {
|
|
205
|
+
delete this.handleRefMap;
|
|
206
|
+
}
|
|
207
|
+
get boundingClientRect() {
|
|
208
|
+
if (!this._boundingClientRect) {
|
|
209
|
+
this._boundingClientRect = this.host.track.getBoundingClientRect();
|
|
210
|
+
}
|
|
211
|
+
return this._boundingClientRect;
|
|
212
|
+
}
|
|
213
|
+
updateBoundingRect() {
|
|
214
|
+
delete this._boundingClientRect;
|
|
215
|
+
}
|
|
216
|
+
extractDataFromEvent(event) {
|
|
217
|
+
if (!this._activePointerEventData) {
|
|
218
|
+
let input = event.target.querySelector(":scope > .input");
|
|
219
|
+
const resolvedInput = !input;
|
|
220
|
+
const model = input ? input.model : this.model.find((item) => item.name === this.activeHandle);
|
|
221
|
+
if (!input && !!model) {
|
|
222
|
+
input = model.handle.focusElement;
|
|
223
|
+
}
|
|
224
|
+
this._activePointerEventData = {
|
|
225
|
+
input,
|
|
226
|
+
model,
|
|
227
|
+
resolvedInput
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return this._activePointerEventData;
|
|
231
|
+
}
|
|
232
|
+
handlePointerdown(event) {
|
|
233
|
+
const { resolvedInput, model } = this.extractDataFromEvent(event);
|
|
234
|
+
if (!model || this.host.disabled || event.button !== 0) {
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this.host.track.setPointerCapture(event.pointerId);
|
|
239
|
+
this.updateBoundingRect();
|
|
240
|
+
this.host.labelEl.click();
|
|
241
|
+
this.draggingHandle = model.handle;
|
|
242
|
+
model.handle.dragging = true;
|
|
243
|
+
this.activateHandle(model.name);
|
|
244
|
+
if (resolvedInput) {
|
|
245
|
+
this.handlePointermove(event);
|
|
246
|
+
}
|
|
247
|
+
this.requestUpdate();
|
|
248
|
+
}
|
|
249
|
+
handlePointerup(event) {
|
|
250
|
+
const { input, model } = this.extractDataFromEvent(event);
|
|
251
|
+
delete this._activePointerEventData;
|
|
252
|
+
if (!model)
|
|
253
|
+
return;
|
|
254
|
+
this.host.labelEl.click();
|
|
255
|
+
this.cancelDrag(model);
|
|
256
|
+
this.requestUpdate();
|
|
257
|
+
this.host.track.releasePointerCapture(event.pointerId);
|
|
258
|
+
this.dispatchChangeEvent(input, model.handle);
|
|
259
|
+
}
|
|
260
|
+
handlePointermove(event) {
|
|
261
|
+
const { input, model } = this.extractDataFromEvent(event);
|
|
262
|
+
if (!model)
|
|
263
|
+
return;
|
|
264
|
+
if (!this.draggingHandle) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
event.stopPropagation();
|
|
268
|
+
input.value = this.calculateHandlePosition(event, model).toString();
|
|
269
|
+
model.handle.value = parseFloat(input.value);
|
|
270
|
+
this.host.indeterminate = false;
|
|
271
|
+
this.requestUpdate();
|
|
272
|
+
}
|
|
273
|
+
cancelDrag(model) {
|
|
274
|
+
model = model || this.model.find((item) => item.name === this.activeHandle);
|
|
275
|
+
if (!model)
|
|
276
|
+
return;
|
|
277
|
+
model.handle.highlight = false;
|
|
278
|
+
delete this.draggingHandle;
|
|
279
|
+
model.handle.dragging = false;
|
|
280
|
+
}
|
|
281
|
+
dispatchChangeEvent(input, handle) {
|
|
282
|
+
input.valueAsNumber = handle.value;
|
|
283
|
+
const changeEvent = new Event("change", {
|
|
284
|
+
bubbles: true,
|
|
285
|
+
composed: true
|
|
286
|
+
});
|
|
287
|
+
handle.dispatchEvent(changeEvent);
|
|
288
|
+
}
|
|
289
|
+
calculateHandlePosition(event, model) {
|
|
290
|
+
const rect = this.boundingClientRect;
|
|
291
|
+
const minOffset = rect.left;
|
|
292
|
+
const offset = event.clientX;
|
|
293
|
+
const size = rect.width;
|
|
294
|
+
const directionalOffset = this.host.isLTR ? offset - minOffset : size - (offset - minOffset);
|
|
295
|
+
const normalized = directionalOffset / size;
|
|
296
|
+
return model.normalization.fromNormalized(normalized, model.range.min, model.range.max);
|
|
297
|
+
}
|
|
298
|
+
renderHandle(model, index, zIndex, isMultiHandle) {
|
|
299
|
+
var _a;
|
|
300
|
+
const classes = {
|
|
301
|
+
handle: true,
|
|
302
|
+
dragging: ((_a = this.draggingHandle) == null ? void 0 : _a.handleName) === model.name,
|
|
303
|
+
"handle-highlight": model.highlight
|
|
304
|
+
};
|
|
305
|
+
const style = {
|
|
306
|
+
[this.host.isLTR ? "left" : "right"]: `${model.normalizedValue * 100}%`,
|
|
307
|
+
"z-index": zIndex.toString(),
|
|
308
|
+
"background-color": `var(--spectrum-slider-handle-background-color-${index}, var(--spectrum-slider-handle-default-background-color))`,
|
|
309
|
+
"border-color": `var(--spectrum-slider-handle-border-color-${index}, var(-spectrum-slider-handle-default-border-color))`
|
|
310
|
+
};
|
|
311
|
+
const ariaLabelledBy = isMultiHandle ? `label input-${index}` : "label";
|
|
312
|
+
return html`
|
|
313
|
+
<div
|
|
314
|
+
class=${classMap(classes)}
|
|
315
|
+
name=${model.name}
|
|
316
|
+
style=${styleMap(style)}
|
|
317
|
+
role="presentation"
|
|
318
|
+
>
|
|
319
|
+
<input
|
|
320
|
+
type="range"
|
|
321
|
+
class="input"
|
|
322
|
+
id="input-${index}"
|
|
323
|
+
min=${model.clamp.min}
|
|
324
|
+
max=${model.clamp.max}
|
|
325
|
+
step=${model.step}
|
|
326
|
+
value=${model.value}
|
|
327
|
+
aria-disabled=${ifDefined(this.host.disabled ? "true" : void 0)}
|
|
328
|
+
tabindex=${ifDefined(this.host.editable ? -1 : void 0)}
|
|
329
|
+
aria-label=${ifDefined(model.ariaLabel)}
|
|
330
|
+
aria-labelledby=${ariaLabelledBy}
|
|
331
|
+
aria-valuetext=${this.formattedValueForHandle(model)}
|
|
332
|
+
@change=${this.onInputChange}
|
|
333
|
+
@focus=${this.onInputFocus}
|
|
334
|
+
@blur=${this.onInputBlur}
|
|
335
|
+
@keydown=${this.onInputKeydown}
|
|
336
|
+
.model=${model}
|
|
337
|
+
/>
|
|
338
|
+
</div>
|
|
339
|
+
`;
|
|
340
|
+
}
|
|
341
|
+
render() {
|
|
342
|
+
this.clearHandleComponentCache();
|
|
343
|
+
return this.model.map((model, index) => {
|
|
344
|
+
const zIndex = this.handleOrder.indexOf(model.name) + 1;
|
|
345
|
+
return this.renderHandle(model, index, zIndex, this.model.length > 1);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
trackSegments() {
|
|
349
|
+
const values = this.model.map((model) => model.normalizedValue);
|
|
350
|
+
values.sort((a, b) => a - b);
|
|
351
|
+
values.unshift(0);
|
|
352
|
+
return values.map((value, index, array) => {
|
|
353
|
+
var _a;
|
|
354
|
+
return [
|
|
355
|
+
value,
|
|
356
|
+
(_a = array[index + 1]) != null ? _a : 1
|
|
357
|
+
];
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
updateModel() {
|
|
361
|
+
const handles = [...this.handles.values()];
|
|
362
|
+
const getRangeAndClamp = (index) => {
|
|
363
|
+
const handle = handles[index];
|
|
364
|
+
const previous = handles[index - 1];
|
|
365
|
+
const next = handles[index + 1];
|
|
366
|
+
const min = typeof handle.min === "number" ? handle.min : this.host.min;
|
|
367
|
+
const max = typeof handle.max === "number" ? handle.max : this.host.max;
|
|
368
|
+
const result = {
|
|
369
|
+
range: { min, max },
|
|
370
|
+
clamp: { min, max }
|
|
371
|
+
};
|
|
372
|
+
if (handle.min === "previous") {
|
|
373
|
+
if (previous) {
|
|
374
|
+
for (let j = index - 1; j >= 0; j--) {
|
|
375
|
+
const item = handles[j];
|
|
376
|
+
if (typeof item.min === "number") {
|
|
377
|
+
result.range.min = item.min;
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
result.clamp.min = Math.max(previous.value, result.range.min);
|
|
382
|
+
}
|
|
383
|
+
if (true) {
|
|
384
|
+
if (!previous) {
|
|
385
|
+
window.__swc.issueWarning("slider:api:default", 'First slider handle cannot have attribute min="previous"', "https://opensource.adobe.com/spectrum-web-components/components/slider-handle/#multi-handle-slider-with-ordered-handles");
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (handle.max === "next") {
|
|
390
|
+
if (next) {
|
|
391
|
+
for (let j = index + 1; j < handles.length; j++) {
|
|
392
|
+
const item = handles[j];
|
|
393
|
+
if (typeof item.max === "number") {
|
|
394
|
+
result.range.max = item.max;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
result.clamp.max = Math.min(next.value, result.range.max);
|
|
399
|
+
}
|
|
400
|
+
if (true) {
|
|
401
|
+
if (!next) {
|
|
402
|
+
window.__swc.issueWarning("slider:api:default", 'Last slider handle cannot have attribute max="next"', "This needs a URL!");
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
};
|
|
408
|
+
const modelValues = handles.map((handle, index) => {
|
|
409
|
+
var _a;
|
|
410
|
+
const rangeAndClamp = getRangeAndClamp(index);
|
|
411
|
+
const { toNormalized } = handle.normalization;
|
|
412
|
+
const clampedValue = Math.max(Math.min(handle.value, rangeAndClamp.clamp.max), rangeAndClamp.clamp.min);
|
|
413
|
+
const normalizedValue = toNormalized(clampedValue, rangeAndClamp.range.min, rangeAndClamp.range.max);
|
|
414
|
+
const model = {
|
|
415
|
+
name: handle.handleName,
|
|
416
|
+
value: clampedValue,
|
|
417
|
+
normalizedValue,
|
|
418
|
+
highlight: handle.highlight,
|
|
419
|
+
step: (_a = handle.step) != null ? _a : this.host.step,
|
|
420
|
+
normalization: handle.normalization,
|
|
421
|
+
handle,
|
|
422
|
+
ariaLabel: handle !== this.host && (handle == null ? void 0 : handle.label.length) > 0 ? handle.label : void 0,
|
|
423
|
+
...rangeAndClamp
|
|
424
|
+
};
|
|
425
|
+
return model;
|
|
426
|
+
});
|
|
427
|
+
this.model = modelValues;
|
|
428
|
+
}
|
|
429
|
+
async handleUpdatesComplete() {
|
|
430
|
+
const updates = [...this.handles.values()].filter((handle) => handle !== this.host).map((handle) => handle.updateComplete);
|
|
431
|
+
await Promise.all(updates);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=HandleController.dev.js.map
|