godown 3.11.2 → 3.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/build/godown+lit.iife.js +12 -13
- package/build/godown+lit.iife.js.map +1 -1
- package/build/godown+lit.js +11 -12
- package/build/godown+lit.js.map +1 -1
- package/build/godown+lit.umd.js +12 -13
- package/build/godown+lit.umd.js.map +1 -1
- package/build/godown.iife.js +9 -8
- package/build/godown.iife.js.map +1 -0
- package/build/godown.js +7 -7
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +8 -8
- package/build/godown.umd.js.map +1 -1
- package/custom-elements.json +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/internal/global-style.d.ts.map +1 -1
- package/internal/global-style.js +1 -1
- package/internal/global-style.js.map +1 -1
- package/internal/popover.d.ts +3 -0
- package/internal/popover.d.ts.map +1 -0
- package/internal/popover.js +2 -0
- package/internal/popover.js.map +1 -0
- package/internal/reset-style.d.ts +3 -0
- package/internal/reset-style.d.ts.map +1 -0
- package/internal/reset-style.js +2 -0
- package/internal/reset-style.js.map +1 -0
- package/internal/ring.d.ts +1 -0
- package/internal/ring.d.ts.map +1 -1
- package/internal/ring.js +1 -1
- package/internal/ring.js.map +1 -1
- package/internal/super-input.d.ts +1 -4
- package/internal/super-input.d.ts.map +1 -1
- package/internal/super-input.js +1 -1
- package/internal/super-input.js.map +1 -1
- package/internal/utils.d.ts +2 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +2 -0
- package/internal/utils.js.map +1 -0
- package/package.json +3 -4
- package/popover.d.ts +2 -0
- package/popover.d.ts.map +1 -0
- package/popover.js +2 -0
- package/popover.js.map +1 -0
- package/src/index.ts +1 -0
- package/src/internal/global-style.ts +6 -34
- package/src/internal/popover.ts +64 -0
- package/src/internal/reset-style.ts +63 -0
- package/src/internal/ring.ts +3 -2
- package/src/internal/super-input.ts +2 -33
- package/src/internal/utils.ts +10 -0
- package/src/popover.ts +1 -0
- package/src/web-components/alert/component.ts +5 -4
- package/src/web-components/avatar/component.ts +1 -0
- package/src/web-components/button/component.ts +22 -18
- package/src/web-components/card/component.ts +3 -2
- package/src/web-components/chip/component.ts +1 -3
- package/src/web-components/details/component.ts +28 -17
- package/src/web-components/dialog/component.ts +51 -67
- package/src/web-components/heading/component.ts +0 -1
- package/src/web-components/input/component.ts +38 -30
- package/src/web-components/layout/component.ts +1 -0
- package/src/web-components/link/component.ts +0 -2
- package/src/web-components/popover/component.ts +172 -0
- package/src/web-components/popover/definition.ts +11 -0
- package/src/web-components/range/component.ts +2 -1
- package/src/web-components/rotate/component.ts +0 -1
- package/src/web-components/select/component.ts +109 -173
- package/src/web-components/split/component.ts +2 -2
- package/src/web-components/switch/component.ts +2 -1
- package/src/web-components/tabs/component.ts +99 -100
- package/src/web-components/text/component.ts +47 -52
- package/src/web-components/time/component.ts +5 -15
- package/src/web-components/tooltip/component.ts +44 -111
- package/vscode.css-custom-data.json +1 -1
- package/vscode.html-custom-data.json +1 -1
- package/web-components/alert/component.d.ts.map +1 -1
- package/web-components/alert/component.js +1 -1
- package/web-components/alert/component.js.map +1 -1
- package/web-components/avatar/component.d.ts.map +1 -1
- package/web-components/avatar/component.js +1 -1
- package/web-components/avatar/component.js.map +1 -1
- package/web-components/button/component.d.ts.map +1 -1
- package/web-components/button/component.js +1 -1
- package/web-components/button/component.js.map +1 -1
- package/web-components/card/component.d.ts.map +1 -1
- package/web-components/card/component.js +1 -1
- package/web-components/card/component.js.map +1 -1
- package/web-components/chip/component.d.ts +1 -3
- package/web-components/chip/component.d.ts.map +1 -1
- package/web-components/chip/component.js.map +1 -1
- package/web-components/details/component.d.ts +9 -13
- package/web-components/details/component.d.ts.map +1 -1
- package/web-components/details/component.js +1 -1
- package/web-components/details/component.js.map +1 -1
- package/web-components/dialog/component.d.ts +12 -14
- package/web-components/dialog/component.d.ts.map +1 -1
- package/web-components/dialog/component.js +1 -1
- package/web-components/dialog/component.js.map +1 -1
- package/web-components/heading/component.d.ts.map +1 -1
- package/web-components/heading/component.js +1 -1
- package/web-components/heading/component.js.map +1 -1
- package/web-components/input/component.d.ts +3 -1
- package/web-components/input/component.d.ts.map +1 -1
- package/web-components/input/component.js +1 -1
- package/web-components/input/component.js.map +1 -1
- package/web-components/layout/component.d.ts.map +1 -1
- package/web-components/layout/component.js +1 -1
- package/web-components/layout/component.js.map +1 -1
- package/web-components/link/component.d.ts.map +1 -1
- package/web-components/link/component.js +1 -1
- package/web-components/link/component.js.map +1 -1
- package/web-components/popover/component.d.ts +35 -0
- package/web-components/popover/component.d.ts.map +1 -0
- package/web-components/popover/component.js +2 -0
- package/web-components/popover/component.js.map +1 -0
- package/web-components/popover/definition.d.ts +8 -0
- package/web-components/popover/definition.d.ts.map +1 -0
- package/web-components/popover/definition.js +2 -0
- package/web-components/popover/definition.js.map +1 -0
- package/web-components/range/component.d.ts.map +1 -1
- package/web-components/range/component.js +1 -1
- package/web-components/range/component.js.map +1 -1
- package/web-components/rotate/component.d.ts.map +1 -1
- package/web-components/rotate/component.js.map +1 -1
- package/web-components/select/component.d.ts +11 -27
- package/web-components/select/component.d.ts.map +1 -1
- package/web-components/select/component.js +1 -1
- package/web-components/select/component.js.map +1 -1
- package/web-components/split/component.js +1 -1
- package/web-components/split/component.js.map +1 -1
- package/web-components/switch/component.d.ts.map +1 -1
- package/web-components/switch/component.js +1 -1
- package/web-components/switch/component.js.map +1 -1
- package/web-components/tabs/component.d.ts +18 -25
- package/web-components/tabs/component.d.ts.map +1 -1
- package/web-components/tabs/component.js +1 -1
- package/web-components/tabs/component.js.map +1 -1
- package/web-components/text/component.d.ts +4 -7
- package/web-components/text/component.d.ts.map +1 -1
- package/web-components/text/component.js +1 -1
- package/web-components/text/component.js.map +1 -1
- package/web-components/time/component.d.ts +2 -2
- package/web-components/time/component.d.ts.map +1 -1
- package/web-components/time/component.js +1 -1
- package/web-components/time/component.js.map +1 -1
- package/web-components/tooltip/component.d.ts +15 -39
- package/web-components/tooltip/component.d.ts.map +1 -1
- package/web-components/tooltip/component.js +1 -1
- package/web-components/tooltip/component.js.map +1 -1
- package/web-types.json +1 -1
- package/internal/direction.d.ts +0 -27
- package/internal/direction.d.ts.map +0 -1
- package/internal/direction.js +0 -2
- package/internal/direction.js.map +0 -1
- package/internal/super-openable.d.ts +0 -15
- package/internal/super-openable.d.ts.map +0 -1
- package/internal/super-openable.js +0 -2
- package/internal/super-openable.js.map +0 -1
- package/src/internal/direction.ts +0 -65
- package/src/internal/super-openable.ts +0 -34
@@ -0,0 +1,172 @@
|
|
1
|
+
import { property } from "lit/decorators.js";
|
2
|
+
import GlobalStyle from "../../internal/global-style.js";
|
3
|
+
import { css, html, type PropertyValues, type TemplateResult } from "lit";
|
4
|
+
import { godown, htmlSlot, joinRules, part, StyleController, styles } from "@godown/element";
|
5
|
+
import { hidePopover, showPopover } from "../../internal/popover.js";
|
6
|
+
|
7
|
+
const POPOVER = "popover";
|
8
|
+
const protoName = POPOVER;
|
9
|
+
|
10
|
+
/**
|
11
|
+
* {@link Popover} renders a popover.
|
12
|
+
*
|
13
|
+
* This requires the support of the popover API and CSS position-area.
|
14
|
+
*
|
15
|
+
* @fires toggle - Fired when the popover is toggled.
|
16
|
+
* @slot popover - Popover content.
|
17
|
+
* @slot - Popover trigger.
|
18
|
+
* @category display
|
19
|
+
*/
|
20
|
+
@godown(protoName)
|
21
|
+
@styles(css`
|
22
|
+
:host {
|
23
|
+
display: inline-block;
|
24
|
+
}
|
25
|
+
|
26
|
+
[part="trigger"] {
|
27
|
+
display: contents;
|
28
|
+
}
|
29
|
+
|
30
|
+
[part="root"] {
|
31
|
+
display: inherit;
|
32
|
+
}
|
33
|
+
|
34
|
+
[part="popover"] {
|
35
|
+
inset: unset;
|
36
|
+
z-index: 1;
|
37
|
+
overflow: visible;
|
38
|
+
position: absolute;
|
39
|
+
position-try-fallbacks: flip-block;
|
40
|
+
}
|
41
|
+
`)
|
42
|
+
class Popover extends GlobalStyle {
|
43
|
+
anchorName = `--${POPOVER}-${Math.random().toString(36).slice(2)}`;
|
44
|
+
|
45
|
+
@property({ type: Boolean, reflect: true })
|
46
|
+
open = false;
|
47
|
+
|
48
|
+
@property()
|
49
|
+
action: "hide" | "show" | "toggle" | "none" = "show";
|
50
|
+
|
51
|
+
@property()
|
52
|
+
span: "span" | "spread" | "isolated" = "span";
|
53
|
+
|
54
|
+
/**
|
55
|
+
* The position refers to the spatial location of the popover in relation to the trigger,
|
56
|
+
* rather than the alignment property between them.
|
57
|
+
*/
|
58
|
+
@property()
|
59
|
+
position:
|
60
|
+
| "center"
|
61
|
+
| "left"
|
62
|
+
| "left-top"
|
63
|
+
| "left-bottom"
|
64
|
+
| "right"
|
65
|
+
| "right-top"
|
66
|
+
| "right-bottom"
|
67
|
+
| "top"
|
68
|
+
| "top-left"
|
69
|
+
| "top-right"
|
70
|
+
| "bottom"
|
71
|
+
| "bottom-left"
|
72
|
+
| "bottom-right"
|
73
|
+
| "start"
|
74
|
+
| "start-start"
|
75
|
+
| "start-end"
|
76
|
+
| "end"
|
77
|
+
| "end-start"
|
78
|
+
| "end-end" = "bottom";
|
79
|
+
|
80
|
+
@part(POPOVER)
|
81
|
+
protected _popover: HTMLElement;
|
82
|
+
|
83
|
+
constructor() {
|
84
|
+
super();
|
85
|
+
new StyleController(this, () => {
|
86
|
+
return joinRules({
|
87
|
+
"[part=root],slot:not([name])::slotted(*)": {
|
88
|
+
"anchor-name": this.anchorName,
|
89
|
+
},
|
90
|
+
"[part=popover]": {
|
91
|
+
"position-anchor": this.anchorName,
|
92
|
+
"position-area": this.resolveArea(),
|
93
|
+
},
|
94
|
+
});
|
95
|
+
});
|
96
|
+
}
|
97
|
+
protected render(): TemplateResult<1> {
|
98
|
+
return html`
|
99
|
+
<div part="root">
|
100
|
+
<div
|
101
|
+
part="trigger"
|
102
|
+
@click=${this._handleClick}
|
103
|
+
>
|
104
|
+
${htmlSlot()}
|
105
|
+
</div>
|
106
|
+
<div
|
107
|
+
part="popover"
|
108
|
+
popover="manual"
|
109
|
+
>
|
110
|
+
${htmlSlot("popover")}
|
111
|
+
</div>
|
112
|
+
</div>
|
113
|
+
`;
|
114
|
+
}
|
115
|
+
|
116
|
+
protected _handleClick(): void {
|
117
|
+
const { action } = this;
|
118
|
+
switch (action) {
|
119
|
+
case "show":
|
120
|
+
case "hide":
|
121
|
+
case "toggle":
|
122
|
+
this[action]();
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
show(): void {
|
127
|
+
this.toggle(true);
|
128
|
+
}
|
129
|
+
|
130
|
+
hide(): void {
|
131
|
+
this.toggle(false);
|
132
|
+
}
|
133
|
+
|
134
|
+
toggle(force?: boolean): void {
|
135
|
+
this.open = force ?? !this.open;
|
136
|
+
}
|
137
|
+
|
138
|
+
protected updated(_changedProperties: PropertyValues): void {
|
139
|
+
if (_changedProperties.has("open")) {
|
140
|
+
this._openChange();
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
protected _openChange(): void {
|
145
|
+
const { open } = this;
|
146
|
+
if (open) {
|
147
|
+
showPopover.call(this, this._popover);
|
148
|
+
const listener = (e) => {
|
149
|
+
if (!this.contains(e.target)) {
|
150
|
+
this.events.remove(document, "click", listener);
|
151
|
+
this.open = false;
|
152
|
+
}
|
153
|
+
};
|
154
|
+
this.events.add(document, "click", listener);
|
155
|
+
} else {
|
156
|
+
hidePopover(this._popover);
|
157
|
+
}
|
158
|
+
this.dispatchCustomEvent("toggle", open);
|
159
|
+
}
|
160
|
+
|
161
|
+
resolveArea(): string {
|
162
|
+
const split = this.position.split("-");
|
163
|
+
const firstValue = this.span === "spread" ? `span-${split[0]}` : split[0];
|
164
|
+
if (split.length < 2) {
|
165
|
+
return `${firstValue} center`;
|
166
|
+
}
|
167
|
+
const secondValue = this.span === "isolated" ? split[1] : `span-${split[1]}`;
|
168
|
+
return `${firstValue} ${secondValue}`;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
export { Popover, Popover as default };
|
@@ -15,6 +15,7 @@ import { property, queryAll, state } from "lit/decorators.js";
|
|
15
15
|
|
16
16
|
import { cssGlobalVars, scopePrefix } from "../../internal/global-style.js";
|
17
17
|
import { SuperInput } from "../../internal/super-input.js";
|
18
|
+
import { ringTypeAttribute } from "../../internal/ring.js";
|
18
19
|
|
19
20
|
const protoName = "range";
|
20
21
|
const cssScope = scopePrefix(protoName);
|
@@ -203,7 +204,7 @@ class Range<V extends RangeValue = RangeValue> extends SuperInput<RangeValue> {
|
|
203
204
|
}
|
204
205
|
|
205
206
|
get observedRecord(): Record<string, any> {
|
206
|
-
return omit(super.observedRecord,
|
207
|
+
return omit(super.observedRecord, ringTypeAttribute);
|
207
208
|
}
|
208
209
|
|
209
210
|
protected render(): TemplateResult<1> {
|
@@ -1,25 +1,17 @@
|
|
1
1
|
import { type HandlerEvent, attr, godown, htmlSlot, queryPart, styles } from "@godown/element";
|
2
2
|
import svgCaretDown from "../../internal/icons/caret-down.js";
|
3
3
|
import { type TemplateResult, css, html, nothing } from "lit";
|
4
|
-
import { property
|
4
|
+
import { property } from "lit/decorators.js";
|
5
5
|
|
6
6
|
import Input from "../input/component.js";
|
7
|
-
import {
|
8
|
-
import {
|
7
|
+
import { hidePopover, showPopover } from "../../internal/popover.js";
|
8
|
+
import { memoize } from "../../internal/utils.js";
|
9
9
|
|
10
|
-
|
11
|
-
return a && b && a.toLowerCase().includes(b.toLowerCase());
|
12
|
-
}
|
13
|
-
|
14
|
-
function betweenAt(i: number, s: string, c: string) {
|
15
|
-
const start = s.slice(0, i).lastIndexOf(c) + 1 || 0;
|
16
|
-
const end = s.indexOf(c, i) || s.length;
|
17
|
-
return s.slice(start, end);
|
18
|
-
}
|
10
|
+
const supportsPositionArea = memoize(() => CSS.supports("position-area:top"));
|
19
11
|
|
20
|
-
function
|
12
|
+
function updateSelected(element: HTMLElement | null, operation: 0 | 1) {
|
21
13
|
if (element) {
|
22
|
-
const name = "
|
14
|
+
const name = "selected";
|
23
15
|
if (operation) {
|
24
16
|
element.setAttribute(name, "");
|
25
17
|
} else {
|
@@ -33,14 +25,6 @@ const protoName = "select";
|
|
33
25
|
/**
|
34
26
|
* {@linkcode Select} is similar to `<select>`.
|
35
27
|
*
|
36
|
-
* Elements with the value attribute/property can be used as options.
|
37
|
-
*
|
38
|
-
* The checked attribute will be added to the selected element.
|
39
|
-
*
|
40
|
-
* Multi-selected state looks the same as single-selected.
|
41
|
-
*
|
42
|
-
* Input will filter the options.
|
43
|
-
*
|
44
28
|
* @fires input - Fires when the input value changes.
|
45
29
|
* @fires change - Fires when the input value changes.
|
46
30
|
* @fires select - Fires when select an option.
|
@@ -48,67 +32,63 @@ const protoName = "select";
|
|
48
32
|
* @category input
|
49
33
|
*/
|
50
34
|
@godown(protoName)
|
51
|
-
@styles(
|
52
|
-
|
53
|
-
|
54
|
-
:
|
55
|
-
|
56
|
-
${cssGlobalVars.input}-outline-color: currentColor;
|
57
|
-
}
|
35
|
+
@styles(css`
|
36
|
+
[part="root"] {
|
37
|
+
position: relative;
|
38
|
+
anchor-name: --select;
|
39
|
+
}
|
58
40
|
|
59
|
-
|
60
|
-
|
61
|
-
|
41
|
+
label {
|
42
|
+
display: contents;
|
43
|
+
}
|
62
44
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
45
|
+
[part="popover"] {
|
46
|
+
border: 0;
|
47
|
+
width: 100%;
|
48
|
+
background: none;
|
49
|
+
position-anchor: --select;
|
50
|
+
position-area: bottom center;
|
51
|
+
position-try-fallbacks: flip-block;
|
52
|
+
}
|
53
|
+
|
54
|
+
[part="input"] {
|
55
|
+
text-overflow: ellipsis;
|
56
|
+
}
|
68
57
|
|
69
|
-
|
70
|
-
|
58
|
+
@supports not (position-area: top) {
|
59
|
+
[part="popover"] {
|
60
|
+
left: 0;
|
61
|
+
top: 100%;
|
62
|
+
display: none;
|
63
|
+
position: absolute;
|
71
64
|
}
|
72
|
-
|
73
|
-
)
|
65
|
+
}
|
66
|
+
`)
|
74
67
|
class Select extends Input {
|
75
|
-
// @ts-ignore
|
76
|
-
value: string | string[];
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Selected texts.
|
80
|
-
*/
|
81
68
|
@property()
|
82
69
|
text: string;
|
83
70
|
|
84
|
-
@queryPart("content")
|
85
|
-
protected _content: HTMLElement;
|
86
|
-
|
87
|
-
@property()
|
88
|
-
direction: DirectionCardinalY;
|
89
|
-
|
90
71
|
@property({ type: Boolean })
|
91
72
|
multiple = false;
|
92
73
|
|
93
74
|
@property({ type: Boolean })
|
94
|
-
|
75
|
+
noEdit = false;
|
76
|
+
|
77
|
+
@property({ type: Array })
|
78
|
+
values: {
|
79
|
+
value: string;
|
80
|
+
label?: string;
|
81
|
+
}[] = [];
|
95
82
|
|
96
|
-
@
|
97
|
-
|
83
|
+
@queryPart("popover")
|
84
|
+
_popover: HTMLElement;
|
98
85
|
|
99
86
|
protected lastChecked: HTMLElement;
|
100
87
|
protected defaultText: string;
|
101
|
-
protected
|
102
|
-
private __store: { value: string; text: string }[] = [];
|
103
|
-
|
104
|
-
get observedRecord(): Record<string, any> {
|
105
|
-
return {
|
106
|
-
...super.observedRecord,
|
107
|
-
direction: this.direction || this.autoDirection,
|
108
|
-
};
|
109
|
-
}
|
88
|
+
protected optionsVisible = false;
|
110
89
|
|
111
90
|
protected render(): TemplateResult<1> {
|
91
|
+
const inputNoEdit = this.noEdit || this.disabled;
|
112
92
|
return html`
|
113
93
|
<label
|
114
94
|
part="root"
|
@@ -116,171 +96,127 @@ class Select extends Input {
|
|
116
96
|
>
|
117
97
|
${[
|
118
98
|
this._renderPrefix(),
|
99
|
+
this.noEdit
|
100
|
+
? html`
|
101
|
+
<input style="position: absolute;inset: 0;opacity: 0;" />
|
102
|
+
`
|
103
|
+
: "",
|
119
104
|
html`
|
120
105
|
<input
|
121
106
|
part="input"
|
122
|
-
type="${this.type}"
|
123
107
|
.value="${this.text}"
|
124
108
|
?autofocus="${this.autofocus}"
|
125
|
-
?disabled="${
|
109
|
+
?disabled="${inputNoEdit}"
|
126
110
|
autocapitalize="${this.autocapitalize || nothing}"
|
127
111
|
autocomplete="${this.autocomplete || nothing}"
|
128
112
|
placeholder="${this.placeholder || nothing}"
|
129
|
-
@
|
130
|
-
@
|
131
|
-
@change="${this._handleChange}"
|
113
|
+
@input="${inputNoEdit ? null : this._handleInput}"
|
114
|
+
@change="${inputNoEdit ? null : this._handleChange}"
|
132
115
|
/>
|
133
116
|
`,
|
134
117
|
this._renderSuffix(),
|
135
|
-
html`
|
136
|
-
<label
|
137
|
-
part="content"
|
138
|
-
direction-outset-place
|
139
|
-
>
|
140
|
-
${htmlSlot()}
|
141
|
-
</label>
|
142
|
-
`,
|
143
118
|
]}
|
119
|
+
<div
|
120
|
+
part="popover"
|
121
|
+
popover="${supportsPositionArea() ? "manual" : nothing}"
|
122
|
+
>
|
123
|
+
${htmlSlot()}
|
124
|
+
</div>
|
144
125
|
</label>
|
145
126
|
`;
|
146
127
|
}
|
147
128
|
|
148
129
|
protected _renderSuffix(): TemplateResult<1> {
|
149
130
|
return html`
|
150
|
-
<i part="suffix
|
131
|
+
<i part="suffix">${htmlSlot("suffix", svgCaretDown())}</i>
|
151
132
|
`;
|
152
133
|
}
|
153
134
|
|
154
|
-
protected _handleFocus(): void {
|
155
|
-
if (!this.direction) {
|
156
|
-
const { top, bottom } = this.getBoundingClientRect();
|
157
|
-
if (window.innerHeight - bottom < this._content.clientHeight && top > this._content.clientHeight) {
|
158
|
-
this.autoDirection = "top";
|
159
|
-
} else {
|
160
|
-
this.autoDirection = "bottom";
|
161
|
-
}
|
162
|
-
}
|
163
|
-
this.visible = true;
|
164
|
-
}
|
165
|
-
|
166
135
|
protected firstUpdated(): void {
|
167
|
-
this.events.add(this.
|
168
|
-
e.preventDefault();
|
169
|
-
e.stopPropagation();
|
136
|
+
this.events.add(this._slot, "click", (e: HandlerEvent<HTMLOptionElement>) => {
|
170
137
|
const { target } = e;
|
171
|
-
|
172
|
-
|
173
|
-
const operation = this.select(value, target.textContent);
|
174
|
-
if (!this.multiple) {
|
175
|
-
updateChecked(this.lastChecked, 0);
|
176
|
-
}
|
177
|
-
updateChecked(target, operation);
|
178
|
-
this.lastChecked = target;
|
138
|
+
if (target.tagName !== "OPTION") {
|
139
|
+
return;
|
179
140
|
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
const composed1 = e.composedPath()[0] as HTMLElement;
|
186
|
-
if (composed1 && !this.shadowRoot.contains(composed1)) {
|
187
|
-
this.blur();
|
141
|
+
const { label, value } = target;
|
142
|
+
const operation = this.select(value, label);
|
143
|
+
if (!this.multiple) {
|
144
|
+
updateSelected(this.lastChecked, 0);
|
145
|
+
this.hideOptions();
|
188
146
|
}
|
147
|
+
updateSelected(target, operation);
|
148
|
+
this.lastChecked = target;
|
189
149
|
});
|
190
150
|
}
|
191
151
|
|
192
152
|
protected _connectedInit(): void {
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
list.forEach((element: HTMLElement) => {
|
197
|
-
const operation = this.select(this.optionValue(element), element.textContent);
|
198
|
-
updateChecked(element, operation);
|
199
|
-
});
|
200
|
-
|
201
|
-
this.default = this.value;
|
202
|
-
this.defaultText = this.text;
|
203
|
-
this.defaultChecked = checked;
|
204
|
-
}
|
205
|
-
if (!this.text) {
|
206
|
-
this.text = "";
|
207
|
-
}
|
153
|
+
this.default = this.value ??= "";
|
154
|
+
this.defaultText = this.text ??= "";
|
155
|
+
this.events.add(this, "focus", this.showOptions);
|
208
156
|
}
|
209
157
|
|
210
158
|
reset(): void {
|
211
159
|
this.value = this.default;
|
212
160
|
this.text = this.defaultText;
|
213
|
-
this.querySelectorAll<HTMLElement>("[checked]").forEach((element) => updateChecked(element, 0));
|
214
|
-
this.defaultChecked.forEach((element) => updateChecked(element, 1));
|
215
161
|
}
|
216
162
|
|
217
|
-
select(value: string,
|
218
|
-
|
219
|
-
text = text.trim();
|
163
|
+
select(value: string, label: string): 0 | 1 {
|
164
|
+
label ||= value;
|
220
165
|
let operation: 0 | 1 = 0;
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
this.__store.splice(i, 1);
|
225
|
-
} else {
|
226
|
-
this.__store.push({ value, text });
|
227
|
-
operation = 1;
|
228
|
-
}
|
229
|
-
this.value = this.__store.map((s) => s.value);
|
230
|
-
this.text = this.__store.map((s) => s.text).join(", ");
|
166
|
+
const i = this.values.findIndex((s) => s.value === value);
|
167
|
+
if (i > -1) {
|
168
|
+
this.values.splice(i, 1);
|
231
169
|
} else {
|
232
|
-
|
233
|
-
|
234
|
-
this.text = "";
|
235
|
-
} else {
|
236
|
-
this.value = value;
|
237
|
-
this.text = text;
|
238
|
-
operation = 1;
|
239
|
-
}
|
170
|
+
this.values.push({ value, label });
|
171
|
+
operation = 1;
|
240
172
|
}
|
173
|
+
this.checkValues();
|
174
|
+
this.value = this.values.map((s) => s.value).join(",");
|
175
|
+
this.text = this.values.map((s) => s.label).join(", ");
|
241
176
|
this.dispatchCustomEvent("select", this.value);
|
242
|
-
this.filter();
|
243
177
|
return operation;
|
244
178
|
}
|
245
179
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
this.
|
250
|
-
|
251
|
-
!query || contain(this.optionValue(element), query) || contain(element.textContent, query),
|
252
|
-
query,
|
253
|
-
);
|
254
|
-
});
|
180
|
+
checkValues(): void {
|
181
|
+
if (!this.multiple && this.values.length > 1) {
|
182
|
+
this.values.splice(0, this.values.length - 1);
|
183
|
+
this.requestUpdate();
|
184
|
+
}
|
255
185
|
}
|
256
186
|
|
257
|
-
|
258
|
-
|
187
|
+
showOptions(): void {
|
188
|
+
if (this.optionsVisible) {
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
showPopover(this._popover);
|
192
|
+
const listener = (e) => {
|
193
|
+
if (!this.contains(e.target)) {
|
194
|
+
this.hideOptions();
|
195
|
+
this.events.remove(document, "click", listener);
|
196
|
+
}
|
197
|
+
};
|
198
|
+
this.events.add(document, "click", listener);
|
199
|
+
this.optionsVisible = true;
|
259
200
|
}
|
260
201
|
|
261
|
-
|
262
|
-
|
263
|
-
if (this.compositing) {
|
202
|
+
hideOptions(): void {
|
203
|
+
if (!this.optionsVisible) {
|
264
204
|
return;
|
265
205
|
}
|
266
|
-
|
267
|
-
this.
|
268
|
-
this.dispatchCustomEvent("input", this.value, { bubbles: true });
|
206
|
+
hidePopover(this._popover);
|
207
|
+
this.optionsVisible = false;
|
269
208
|
}
|
270
209
|
|
271
210
|
focus(options?: FocusOptions): void {
|
211
|
+
super.focus();
|
272
212
|
this._input.focus(options);
|
273
|
-
this.
|
213
|
+
this.showOptions();
|
274
214
|
}
|
275
215
|
|
276
216
|
blur(): void {
|
277
|
-
this._input.blur();
|
278
|
-
this.visible = false;
|
279
217
|
super.blur();
|
280
|
-
|
281
|
-
|
282
|
-
optionValue(option: HTMLElement): string {
|
283
|
-
return (option as any).value || option.getAttribute("value") || "";
|
218
|
+
this._input.blur();
|
219
|
+
hidePopover(this._popover);
|
284
220
|
}
|
285
221
|
}
|
286
222
|
|
@@ -4,7 +4,7 @@ import { property, state } from "lit/decorators.js";
|
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../../internal/global-style.js";
|
6
6
|
import { SuperInput } from "../../internal/super-input.js";
|
7
|
-
import { RingBuilder } from "../../internal/ring.js";
|
7
|
+
import { RingBuilder, ringTypeAttribute } from "../../internal/ring.js";
|
8
8
|
|
9
9
|
const protoName = "split";
|
10
10
|
const cssScope = scopePrefix(protoName);
|
@@ -97,7 +97,7 @@ class Split extends SuperInput {
|
|
97
97
|
}
|
98
98
|
|
99
99
|
get observedRecord(): Record<string, any> {
|
100
|
-
return omit(super.observedRecord,
|
100
|
+
return omit(super.observedRecord, ringTypeAttribute);
|
101
101
|
}
|
102
102
|
|
103
103
|
protected render(): TemplateResult<1> {
|
@@ -4,6 +4,7 @@ import { property } from "lit/decorators.js";
|
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../../internal/global-style.js";
|
6
6
|
import { SuperInput } from "../../internal/super-input.js";
|
7
|
+
import { ringTypeAttribute } from "../../internal/ring.js";
|
7
8
|
|
8
9
|
const protoName = "switch";
|
9
10
|
const cssScope = scopePrefix(protoName);
|
@@ -94,7 +95,7 @@ class Switch extends SuperInput<boolean> {
|
|
94
95
|
value = false;
|
95
96
|
|
96
97
|
get observedRecord(): Record<string, any> {
|
97
|
-
return omit(super.observedRecord,
|
98
|
+
return omit(super.observedRecord, ringTypeAttribute);
|
98
99
|
}
|
99
100
|
|
100
101
|
protected render(): TemplateResult<1> {
|