@spectrum-web-components/picker 0.13.0-devmode.0 → 0.13.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 +13 -13
- package/sp-picker.js +1 -2
- package/sp-picker.js.map +1 -1
- package/src/Picker.js +17 -442
- package/src/Picker.js.map +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/picker.css.js +2 -4
- package/src/picker.css.js.map +1 -1
- package/src/spectrum-picker.css.js +2 -4
- package/src/spectrum-picker.css.js.map +1 -1
- package/stories/picker-sizes.stories.js +6 -29
- package/stories/picker-sizes.stories.js.map +1 -1
- package/stories/picker.stories.js +38 -155
- package/stories/picker.stories.js.map +1 -1
- package/stories/states.js +1 -226
- package/stories/states.js.map +1 -1
- package/sync/index.js +1 -7
- package/sync/index.js.map +1 -1
- package/sync/sp-picker.js +1 -2
- package/sync/sp-picker.js.map +1 -1
- package/test/benchmark/basic-test.js +4 -259
- package/test/benchmark/basic-test.js.map +1 -1
- package/test/index.js +14 -895
- package/test/index.js.map +1 -1
- package/test/picker-reparenting.test.js +2 -74
- package/test/picker-reparenting.test.js.map +1 -1
- package/test/picker-responsive.test.js +2 -43
- package/test/picker-responsive.test.js.map +1 -1
- package/test/picker-sizes.test-vrt.js +1 -3
- package/test/picker-sizes.test-vrt.js.map +1 -1
- package/test/picker-sync.test.js +1 -5
- package/test/picker-sync.test.js.map +1 -1
- package/test/picker.test-vrt.js +1 -3
- package/test/picker.test-vrt.js.map +1 -1
- package/test/picker.test.js +1 -5
- package/test/picker.test.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/picker",
|
|
3
|
-
"version": "0.13.0
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -65,17 +65,17 @@
|
|
|
65
65
|
"lit-html"
|
|
66
66
|
],
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@spectrum-web-components/base": "^0.
|
|
69
|
-
"@spectrum-web-components/button": "^0.19.0
|
|
70
|
-
"@spectrum-web-components/icon": "^0.12.0
|
|
71
|
-
"@spectrum-web-components/icons-ui": "^0.9.0
|
|
72
|
-
"@spectrum-web-components/icons-workflow": "^0.9.0
|
|
73
|
-
"@spectrum-web-components/menu": "^0.16.0
|
|
74
|
-
"@spectrum-web-components/overlay": "^0.18.0
|
|
75
|
-
"@spectrum-web-components/popover": "^0.12.0
|
|
76
|
-
"@spectrum-web-components/reactive-controllers": "^0.
|
|
77
|
-
"@spectrum-web-components/shared": "^0.15.0
|
|
78
|
-
"@spectrum-web-components/tray": "^0.4.0
|
|
68
|
+
"@spectrum-web-components/base": "^0.7.0",
|
|
69
|
+
"@spectrum-web-components/button": "^0.19.0",
|
|
70
|
+
"@spectrum-web-components/icon": "^0.12.0",
|
|
71
|
+
"@spectrum-web-components/icons-ui": "^0.9.0",
|
|
72
|
+
"@spectrum-web-components/icons-workflow": "^0.9.0",
|
|
73
|
+
"@spectrum-web-components/menu": "^0.16.0",
|
|
74
|
+
"@spectrum-web-components/overlay": "^0.18.0",
|
|
75
|
+
"@spectrum-web-components/popover": "^0.12.0",
|
|
76
|
+
"@spectrum-web-components/reactive-controllers": "^0.3.0",
|
|
77
|
+
"@spectrum-web-components/shared": "^0.15.0",
|
|
78
|
+
"@spectrum-web-components/tray": "^0.4.0",
|
|
79
79
|
"tslib": "^2.0.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"./sync/index.js",
|
|
90
90
|
"./sync/sp-*.js"
|
|
91
91
|
],
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "05c81318844160db3f8156144106e643507fef97"
|
|
93
93
|
}
|
package/sp-picker.js
CHANGED
package/sp-picker.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-picker.ts"],
|
|
4
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*/\n\nimport { Picker } from './src/Picker.js';\n\ncustomElements.define('sp-picker', Picker);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-picker': Picker;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAYA
|
|
5
|
+
"mappings": "AAYA,yCAEA,eAAe,OAAO,YAAa,CAAM",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/Picker.js
CHANGED
|
@@ -1,277 +1,29 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result)
|
|
9
|
-
__defProp(target, key, result);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
import {
|
|
13
|
-
html,
|
|
14
|
-
nothing,
|
|
15
|
-
render,
|
|
16
|
-
SizedMixin
|
|
17
|
-
} from "@spectrum-web-components/base";
|
|
18
|
-
import { classMap } from "@spectrum-web-components/base/src/directives.js";
|
|
19
|
-
import {
|
|
20
|
-
property,
|
|
21
|
-
query
|
|
22
|
-
} from "@spectrum-web-components/base/src/decorators.js";
|
|
23
|
-
import pickerStyles from "./picker.css.js";
|
|
24
|
-
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
25
|
-
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
26
|
-
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
27
|
-
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
28
|
-
import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
|
|
29
|
-
import "@spectrum-web-components/menu/sp-menu.js";
|
|
30
|
-
import "@spectrum-web-components/tray/sp-tray.js";
|
|
31
|
-
import "@spectrum-web-components/popover/sp-popover.js";
|
|
32
|
-
import {
|
|
33
|
-
openOverlay
|
|
34
|
-
} from "@spectrum-web-components/overlay";
|
|
35
|
-
import {
|
|
36
|
-
IS_MOBILE,
|
|
37
|
-
MatchMediaController
|
|
38
|
-
} from "@spectrum-web-components/reactive-controllers/src/MatchMedia.js";
|
|
39
|
-
const chevronClass = {
|
|
40
|
-
s: "spectrum-UIIcon-ChevronDown75",
|
|
41
|
-
m: "spectrum-UIIcon-ChevronDown100",
|
|
42
|
-
l: "spectrum-UIIcon-ChevronDown200",
|
|
43
|
-
xl: "spectrum-UIIcon-ChevronDown300"
|
|
44
|
-
};
|
|
45
|
-
export class PickerBase extends SizedMixin(Focusable) {
|
|
46
|
-
constructor() {
|
|
47
|
-
super();
|
|
48
|
-
this.isMobile = new MatchMediaController(this, IS_MOBILE);
|
|
49
|
-
this.disabled = false;
|
|
50
|
-
this.focused = false;
|
|
51
|
-
this.invalid = false;
|
|
52
|
-
this.open = false;
|
|
53
|
-
this.readonly = false;
|
|
54
|
-
this.selects = "single";
|
|
55
|
-
this.menuItems = [];
|
|
56
|
-
this.placement = "bottom-start";
|
|
57
|
-
this.quiet = false;
|
|
58
|
-
this.value = "";
|
|
59
|
-
this.listRole = "listbox";
|
|
60
|
-
this.itemRole = "option";
|
|
61
|
-
this.onKeydown = (event) => {
|
|
62
|
-
this.focused = true;
|
|
63
|
-
if (event.code !== "ArrowDown" && event.code !== "ArrowUp") {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
event.preventDefault();
|
|
67
|
-
this.toggle(true);
|
|
68
|
-
};
|
|
69
|
-
this.overlayOpenCallback = async () => {
|
|
70
|
-
this.updateMenuItems();
|
|
71
|
-
await this.itemsUpdated;
|
|
72
|
-
await this.optionsMenu.updateComplete;
|
|
73
|
-
requestAnimationFrame(() => this.menuStateResolver());
|
|
74
|
-
};
|
|
75
|
-
this.overlayCloseCallback = async () => {
|
|
76
|
-
if (this.restoreChildren) {
|
|
77
|
-
this.restoreChildren();
|
|
78
|
-
this.restoreChildren = void 0;
|
|
79
|
-
}
|
|
80
|
-
this.close();
|
|
81
|
-
requestAnimationFrame(() => this.menuStateResolver());
|
|
82
|
-
};
|
|
83
|
-
this._willUpdateItems = false;
|
|
84
|
-
this.itemsUpdated = Promise.resolve();
|
|
85
|
-
this.menuStatePromise = Promise.resolve();
|
|
86
|
-
this.selectionPromise = Promise.resolve();
|
|
87
|
-
this.onKeydown = this.onKeydown.bind(this);
|
|
88
|
-
}
|
|
89
|
-
get target() {
|
|
90
|
-
return this.button;
|
|
91
|
-
}
|
|
92
|
-
get focusElement() {
|
|
93
|
-
if (this.open) {
|
|
94
|
-
return this.optionsMenu;
|
|
95
|
-
}
|
|
96
|
-
return this.button;
|
|
97
|
-
}
|
|
98
|
-
forceFocusVisible() {
|
|
99
|
-
this.focused = true;
|
|
100
|
-
}
|
|
101
|
-
onButtonBlur() {
|
|
102
|
-
this.focused = false;
|
|
103
|
-
this.target.removeEventListener("keydown", this.onKeydown);
|
|
104
|
-
}
|
|
105
|
-
onButtonClick() {
|
|
106
|
-
this.toggle();
|
|
107
|
-
}
|
|
108
|
-
focus(options) {
|
|
109
|
-
super.focus(options);
|
|
110
|
-
if (!this.disabled && this.focusElement) {
|
|
111
|
-
this.focused = this.hasVisibleFocusInTree();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
onHelperFocus() {
|
|
115
|
-
this.focused = true;
|
|
116
|
-
this.button.focus();
|
|
117
|
-
}
|
|
118
|
-
onButtonFocus() {
|
|
119
|
-
this.target.addEventListener("keydown", this.onKeydown);
|
|
120
|
-
}
|
|
121
|
-
handleChange(event) {
|
|
122
|
-
event.stopPropagation();
|
|
123
|
-
const target = event.target;
|
|
124
|
-
const [selected] = target.selectedItems;
|
|
125
|
-
this.setValueFromItem(selected, event);
|
|
126
|
-
}
|
|
127
|
-
async setValueFromItem(item, menuChangeEvent) {
|
|
128
|
-
const oldSelectedItem = this.selectedItem;
|
|
129
|
-
const oldValue = this.value;
|
|
130
|
-
this.selectedItem = item;
|
|
131
|
-
this.value = item.value;
|
|
132
|
-
this.open = false;
|
|
133
|
-
await this.updateComplete;
|
|
134
|
-
const applyDefault = this.dispatchEvent(new Event("change", {
|
|
135
|
-
bubbles: true,
|
|
136
|
-
cancelable: true,
|
|
137
|
-
composed: true
|
|
138
|
-
}));
|
|
139
|
-
if (!applyDefault) {
|
|
140
|
-
if (menuChangeEvent) {
|
|
141
|
-
menuChangeEvent.preventDefault();
|
|
142
|
-
}
|
|
143
|
-
this.selectedItem.selected = false;
|
|
144
|
-
if (oldSelectedItem) {
|
|
145
|
-
oldSelectedItem.selected = true;
|
|
146
|
-
}
|
|
147
|
-
this.selectedItem = oldSelectedItem;
|
|
148
|
-
this.value = oldValue;
|
|
149
|
-
this.open = true;
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (oldSelectedItem) {
|
|
153
|
-
oldSelectedItem.selected = false;
|
|
154
|
-
}
|
|
155
|
-
item.selected = !!this.selects;
|
|
156
|
-
}
|
|
157
|
-
toggle(target) {
|
|
158
|
-
if (this.readonly) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
this.open = typeof target !== "undefined" ? target : !this.open;
|
|
162
|
-
}
|
|
163
|
-
close() {
|
|
164
|
-
if (this.readonly) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
this.open = false;
|
|
168
|
-
}
|
|
169
|
-
async generatePopover() {
|
|
170
|
-
if (!this.popoverFragment) {
|
|
171
|
-
this.popoverFragment = document.createDocumentFragment();
|
|
172
|
-
}
|
|
173
|
-
render(this.renderPopover, this.popoverFragment, { host: this });
|
|
174
|
-
this.popover = this.popoverFragment.children[0];
|
|
175
|
-
this.optionsMenu = this.popover.children[1];
|
|
176
|
-
}
|
|
177
|
-
async openMenu() {
|
|
178
|
-
let reparentableChildren = [];
|
|
179
|
-
const deprecatedMenu = this.querySelector(":scope > sp-menu");
|
|
180
|
-
await this.generatePopover();
|
|
181
|
-
if (deprecatedMenu) {
|
|
182
|
-
reparentableChildren = Array.from(deprecatedMenu.children);
|
|
183
|
-
} else {
|
|
184
|
-
reparentableChildren = Array.from(this.children).filter((element) => {
|
|
185
|
-
return !element.hasAttribute("slot");
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (reparentableChildren.length === 0) {
|
|
189
|
-
this.menuStateResolver();
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
this.restoreChildren = reparentChildren(reparentableChildren, this.optionsMenu, {
|
|
193
|
-
position: "beforeend",
|
|
194
|
-
prepareCallback: (el) => {
|
|
195
|
-
if (this.value === el.value) {
|
|
196
|
-
el.selected = true;
|
|
197
|
-
}
|
|
198
|
-
return (el2) => {
|
|
199
|
-
if (typeof el2.focused !== "undefined") {
|
|
200
|
-
el2.focused = false;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
this.sizePopover(this.popover);
|
|
206
|
-
this.closeOverlay = Picker.openOverlay(this, "modal", this.popover, {
|
|
207
|
-
placement: this.isMobile.matches ? "none" : this.placement,
|
|
208
|
-
receivesFocus: "auto"
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
sizePopover(popover) {
|
|
212
|
-
if (this.isMobile.matches) {
|
|
213
|
-
popover.style.setProperty("--swc-menu-width", `100%`);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (this.quiet)
|
|
217
|
-
return;
|
|
218
|
-
popover.style.setProperty("min-width", `${this.offsetWidth}px`);
|
|
219
|
-
}
|
|
220
|
-
async closeMenu() {
|
|
221
|
-
if (this.closeOverlay) {
|
|
222
|
-
const closeOverlay = this.closeOverlay;
|
|
223
|
-
delete this.closeOverlay;
|
|
224
|
-
(await closeOverlay)();
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
get selectedItemContent() {
|
|
228
|
-
if (this.selectedItem) {
|
|
229
|
-
return this.selectedItem.itemChildren;
|
|
230
|
-
}
|
|
231
|
-
return { icon: [], content: [] };
|
|
232
|
-
}
|
|
233
|
-
renderLabelContent(content) {
|
|
234
|
-
if (this.value && this.selectedItem) {
|
|
235
|
-
return content;
|
|
236
|
-
}
|
|
237
|
-
return html`
|
|
1
|
+
var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var o=(a,e,t,s)=>{for(var i=s>1?void 0:s?p(e,t):e,n=a.length-1,u;n>=0;n--)(u=a[n])&&(i=(s?u(e,t,i):u(i))||i);return s&&i&&d(e,t,i),i};import{html as l,nothing as c,render as m,SizedMixin as h}from"@spectrum-web-components/base";import{classMap as v}from"@spectrum-web-components/base/src/directives.js";import{property as r,query as f}from"@spectrum-web-components/base/src/decorators.js";import b from"./picker.css.js";import y from"@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";import{Focusable as I}from"@spectrum-web-components/shared/src/focusable.js";import{reparentChildren as w}from"@spectrum-web-components/shared/src/reparent-children.js";import"@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";import"@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";import"@spectrum-web-components/menu/sp-menu.js";import"@spectrum-web-components/tray/sp-tray.js";import"@spectrum-web-components/popover/sp-popover.js";import{openOverlay as M}from"@spectrum-web-components/overlay";import{IS_MOBILE as C,MatchMediaController as g}from"@spectrum-web-components/reactive-controllers/src/MatchMedia.js";const E={s:"spectrum-UIIcon-ChevronDown75",m:"spectrum-UIIcon-ChevronDown100",l:"spectrum-UIIcon-ChevronDown200",xl:"spectrum-UIIcon-ChevronDown300"};export class PickerBase extends h(I){constructor(){super();this.isMobile=new g(this,C);this.disabled=!1;this.focused=!1;this.invalid=!1;this.open=!1;this.readonly=!1;this.selects="single";this.menuItems=[];this.placement="bottom-start";this.quiet=!1;this.value="";this.listRole="listbox";this.itemRole="option";this.onKeydown=e=>{this.focused=!0,!(e.code!=="ArrowDown"&&e.code!=="ArrowUp")&&(e.preventDefault(),this.toggle(!0))};this.overlayOpenCallback=async()=>{this.updateMenuItems(),await this.itemsUpdated,await this.optionsMenu.updateComplete,requestAnimationFrame(()=>this.menuStateResolver())};this.overlayCloseCallback=async()=>{this.restoreChildren&&(this.restoreChildren(),this.restoreChildren=void 0),this.close(),requestAnimationFrame(()=>this.menuStateResolver())};this._willUpdateItems=!1;this.itemsUpdated=Promise.resolve();this.menuStatePromise=Promise.resolve();this.selectionPromise=Promise.resolve();this.onKeydown=this.onKeydown.bind(this)}get target(){return this.button}get focusElement(){return this.open?this.optionsMenu:this.button}forceFocusVisible(){this.focused=!0}onButtonBlur(){this.focused=!1,this.target.removeEventListener("keydown",this.onKeydown)}onButtonClick(){this.toggle()}focus(e){super.focus(e),!this.disabled&&this.focusElement&&(this.focused=this.hasVisibleFocusInTree())}onHelperFocus(){this.focused=!0,this.button.focus()}onButtonFocus(){this.target.addEventListener("keydown",this.onKeydown)}handleChange(e){e.stopPropagation();const t=e.target,[s]=t.selectedItems;this.setValueFromItem(s,e)}async setValueFromItem(e,t){const s=this.selectedItem,i=this.value;if(this.selectedItem=e,this.value=e.value,this.open=!1,await this.updateComplete,!this.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!0,composed:!0}))){t&&t.preventDefault(),this.selectedItem.selected=!1,s&&(s.selected=!0),this.selectedItem=s,this.value=i,this.open=!0;return}s&&(s.selected=!1),e.selected=!!this.selects}toggle(e){this.readonly||(this.open=typeof e!="undefined"?e:!this.open)}close(){this.readonly||(this.open=!1)}async generatePopover(){this.popoverFragment||(this.popoverFragment=document.createDocumentFragment()),m(this.renderPopover,this.popoverFragment,{host:this}),this.popover=this.popoverFragment.children[0],this.optionsMenu=this.popover.children[1]}async openMenu(){let e=[];const t=this.querySelector(":scope > sp-menu");if(await this.generatePopover(),t?e=Array.from(t.children):e=Array.from(this.children).filter(s=>!s.hasAttribute("slot")),e.length===0){this.menuStateResolver();return}this.restoreChildren=w(e,this.optionsMenu,{position:"beforeend",prepareCallback:s=>(this.value===s.value&&(s.selected=!0),i=>{typeof i.focused!="undefined"&&(i.focused=!1)})}),this.sizePopover(this.popover),this.closeOverlay=Picker.openOverlay(this,"modal",this.popover,{placement:this.isMobile.matches?"none":this.placement,receivesFocus:"auto"})}sizePopover(e){if(this.isMobile.matches){e.style.setProperty("--swc-menu-width","100%");return}this.quiet||e.style.setProperty("min-width",`${this.offsetWidth}px`)}async closeMenu(){if(this.closeOverlay){const e=this.closeOverlay;delete this.closeOverlay,(await e)()}}get selectedItemContent(){return this.selectedItem?this.selectedItem.itemChildren:{icon:[],content:[]}}renderLabelContent(e){return this.value&&this.selectedItem?e:l`
|
|
238
2
|
<slot name="label">${this.label}</slot>
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
get buttonContent() {
|
|
242
|
-
const labelClasses = {
|
|
243
|
-
"visually-hidden": this.icons === "only" && !!this.value,
|
|
244
|
-
placeholder: !this.value
|
|
245
|
-
};
|
|
246
|
-
return [
|
|
247
|
-
html`
|
|
248
|
-
<span id="icon" ?hidden=${this.icons === "none"}>
|
|
3
|
+
`}get buttonContent(){const e={"visually-hidden":this.icons==="only"&&!!this.value,placeholder:!this.value};return[l`
|
|
4
|
+
<span id="icon" ?hidden=${this.icons==="none"}>
|
|
249
5
|
${this.selectedItemContent.icon}
|
|
250
6
|
</span>
|
|
251
|
-
<span id="label" class=${
|
|
7
|
+
<span id="label" class=${v(e)}>
|
|
252
8
|
${this.renderLabelContent(this.selectedItemContent.content)}
|
|
253
9
|
</span>
|
|
254
|
-
${this.invalid
|
|
10
|
+
${this.invalid?l`
|
|
255
11
|
<sp-icon-alert
|
|
256
12
|
class="validation-icon"
|
|
257
13
|
></sp-icon-alert>
|
|
258
|
-
|
|
14
|
+
`:c}
|
|
259
15
|
<sp-icon-chevron100
|
|
260
|
-
class="picker ${
|
|
16
|
+
class="picker ${E[this.size]}"
|
|
261
17
|
></sp-icon-chevron100>
|
|
262
|
-
`
|
|
263
|
-
];
|
|
264
|
-
}
|
|
265
|
-
render() {
|
|
266
|
-
return html`
|
|
18
|
+
`]}render(){return l`
|
|
267
19
|
<span
|
|
268
20
|
id="focus-helper"
|
|
269
|
-
tabindex="${this.focused
|
|
21
|
+
tabindex="${this.focused?"-1":"0"}"
|
|
270
22
|
@focus=${this.onHelperFocus}
|
|
271
23
|
></span>
|
|
272
24
|
<button
|
|
273
25
|
aria-haspopup="true"
|
|
274
|
-
aria-expanded=${this.open
|
|
26
|
+
aria-expanded=${this.open?"true":"false"}
|
|
275
27
|
aria-labelledby="button icon label"
|
|
276
28
|
id="button"
|
|
277
29
|
class="button"
|
|
@@ -283,36 +35,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
283
35
|
>
|
|
284
36
|
${this.buttonContent}
|
|
285
37
|
</button>
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
update(changes) {
|
|
289
|
-
if (this.selects) {
|
|
290
|
-
this.selects = "single";
|
|
291
|
-
}
|
|
292
|
-
if (changes.has("disabled") && this.disabled) {
|
|
293
|
-
this.open = false;
|
|
294
|
-
}
|
|
295
|
-
if (changes.has("open") && (this.open || typeof changes.get("open") !== "undefined")) {
|
|
296
|
-
this.menuStatePromise = new Promise((res) => this.menuStateResolver = res);
|
|
297
|
-
if (this.open) {
|
|
298
|
-
this.openMenu();
|
|
299
|
-
} else {
|
|
300
|
-
this.closeMenu();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (changes.has("value") && !changes.has("selectedItem")) {
|
|
304
|
-
this.updateMenuItems();
|
|
305
|
-
}
|
|
306
|
-
if (false) {
|
|
307
|
-
if (!this.hasUpdated && this.querySelector("sp-menu")) {
|
|
308
|
-
const { localName } = this;
|
|
309
|
-
window.__swc.warn(this, `You no longer need to provide an <sp-menu> child to ${localName}. Any styling or attributes on the <sp-menu> will be ignored.`, "https://opensource.adobe.com/spectrum-web-components/components/picker/#sizes", { level: "deprecation" });
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
super.update(changes);
|
|
313
|
-
}
|
|
314
|
-
get dismissHelper() {
|
|
315
|
-
return html`
|
|
38
|
+
`}update(e){this.selects&&(this.selects="single"),e.has("disabled")&&this.disabled&&(this.open=!1),e.has("open")&&(this.open||typeof e.get("open")!="undefined")&&(this.menuStatePromise=new Promise(t=>this.menuStateResolver=t),this.open?this.openMenu():this.closeMenu()),e.has("value")&&!e.has("selectedItem")&&this.updateMenuItems(),super.update(e)}get dismissHelper(){return l`
|
|
316
39
|
<div class="visually-hidden">
|
|
317
40
|
<button
|
|
318
41
|
tabindex="-1"
|
|
@@ -320,10 +43,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
320
43
|
@click=${this.close}
|
|
321
44
|
></button>
|
|
322
45
|
</div>
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
get renderPopover() {
|
|
326
|
-
const content = html`
|
|
46
|
+
`}get renderPopover(){const e=l`
|
|
327
47
|
${this.dismissHelper}
|
|
328
48
|
<sp-menu
|
|
329
49
|
id="menu"
|
|
@@ -332,9 +52,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
332
52
|
.selects=${this.selects}
|
|
333
53
|
></sp-menu>
|
|
334
54
|
${this.dismissHelper}
|
|
335
|
-
`;
|
|
336
|
-
if (this.isMobile.matches) {
|
|
337
|
-
return html`
|
|
55
|
+
`;return this.isMobile.matches?l`
|
|
338
56
|
<sp-tray
|
|
339
57
|
id="popover"
|
|
340
58
|
role="dialog"
|
|
@@ -342,11 +60,9 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
342
60
|
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
343
61
|
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
344
62
|
>
|
|
345
|
-
${
|
|
63
|
+
${e}
|
|
346
64
|
</sp-tray>
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
return html`
|
|
65
|
+
`:l`
|
|
350
66
|
<sp-popover
|
|
351
67
|
id="popover"
|
|
352
68
|
role="dialog"
|
|
@@ -354,148 +70,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
354
70
|
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
355
71
|
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
356
72
|
>
|
|
357
|
-
${
|
|
73
|
+
${e}
|
|
358
74
|
</sp-popover>
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
updateMenuItems(event) {
|
|
362
|
-
if (this.open && (event == null ? void 0 : event.type) === "sp-menu-item-removed")
|
|
363
|
-
return;
|
|
364
|
-
if (this._willUpdateItems)
|
|
365
|
-
return;
|
|
366
|
-
this._willUpdateItems = true;
|
|
367
|
-
if ((event == null ? void 0 : event.item) === this.selectedItem) {
|
|
368
|
-
this.requestUpdate();
|
|
369
|
-
}
|
|
370
|
-
let resolve = () => {
|
|
371
|
-
return;
|
|
372
|
-
};
|
|
373
|
-
this.itemsUpdated = new Promise((res) => resolve = res);
|
|
374
|
-
window.requestAnimationFrame(async () => {
|
|
375
|
-
if (this.open) {
|
|
376
|
-
await this.optionsMenu.updateComplete;
|
|
377
|
-
this.menuItems = this.optionsMenu.childItems;
|
|
378
|
-
} else {
|
|
379
|
-
this.menuItems = [
|
|
380
|
-
...this.querySelectorAll('sp-menu-item:not([slot="submenu"] *)')
|
|
381
|
-
];
|
|
382
|
-
}
|
|
383
|
-
this.manageSelection();
|
|
384
|
-
resolve();
|
|
385
|
-
this._willUpdateItems = false;
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
async manageSelection() {
|
|
389
|
-
await this.menuStatePromise;
|
|
390
|
-
this.selectionPromise = new Promise((res) => this.selectionResolver = res);
|
|
391
|
-
let selectedItem;
|
|
392
|
-
this.menuItems.forEach((item) => {
|
|
393
|
-
if (this.value === item.value && !item.disabled) {
|
|
394
|
-
selectedItem = item;
|
|
395
|
-
} else {
|
|
396
|
-
item.selected = false;
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
if (selectedItem) {
|
|
400
|
-
selectedItem.selected = !!this.selects;
|
|
401
|
-
this.selectedItem = selectedItem;
|
|
402
|
-
} else {
|
|
403
|
-
this.value = "";
|
|
404
|
-
this.selectedItem = void 0;
|
|
405
|
-
}
|
|
406
|
-
if (this.open) {
|
|
407
|
-
await this.optionsMenu.updateComplete;
|
|
408
|
-
this.optionsMenu.updateSelectedItemIndex();
|
|
409
|
-
}
|
|
410
|
-
this.selectionResolver();
|
|
411
|
-
}
|
|
412
|
-
async getUpdateComplete() {
|
|
413
|
-
const complete = await super.getUpdateComplete();
|
|
414
|
-
await this.menuStatePromise;
|
|
415
|
-
await this.itemsUpdated;
|
|
416
|
-
await this.selectionPromise;
|
|
417
|
-
return complete;
|
|
418
|
-
}
|
|
419
|
-
connectedCallback() {
|
|
420
|
-
this.updateMenuItems();
|
|
421
|
-
this.addEventListener("sp-menu-item-added-or-updated", this.updateMenuItems);
|
|
422
|
-
this.addEventListener("sp-menu-item-removed", this.updateMenuItems);
|
|
423
|
-
super.connectedCallback();
|
|
424
|
-
}
|
|
425
|
-
disconnectedCallback() {
|
|
426
|
-
this.close();
|
|
427
|
-
super.disconnectedCallback();
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
PickerBase.openOverlay = async (target, interaction, content, options) => {
|
|
431
|
-
return await openOverlay(target, interaction, content, options);
|
|
432
|
-
};
|
|
433
|
-
__decorateClass([
|
|
434
|
-
query("#button")
|
|
435
|
-
], PickerBase.prototype, "button", 2);
|
|
436
|
-
__decorateClass([
|
|
437
|
-
property({ type: Boolean, reflect: true })
|
|
438
|
-
], PickerBase.prototype, "disabled", 2);
|
|
439
|
-
__decorateClass([
|
|
440
|
-
property({ type: Boolean, reflect: true })
|
|
441
|
-
], PickerBase.prototype, "focused", 2);
|
|
442
|
-
__decorateClass([
|
|
443
|
-
property({ type: String, reflect: true })
|
|
444
|
-
], PickerBase.prototype, "icons", 2);
|
|
445
|
-
__decorateClass([
|
|
446
|
-
property({ type: Boolean, reflect: true })
|
|
447
|
-
], PickerBase.prototype, "invalid", 2);
|
|
448
|
-
__decorateClass([
|
|
449
|
-
property()
|
|
450
|
-
], PickerBase.prototype, "label", 2);
|
|
451
|
-
__decorateClass([
|
|
452
|
-
property({ type: Boolean, reflect: true })
|
|
453
|
-
], PickerBase.prototype, "open", 2);
|
|
454
|
-
__decorateClass([
|
|
455
|
-
property({ type: Boolean, reflect: true })
|
|
456
|
-
], PickerBase.prototype, "readonly", 2);
|
|
457
|
-
__decorateClass([
|
|
458
|
-
property()
|
|
459
|
-
], PickerBase.prototype, "placement", 2);
|
|
460
|
-
__decorateClass([
|
|
461
|
-
property({ type: Boolean, reflect: true })
|
|
462
|
-
], PickerBase.prototype, "quiet", 2);
|
|
463
|
-
__decorateClass([
|
|
464
|
-
property({ type: String })
|
|
465
|
-
], PickerBase.prototype, "value", 2);
|
|
466
|
-
__decorateClass([
|
|
467
|
-
property({ attribute: false })
|
|
468
|
-
], PickerBase.prototype, "selectedItem", 2);
|
|
469
|
-
export class Picker extends PickerBase {
|
|
470
|
-
constructor() {
|
|
471
|
-
super(...arguments);
|
|
472
|
-
this.onKeydown = (event) => {
|
|
473
|
-
const { code } = event;
|
|
474
|
-
this.focused = true;
|
|
475
|
-
if (!code.startsWith("Arrow") || this.readonly) {
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
event.preventDefault();
|
|
479
|
-
if (code === "ArrowUp" || code === "ArrowDown") {
|
|
480
|
-
this.toggle(true);
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
const selectedIndex = this.selectedItem ? this.menuItems.indexOf(this.selectedItem) : -1;
|
|
484
|
-
const nextOffset = !this.value || code === "ArrowRight" ? 1 : -1;
|
|
485
|
-
let nextIndex = selectedIndex + nextOffset;
|
|
486
|
-
while (this.menuItems[nextIndex] && this.menuItems[nextIndex].disabled) {
|
|
487
|
-
nextIndex += nextOffset;
|
|
488
|
-
}
|
|
489
|
-
if (!this.menuItems[nextIndex] || this.menuItems[nextIndex].disabled) {
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
if (!this.value || nextIndex !== selectedIndex) {
|
|
493
|
-
this.setValueFromItem(this.menuItems[nextIndex]);
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
static get styles() {
|
|
498
|
-
return [pickerStyles, chevronStyles];
|
|
499
|
-
}
|
|
500
|
-
}
|
|
75
|
+
`}updateMenuItems(e){if(this.open&&(e==null?void 0:e.type)==="sp-menu-item-removed"||this._willUpdateItems)return;this._willUpdateItems=!0,(e==null?void 0:e.item)===this.selectedItem&&this.requestUpdate();let t=()=>{};this.itemsUpdated=new Promise(s=>t=s),window.requestAnimationFrame(async()=>{this.open?(await this.optionsMenu.updateComplete,this.menuItems=this.optionsMenu.childItems):this.menuItems=[...this.querySelectorAll('sp-menu-item:not([slot="submenu"] *)')],this.manageSelection(),t(),this._willUpdateItems=!1})}async manageSelection(){await this.menuStatePromise,this.selectionPromise=new Promise(t=>this.selectionResolver=t);let e;this.menuItems.forEach(t=>{this.value===t.value&&!t.disabled?e=t:t.selected=!1}),e?(e.selected=!!this.selects,this.selectedItem=e):(this.value="",this.selectedItem=void 0),this.open&&(await this.optionsMenu.updateComplete,this.optionsMenu.updateSelectedItemIndex()),this.selectionResolver()}async getUpdateComplete(){const e=await super.getUpdateComplete();return await this.menuStatePromise,await this.itemsUpdated,await this.selectionPromise,e}connectedCallback(){this.updateMenuItems(),this.addEventListener("sp-menu-item-added-or-updated",this.updateMenuItems),this.addEventListener("sp-menu-item-removed",this.updateMenuItems),super.connectedCallback()}disconnectedCallback(){this.close(),super.disconnectedCallback()}}PickerBase.openOverlay=async(e,t,s,i)=>await M(e,t,s,i),o([f("#button")],PickerBase.prototype,"button",2),o([r({type:Boolean,reflect:!0})],PickerBase.prototype,"disabled",2),o([r({type:Boolean,reflect:!0})],PickerBase.prototype,"focused",2),o([r({type:String,reflect:!0})],PickerBase.prototype,"icons",2),o([r({type:Boolean,reflect:!0})],PickerBase.prototype,"invalid",2),o([r()],PickerBase.prototype,"label",2),o([r({type:Boolean,reflect:!0})],PickerBase.prototype,"open",2),o([r({type:Boolean,reflect:!0})],PickerBase.prototype,"readonly",2),o([r()],PickerBase.prototype,"placement",2),o([r({type:Boolean,reflect:!0})],PickerBase.prototype,"quiet",2),o([r({type:String})],PickerBase.prototype,"value",2),o([r({attribute:!1})],PickerBase.prototype,"selectedItem",2);export class Picker extends PickerBase{constructor(){super(...arguments);this.onKeydown=e=>{const{code:t}=e;if(this.focused=!0,!t.startsWith("Arrow")||this.readonly)return;if(e.preventDefault(),t==="ArrowUp"||t==="ArrowDown"){this.toggle(!0);return}const s=this.selectedItem?this.menuItems.indexOf(this.selectedItem):-1,i=!this.value||t==="ArrowRight"?1:-1;let n=s+i;for(;this.menuItems[n]&&this.menuItems[n].disabled;)n+=i;!this.menuItems[n]||this.menuItems[n].disabled||(!this.value||n!==s)&&this.setValueFromItem(this.menuItems[n])}}static get styles(){return[b,y]}}
|
|
501
76
|
//# sourceMappingURL=Picker.js.map
|