godown 3.12.0 → 3.13.1
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 +5 -5
- package/build/godown.iife.js.map +1 -1
- package/build/godown.js +5 -5
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +5 -5
- 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 -1
- 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 +2 -3
- 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 +7 -35
- 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 -2
- package/src/internal/utils.ts +10 -0
- package/src/popover.ts +1 -0
- package/src/web-components/alert/component.ts +8 -15
- package/src/web-components/avatar/component.ts +1 -0
- package/src/web-components/button/component.ts +6 -10
- package/src/web-components/card/component.ts +4 -4
- package/src/web-components/chip/component.ts +1 -3
- package/src/web-components/details/component.ts +27 -16
- package/src/web-components/dialog/component.ts +50 -67
- package/src/web-components/heading/component.ts +0 -1
- package/src/web-components/input/component.ts +5 -7
- 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 +110 -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 +100 -101
- package/src/web-components/tooltip/component.ts +44 -112
- 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.map +1 -1
- package/web-components/input/component.js +1 -1
- package/web-components/input/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/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
@@ -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;
|
95
76
|
|
96
|
-
@
|
97
|
-
|
77
|
+
@property({ type: Array })
|
78
|
+
values: {
|
79
|
+
value: string;
|
80
|
+
label?: string;
|
81
|
+
}[] = [];
|
82
|
+
|
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,128 @@ 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
|
-
|
186
|
-
if (composed1 && !this.shadowRoot.contains(composed1)) {
|
187
|
-
this.blur();
|
141
|
+
e.preventDefault();
|
142
|
+
const { label, value } = target;
|
143
|
+
const operation = this.select(value, label);
|
144
|
+
if (!this.multiple) {
|
145
|
+
updateSelected(this.lastChecked, 0);
|
146
|
+
this.hideOptions();
|
188
147
|
}
|
148
|
+
updateSelected(target, operation);
|
149
|
+
this.lastChecked = target;
|
189
150
|
});
|
190
151
|
}
|
191
152
|
|
192
153
|
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
|
-
}
|
154
|
+
this.default = this.value ??= "";
|
155
|
+
this.defaultText = this.text ??= "";
|
156
|
+
this.events.add(this, "focus", this.showOptions);
|
208
157
|
}
|
209
158
|
|
210
159
|
reset(): void {
|
211
160
|
this.value = this.default;
|
212
161
|
this.text = this.defaultText;
|
213
|
-
this.querySelectorAll<HTMLElement>("[checked]").forEach((element) => updateChecked(element, 0));
|
214
|
-
this.defaultChecked.forEach((element) => updateChecked(element, 1));
|
215
162
|
}
|
216
163
|
|
217
|
-
select(value: string,
|
218
|
-
|
219
|
-
text = text.trim();
|
164
|
+
select(value: string, label: string): 0 | 1 {
|
165
|
+
label ||= value;
|
220
166
|
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(", ");
|
167
|
+
const i = this.values.findIndex((s) => s.value === value);
|
168
|
+
if (i > -1) {
|
169
|
+
this.values.splice(i, 1);
|
231
170
|
} else {
|
232
|
-
|
233
|
-
|
234
|
-
this.text = "";
|
235
|
-
} else {
|
236
|
-
this.value = value;
|
237
|
-
this.text = text;
|
238
|
-
operation = 1;
|
239
|
-
}
|
171
|
+
this.values.push({ value, label });
|
172
|
+
operation = 1;
|
240
173
|
}
|
174
|
+
this.checkValues();
|
175
|
+
this.value = this.values.map((s) => s.value).join(",");
|
176
|
+
this.text = this.values.map((s) => s.label).join(", ");
|
241
177
|
this.dispatchCustomEvent("select", this.value);
|
242
|
-
this.filter();
|
243
178
|
return operation;
|
244
179
|
}
|
245
180
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
this.
|
250
|
-
|
251
|
-
!query || contain(this.optionValue(element), query) || contain(element.textContent, query),
|
252
|
-
query,
|
253
|
-
);
|
254
|
-
});
|
181
|
+
checkValues(): void {
|
182
|
+
if (!this.multiple && this.values.length > 1) {
|
183
|
+
this.values.splice(0, this.values.length - 1);
|
184
|
+
this.requestUpdate();
|
185
|
+
}
|
255
186
|
}
|
256
187
|
|
257
|
-
|
258
|
-
|
188
|
+
showOptions(): void {
|
189
|
+
if (this.optionsVisible) {
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
showPopover(this._popover);
|
193
|
+
const listener = (e) => {
|
194
|
+
if (!this.contains(e.target)) {
|
195
|
+
this.hideOptions();
|
196
|
+
this.events.remove(document, "click", listener);
|
197
|
+
}
|
198
|
+
};
|
199
|
+
this.events.add(document, "click", listener);
|
200
|
+
this.optionsVisible = true;
|
259
201
|
}
|
260
202
|
|
261
|
-
|
262
|
-
|
263
|
-
if (this.compositing) {
|
203
|
+
hideOptions(): void {
|
204
|
+
if (!this.optionsVisible) {
|
264
205
|
return;
|
265
206
|
}
|
266
|
-
|
267
|
-
this.
|
268
|
-
this.dispatchCustomEvent("input", this.value, { bubbles: true });
|
207
|
+
hidePopover(this._popover);
|
208
|
+
this.optionsVisible = false;
|
269
209
|
}
|
270
210
|
|
271
211
|
focus(options?: FocusOptions): void {
|
212
|
+
super.focus();
|
272
213
|
this._input.focus(options);
|
273
|
-
this.
|
214
|
+
this.showOptions();
|
274
215
|
}
|
275
216
|
|
276
217
|
blur(): void {
|
277
|
-
this._input.blur();
|
278
|
-
this.visible = false;
|
279
218
|
super.blur();
|
280
|
-
|
281
|
-
|
282
|
-
optionValue(option: HTMLElement): string {
|
283
|
-
return (option as any).value || option.getAttribute("value") || "";
|
219
|
+
this._input.blur();
|
220
|
+
hidePopover(this._popover);
|
284
221
|
}
|
285
222
|
}
|
286
223
|
|
@@ -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> {
|