@vollowx/seele 0.13.5 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +1256 -115
- package/package.json +22 -14
- package/src/all.d.ts +34 -0
- package/src/base/autocomplete.d.ts +56 -0
- package/src/base/autocomplete.js +75 -87
- package/src/base/button.d.ts +13 -0
- package/src/base/button.js +21 -19
- package/src/base/checkbox.d.ts +18 -0
- package/src/base/checkbox.js +39 -34
- package/src/base/controllers/list-controller.d.ts +37 -0
- package/src/base/controllers/list-controller.js +23 -15
- package/src/base/controllers/popover-controller.d.ts +35 -0
- package/src/base/controllers/popover-controller.js +37 -29
- package/src/base/dialog.d.ts +20 -0
- package/src/base/dialog.js +11 -9
- package/src/base/field.d.ts +3 -0
- package/src/base/input.d.ts +44 -0
- package/src/base/input.js +57 -65
- package/src/base/item.d.ts +7 -0
- package/src/base/item.js +2 -1
- package/src/base/list-item.d.ts +15 -0
- package/src/base/list-item.js +22 -22
- package/src/base/list.d.ts +54 -0
- package/src/base/list.js +69 -55
- package/src/base/menu-item.d.ts +6 -0
- package/src/base/menu-item.js +4 -3
- package/src/base/menu.d.ts +76 -0
- package/src/base/menu.js +135 -143
- package/src/base/mixins/attachable.d.ts +9 -0
- package/src/base/mixins/attachable.js +22 -18
- package/src/base/mixins/focus-delegated.d.ts +5 -0
- package/src/base/mixins/focus-delegated.js +6 -8
- package/src/base/mixins/form-associated.d.ts +15 -0
- package/src/base/mixins/form-associated.js +11 -18
- package/src/base/mixins/internals-attached.d.ts +6 -0
- package/src/base/mixins/internals-attached.js +1 -1
- package/src/base/option.d.ts +9 -0
- package/src/base/option.js +7 -8
- package/src/base/radio.d.ts +13 -0
- package/src/base/radio.js +49 -42
- package/src/base/select.d.ts +116 -0
- package/src/base/select.js +130 -128
- package/src/base/slider.d.ts +75 -0
- package/src/base/slider.js +115 -118
- package/src/base/tab-panel.d.ts +9 -0
- package/src/base/tab-panel.js +11 -11
- package/src/base/tab.d.ts +18 -0
- package/src/base/tab.js +25 -24
- package/src/base/tabs.d.ts +19 -0
- package/src/base/tabs.js +84 -81
- package/src/base/toggle-button.d.ts +47 -0
- package/src/base/toggle-button.js +56 -52
- package/src/base/tooltip.d.ts +37 -0
- package/src/base/tooltip.js +70 -65
- package/src/core/decorators.d.ts +2 -0
- package/src/core/decorators.js +4 -3
- package/src/core/focus-visible.d.ts +2 -0
- package/src/core/focus-visible.js +4 -4
- package/src/core/shared.d.ts +1 -0
- package/src/core/unique-id.d.ts +4 -0
- package/src/core/unique-id.js +2 -1
- package/src/m3/autocomplete/autocomplete.d.ts +8 -0
- package/src/m3/autocomplete/autocomplete.js +10 -10
- package/src/m3/badge/badge.d.ts +12 -0
- package/src/m3/badge/badge.js +24 -37
- package/src/m3/button/common-button-toggle.d.ts +31 -0
- package/src/m3/button/common-button-toggle.js +44 -41
- package/src/m3/button/common-button.d.ts +29 -0
- package/src/m3/button/common-button.js +40 -40
- package/src/m3/button/icon-button-toggle.d.ts +24 -0
- package/src/m3/button/icon-button-toggle.js +35 -32
- package/src/m3/button/icon-button.d.ts +23 -0
- package/src/m3/button/icon-button.js +33 -31
- package/src/m3/button-group/connected-button-group.d.ts +19 -0
- package/src/m3/button-group/connected-button-group.js +26 -24
- package/src/m3/button-group/standard-button-group.d.ts +24 -0
- package/src/m3/button-group/standard-button-group.js +71 -65
- package/src/m3/checkbox/checkbox.d.ts +25 -0
- package/src/m3/checkbox/checkbox.js +23 -22
- package/src/m3/dialog/dialog-spring.d.ts +45 -0
- package/src/m3/dialog/dialog-spring.js +83 -86
- package/src/m3/dialog/dialog.d.ts +46 -0
- package/src/m3/dialog/dialog.js +90 -117
- package/src/m3/divider/divider.d.ts +13 -0
- package/src/m3/divider/divider.js +20 -33
- package/src/m3/fab/fab.d.ts +23 -0
- package/src/m3/fab/fab.js +24 -23
- package/src/m3/field/field.d.ts +28 -0
- package/src/m3/field/field.js +40 -55
- package/src/m3/field/filled-field.d.ts +11 -0
- package/src/m3/field/filled-field.js +7 -11
- package/src/m3/field/outlined-field.d.ts +11 -0
- package/src/m3/field/outlined-field.js +8 -12
- package/src/m3/focus-ring/focus-ring.d.ts +32 -0
- package/src/m3/focus-ring/focus-ring.js +38 -23
- package/src/m3/item/item.d.ts +31 -0
- package/src/m3/item/item.js +32 -17
- package/src/m3/list/list-item.d.ts +22 -0
- package/src/m3/list/list-item.js +18 -16
- package/src/m3/list/list.d.ts +15 -0
- package/src/m3/list/list.js +16 -15
- package/src/m3/loading-indicator/loading-indicator.d.ts +26 -0
- package/src/m3/loading-indicator/loading-indicator.js +113 -161
- package/src/m3/menu/menu-item.d.ts +15 -0
- package/src/m3/menu/menu-item.js +10 -4
- package/src/m3/menu/menu.d.ts +22 -0
- package/src/m3/menu/menu.js +20 -18
- package/src/m3/radio/radio-styles.css.js +1 -1
- package/src/m3/radio/radio.d.ts +17 -0
- package/src/m3/radio/radio.js +22 -11
- package/src/m3/ripple/ripple.d.ts +43 -0
- package/src/m3/ripple/ripple.js +82 -89
- package/src/m3/select/filled-select.d.ts +16 -0
- package/src/m3/select/filled-select.js +12 -10
- package/src/m3/select/option.d.ts +15 -0
- package/src/m3/select/option.js +10 -4
- package/src/m3/select/outlined-select.d.ts +16 -0
- package/src/m3/select/outlined-select.js +12 -10
- package/src/m3/select/select.d.ts +13 -0
- package/src/m3/select/select.js +16 -16
- package/src/m3/slider/slider.d.ts +20 -0
- package/src/m3/slider/slider.js +32 -26
- package/src/m3/switch/switch.d.ts +27 -0
- package/src/m3/switch/switch.js +62 -53
- package/src/m3/system/motion.d.ts +12 -0
- package/src/m3/system/motion.js +16 -9
- package/src/m3/tab/tab-panel.d.ts +9 -0
- package/src/m3/tab/tab-panel.js +6 -9
- package/src/m3/tab/tab.d.ts +19 -0
- package/src/m3/tab/tab.js +14 -12
- package/src/m3/tab/tabs.d.ts +25 -0
- package/src/m3/tab/tabs.js +34 -30
- package/src/m3/text-field/filled-text-field.d.ts +13 -0
- package/src/m3/text-field/filled-text-field.js +15 -20
- package/src/m3/text-field/outlined-text-field.d.ts +13 -0
- package/src/m3/text-field/outlined-text-field.js +15 -20
- package/src/m3/toolbar/toolbar.d.ts +26 -0
- package/src/m3/toolbar/toolbar.js +28 -25
- package/src/m3/tooltip/tooltip.d.ts +19 -0
- package/src/m3/tooltip/tooltip.js +15 -14
- package/src/win98/button/button.d.ts +13 -0
- package/src/win98/button/button.js +13 -11
- package/src/win98/button/radio.d.ts +3 -0
- package/src/win98/button/radio.js +5 -4
- package/src/win98/radio/radio.d.ts +3 -0
- package/src/win98/radio/radio.js +5 -4
package/src/base/tabs.js
CHANGED
|
@@ -1,83 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import { LitElement, html } from 'lit';
|
|
3
3
|
import { property, queryAssignedElements } from 'lit/decorators.js';
|
|
4
4
|
import { internals } from './mixins/internals-attached.js';
|
|
5
5
|
/**
|
|
6
6
|
* @fires {CustomEvent} tab-select
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return html`<div part="tablist" role="tablist"><slot @slotchange="${this.#handleSlotChange}"></slot></div>`;
|
|
16
|
-
}
|
|
17
|
-
connectedCallback() {
|
|
18
|
-
super.connectedCallback();
|
|
19
|
-
this.addEventListener('keydown', this.#handleKeyDown.bind(this));
|
|
20
|
-
this.addEventListener('click', this.#handleClick.bind(this));
|
|
21
|
-
}
|
|
22
|
-
updated(changed) {
|
|
23
|
-
if (changed.has('selected') && this.selected) {
|
|
24
|
-
const targetTab = this.$tabs.find((t)=>t.value === this.selected);
|
|
25
|
-
if (targetTab && !targetTab.selected) {
|
|
26
|
-
this.selectTab(targetTab);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
#handleSlotChange;
|
|
31
|
-
#handleKeyDown;
|
|
32
|
-
#handleClick;
|
|
33
|
-
focusTab(tab) {
|
|
34
|
-
this.$tabs.forEach((t)=>{
|
|
35
|
-
t.blur();
|
|
36
|
-
t.tabIndex = -1;
|
|
37
|
-
});
|
|
38
|
-
tab.tabIndex = 0;
|
|
39
|
-
tab.focus();
|
|
40
|
-
}
|
|
41
|
-
selectTab(selectedTab) {
|
|
42
|
-
this.selected = selectedTab.value;
|
|
43
|
-
const parent = this.$parent;
|
|
44
|
-
const panels = Array.from(parent.querySelectorAll('[seele-base="tabpanel"]'));
|
|
45
|
-
this.$tabs.forEach((tab)=>{
|
|
46
|
-
tab.selected = tab === selectedTab;
|
|
47
|
-
tab.tabIndex = tab === selectedTab ? 0 : -1;
|
|
48
|
-
});
|
|
49
|
-
panels.forEach((panel)=>{
|
|
50
|
-
if (panel.value && selectedTab.value) {
|
|
51
|
-
panel.hidden = panel.value !== selectedTab.value;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this.dispatchEvent(new CustomEvent('tab-select', {
|
|
55
|
-
detail: {
|
|
56
|
-
tab: selectedTab,
|
|
57
|
-
value: this.selected
|
|
58
|
-
},
|
|
59
|
-
bubbles: true,
|
|
60
|
-
composed: true
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
constructor(...args){
|
|
64
|
-
super(...args), this._role = 'tablist', this.switch = 'manual', this.selected = '', this.#handleSlotChange = (_)=>{
|
|
7
|
+
*/
|
|
8
|
+
export class Tabs extends LitElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this._role = 'tablist';
|
|
12
|
+
this.switch = 'manual';
|
|
13
|
+
this.selected = '';
|
|
14
|
+
this.#handleSlotChange = (_) => {
|
|
65
15
|
const parent = this.$parent;
|
|
66
|
-
this.$tabs.forEach((tab)=>{
|
|
16
|
+
this.$tabs.forEach((tab) => {
|
|
67
17
|
const panel = parent.querySelector(`[seele-base="tab"][value="${tab.value}"]`);
|
|
68
|
-
if (!panel)
|
|
18
|
+
if (!panel)
|
|
19
|
+
console.error('[seele] cannot find a matching panel for tab ', tab);
|
|
69
20
|
// TODO: ariaLabelledByElements
|
|
70
21
|
tab.setAttribute('aria-controls', panel.id);
|
|
71
22
|
panel.setAttribute('aria-labelledby', tab.id);
|
|
72
23
|
});
|
|
73
|
-
}
|
|
24
|
+
};
|
|
25
|
+
this.#handleKeyDown = (event) => {
|
|
74
26
|
const tabs = this.$tabs;
|
|
75
|
-
if (!tabs.length)
|
|
76
|
-
|
|
77
|
-
const
|
|
27
|
+
if (!tabs.length)
|
|
28
|
+
return;
|
|
29
|
+
const activeElement = this.getRootNode()
|
|
30
|
+
.activeElement;
|
|
31
|
+
const currentIndex = tabs.findIndex((t) => t === activeElement || t.focused);
|
|
78
32
|
let nextIndex = currentIndex !== -1 ? currentIndex : 0;
|
|
79
33
|
let handled = false;
|
|
80
|
-
switch(event.key){
|
|
34
|
+
switch (event.key) {
|
|
81
35
|
case 'ArrowLeft':
|
|
82
36
|
nextIndex = currentIndex <= 0 ? tabs.length - 1 : currentIndex - 1;
|
|
83
37
|
handled = true;
|
|
@@ -107,10 +61,12 @@ import { internals } from './mixins/internals-attached.js';
|
|
|
107
61
|
event.stopPropagation();
|
|
108
62
|
if (event.key !== 'Enter' && event.key !== ' ') {
|
|
109
63
|
this.focusTab(tabs[nextIndex]);
|
|
110
|
-
if (this.switch === 'auto')
|
|
64
|
+
if (this.switch === 'auto')
|
|
65
|
+
this.selectTab(tabs[nextIndex]);
|
|
111
66
|
}
|
|
112
67
|
}
|
|
113
|
-
}
|
|
68
|
+
};
|
|
69
|
+
this.#handleClick = (event) => {
|
|
114
70
|
const target = event.target;
|
|
115
71
|
const tab = target.closest('md-tab');
|
|
116
72
|
if (tab && this.$tabs.includes(tab)) {
|
|
@@ -119,20 +75,67 @@ import { internals } from './mixins/internals-attached.js';
|
|
|
119
75
|
}
|
|
120
76
|
};
|
|
121
77
|
}
|
|
78
|
+
get $tabs() {
|
|
79
|
+
return this.$slotItems.filter((item) => item[internals].role === 'tab');
|
|
80
|
+
}
|
|
81
|
+
get $parent() {
|
|
82
|
+
return this.parentNode instanceof ShadowRoot
|
|
83
|
+
? this.parentNode.host
|
|
84
|
+
: this.parentElement;
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
return html `<div part="tablist" role="tablist"><slot @slotchange="${this.#handleSlotChange}"></slot></div>`;
|
|
88
|
+
}
|
|
89
|
+
connectedCallback() {
|
|
90
|
+
super.connectedCallback();
|
|
91
|
+
this.addEventListener('keydown', this.#handleKeyDown.bind(this));
|
|
92
|
+
this.addEventListener('click', this.#handleClick.bind(this));
|
|
93
|
+
}
|
|
94
|
+
updated(changed) {
|
|
95
|
+
if (changed.has('selected') && this.selected) {
|
|
96
|
+
const targetTab = this.$tabs.find((t) => t.value === this.selected);
|
|
97
|
+
if (targetTab && !targetTab.selected) {
|
|
98
|
+
this.selectTab(targetTab);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
#handleSlotChange;
|
|
103
|
+
#handleKeyDown;
|
|
104
|
+
#handleClick;
|
|
105
|
+
focusTab(tab) {
|
|
106
|
+
this.$tabs.forEach((t) => {
|
|
107
|
+
t.blur();
|
|
108
|
+
t.tabIndex = -1;
|
|
109
|
+
});
|
|
110
|
+
tab.tabIndex = 0;
|
|
111
|
+
tab.focus();
|
|
112
|
+
}
|
|
113
|
+
selectTab(selectedTab) {
|
|
114
|
+
this.selected = selectedTab.value;
|
|
115
|
+
const parent = this.$parent;
|
|
116
|
+
const panels = Array.from(parent.querySelectorAll('[seele-base="tabpanel"]'));
|
|
117
|
+
this.$tabs.forEach((tab) => {
|
|
118
|
+
tab.selected = tab === selectedTab;
|
|
119
|
+
tab.tabIndex = tab === selectedTab ? 0 : -1;
|
|
120
|
+
});
|
|
121
|
+
panels.forEach((panel) => {
|
|
122
|
+
if (panel.value && selectedTab.value) {
|
|
123
|
+
panel.hidden = panel.value !== selectedTab.value;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
this.dispatchEvent(new CustomEvent('tab-select', {
|
|
127
|
+
detail: { tab: selectedTab, value: this.selected },
|
|
128
|
+
bubbles: true,
|
|
129
|
+
composed: true,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
122
132
|
}
|
|
123
|
-
|
|
124
|
-
property({
|
|
125
|
-
type: String
|
|
126
|
-
})
|
|
133
|
+
__decorate([
|
|
134
|
+
property({ type: String })
|
|
127
135
|
], Tabs.prototype, "switch", void 0);
|
|
128
|
-
|
|
129
|
-
property({
|
|
130
|
-
type: String,
|
|
131
|
-
reflect: true
|
|
132
|
-
})
|
|
136
|
+
__decorate([
|
|
137
|
+
property({ type: String, reflect: true })
|
|
133
138
|
], Tabs.prototype, "selected", void 0);
|
|
134
|
-
|
|
135
|
-
queryAssignedElements({
|
|
136
|
-
flatten: true
|
|
137
|
-
})
|
|
139
|
+
__decorate([
|
|
140
|
+
queryAssignedElements({ flatten: true })
|
|
138
141
|
], Tabs.prototype, "$slotItems", void 0);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
declare const Base: Constructor<import("./mixins/form-associated.js").FormAssociatedInterface> & Constructor<import("./mixins/internals-attached.js").InternalsAttachedInterface> & typeof LitElement;
|
|
3
|
+
export declare class ToggleButton extends Base {
|
|
4
|
+
#private;
|
|
5
|
+
static styles: any[];
|
|
6
|
+
checked: boolean;
|
|
7
|
+
constructor();
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
disconnectedCallback(): void;
|
|
10
|
+
protected updated(changed: Map<string, any>): void;
|
|
11
|
+
protected _updateInternals(): void;
|
|
12
|
+
/**
|
|
13
|
+
* --> Drag-and-drop to the other side
|
|
14
|
+
*
|
|
15
|
+
* `checked` is supposed to be changed once
|
|
16
|
+
*
|
|
17
|
+
* 1. `pointerdown`: _ignoreClick = false
|
|
18
|
+
* 2. `pointermove`: _ignoreClick = true
|
|
19
|
+
* 3. `pointerup`: `checked` changed
|
|
20
|
+
* 4. `click`: ignored, _ignoreClick = false
|
|
21
|
+
*
|
|
22
|
+
* --> Drag-and-drop to the other side, then click
|
|
23
|
+
*
|
|
24
|
+
* `checked` is supposed to be changed twice
|
|
25
|
+
*
|
|
26
|
+
* 1. `pointerdown`: _ignoreClick = false
|
|
27
|
+
* 2. `pointermove`: _ignoreClick = true
|
|
28
|
+
* 3. `pointerup`: `checked` changed(1)
|
|
29
|
+
* 4. `click`: ignored, _ignoreClick = false
|
|
30
|
+
* 5. `click`: `checked` changed(2)
|
|
31
|
+
*
|
|
32
|
+
* --> Drag-and-drop to the other side, then click the label
|
|
33
|
+
*
|
|
34
|
+
* `checked` is supposed to be changed twice
|
|
35
|
+
*
|
|
36
|
+
* 1. `pointerdown`: _ignoreClick = false
|
|
37
|
+
* 2. `pointermove`: _ignoreClick = true
|
|
38
|
+
* 3. `pointerup`: `checked` changed(1)
|
|
39
|
+
* 4. `click` on label: _ignoreClick = false
|
|
40
|
+
* 5. `click` on switch: `checked` changed(2)
|
|
41
|
+
*/
|
|
42
|
+
protected _ignoreClick: boolean;
|
|
43
|
+
protected toggleChecked(): void;
|
|
44
|
+
formResetCallback(): void;
|
|
45
|
+
formStateRestoreCallback(state: string, _reason: string): void;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import { LitElement } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { InternalsAttached, internals } from './mixins/internals-attached.js';
|
|
@@ -6,48 +6,49 @@ import { FormAssociated } from './mixins/form-associated.js';
|
|
|
6
6
|
import { hiddenStyles } from './hidden-styles.css.js';
|
|
7
7
|
const PROPERTY_FROM_ARIA_PRESSED = {
|
|
8
8
|
true: 'checked',
|
|
9
|
-
false: 'unchecked'
|
|
9
|
+
false: 'unchecked',
|
|
10
10
|
};
|
|
11
11
|
const Base = FormAssociated(InternalsAttached(LitElement));
|
|
12
12
|
export class ToggleButton extends Base {
|
|
13
|
-
static{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
13
|
+
static { this.styles = [hiddenStyles]; }
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.checked = false;
|
|
17
|
+
/**
|
|
18
|
+
* --> Drag-and-drop to the other side
|
|
19
|
+
*
|
|
20
|
+
* `checked` is supposed to be changed once
|
|
21
|
+
*
|
|
22
|
+
* 1. `pointerdown`: _ignoreClick = false
|
|
23
|
+
* 2. `pointermove`: _ignoreClick = true
|
|
24
|
+
* 3. `pointerup`: `checked` changed
|
|
25
|
+
* 4. `click`: ignored, _ignoreClick = false
|
|
26
|
+
*
|
|
27
|
+
* --> Drag-and-drop to the other side, then click
|
|
28
|
+
*
|
|
29
|
+
* `checked` is supposed to be changed twice
|
|
30
|
+
*
|
|
31
|
+
* 1. `pointerdown`: _ignoreClick = false
|
|
32
|
+
* 2. `pointermove`: _ignoreClick = true
|
|
33
|
+
* 3. `pointerup`: `checked` changed(1)
|
|
34
|
+
* 4. `click`: ignored, _ignoreClick = false
|
|
35
|
+
* 5. `click`: `checked` changed(2)
|
|
36
|
+
*
|
|
37
|
+
* --> Drag-and-drop to the other side, then click the label
|
|
38
|
+
*
|
|
39
|
+
* `checked` is supposed to be changed twice
|
|
40
|
+
*
|
|
41
|
+
* 1. `pointerdown`: _ignoreClick = false
|
|
42
|
+
* 2. `pointermove`: _ignoreClick = true
|
|
43
|
+
* 3. `pointerup`: `checked` changed(1)
|
|
44
|
+
* 4. `click` on label: _ignoreClick = false
|
|
45
|
+
* 5. `click` on switch: `checked` changed(2)
|
|
46
|
+
*/
|
|
47
|
+
this._ignoreClick = false;
|
|
48
|
+
this.#handleLabelClick = () => {
|
|
49
49
|
this._ignoreClick = false;
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
|
+
this.#handleClick = (e) => {
|
|
51
52
|
e.stopPropagation();
|
|
52
53
|
e.preventDefault();
|
|
53
54
|
if (this._ignoreClick) {
|
|
@@ -55,12 +56,16 @@ export class ToggleButton extends Base {
|
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
this.toggleChecked();
|
|
58
|
-
}
|
|
59
|
-
|
|
59
|
+
};
|
|
60
|
+
this.#handleKeyDown = (e) => {
|
|
61
|
+
if (e.key !== ' ' && e.key !== 'Enter')
|
|
62
|
+
return;
|
|
60
63
|
e.preventDefault();
|
|
61
64
|
e.stopPropagation();
|
|
62
|
-
if (e.key === 'Enter')
|
|
63
|
-
|
|
65
|
+
if (e.key === 'Enter')
|
|
66
|
+
this.toggleChecked();
|
|
67
|
+
};
|
|
68
|
+
this.#handleKeyUp = (e) => {
|
|
64
69
|
if (e.key === ' ') {
|
|
65
70
|
e.preventDefault();
|
|
66
71
|
e.stopPropagation();
|
|
@@ -77,16 +82,16 @@ export class ToggleButton extends Base {
|
|
|
77
82
|
this.addEventListener('click', this.#handleClick);
|
|
78
83
|
this.addEventListener('keydown', this.#handleKeyDown);
|
|
79
84
|
this.addEventListener('keyup', this.#handleKeyUp);
|
|
80
|
-
this.labels.forEach((label)=>{
|
|
85
|
+
this.labels.forEach((label) => {
|
|
81
86
|
label.addEventListener('click', this.#handleLabelClick);
|
|
82
87
|
});
|
|
83
|
-
requestAnimationFrame(()=>requestAnimationFrame(()=>this.removeAttribute('notransition')));
|
|
88
|
+
requestAnimationFrame(() => requestAnimationFrame(() => this.removeAttribute('notransition')));
|
|
84
89
|
}
|
|
85
90
|
disconnectedCallback() {
|
|
86
91
|
this.removeEventListener('click', this.#handleClick);
|
|
87
92
|
this.removeEventListener('keydown', this.#handleKeyDown);
|
|
88
93
|
this.removeEventListener('keyup', this.#handleKeyUp);
|
|
89
|
-
this.labels.forEach((label)=>{
|
|
94
|
+
this.labels.forEach((label) => {
|
|
90
95
|
label.removeEventListener('click', this.#handleLabelClick);
|
|
91
96
|
});
|
|
92
97
|
super.disconnectedCallback();
|
|
@@ -110,12 +115,13 @@ export class ToggleButton extends Base {
|
|
|
110
115
|
#handleKeyDown;
|
|
111
116
|
#handleKeyUp;
|
|
112
117
|
toggleChecked() {
|
|
113
|
-
if (this.disabled)
|
|
118
|
+
if (this.disabled)
|
|
119
|
+
return;
|
|
114
120
|
this.checked = !this.checked;
|
|
115
121
|
this.dispatchEvent(new CustomEvent('change', {
|
|
116
122
|
bubbles: true,
|
|
117
123
|
composed: true,
|
|
118
|
-
detail: this.checked
|
|
124
|
+
detail: this.checked,
|
|
119
125
|
}));
|
|
120
126
|
}
|
|
121
127
|
formResetCallback() {
|
|
@@ -125,8 +131,6 @@ export class ToggleButton extends Base {
|
|
|
125
131
|
this.checked = state === 'on';
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
|
-
|
|
129
|
-
property({
|
|
130
|
-
type: Boolean
|
|
131
|
-
})
|
|
134
|
+
__decorate([
|
|
135
|
+
property({ type: Boolean })
|
|
132
136
|
], ToggleButton.prototype, "checked", void 0);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
declare const Base: Constructor<import("./mixins/attachable.js").AttachableInterface> & Constructor<import("./mixins/internals-attached.js").InternalsAttachedInterface> & typeof LitElement;
|
|
3
|
+
/**
|
|
4
|
+
* TODO: Check if $control controls a menu/popover and keep hidden when it is open.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Tooltip extends Base {
|
|
7
|
+
#private;
|
|
8
|
+
readonly _delays: {
|
|
9
|
+
mouse: {
|
|
10
|
+
show: number;
|
|
11
|
+
hide: number;
|
|
12
|
+
};
|
|
13
|
+
focus: {
|
|
14
|
+
show: number;
|
|
15
|
+
hide: number;
|
|
16
|
+
};
|
|
17
|
+
touch: {
|
|
18
|
+
show: number;
|
|
19
|
+
hide: number;
|
|
20
|
+
};
|
|
21
|
+
recentlyShowed: number;
|
|
22
|
+
};
|
|
23
|
+
readonly _durations: {
|
|
24
|
+
show: number;
|
|
25
|
+
hide: number;
|
|
26
|
+
};
|
|
27
|
+
align: import('@floating-ui/dom').Placement;
|
|
28
|
+
offset: number;
|
|
29
|
+
forceInvisible: boolean;
|
|
30
|
+
$slot: HTMLSlotElement;
|
|
31
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
32
|
+
private readonly popoverController;
|
|
33
|
+
constructor();
|
|
34
|
+
handleControlChange(prev?: HTMLElement | null, next?: HTMLElement | null): void;
|
|
35
|
+
set visible(value: boolean);
|
|
36
|
+
}
|
|
37
|
+
export {};
|
package/src/base/tooltip.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import { LitElement, html } from 'lit';
|
|
3
3
|
import { property, query } from 'lit/decorators.js';
|
|
4
4
|
import { focusVisible } from '../core/focus-visible.js';
|
|
@@ -9,66 +9,76 @@ let lastHidingTime = 0;
|
|
|
9
9
|
const Base = Attachable(InternalsAttached(LitElement));
|
|
10
10
|
/**
|
|
11
11
|
* TODO: Check if $control controls a menu/popover and keep hidden when it is open.
|
|
12
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
export class Tooltip extends Base {
|
|
13
14
|
render() {
|
|
14
|
-
return html`<slot @slotchange="${this.#handleSlotChange}"></slot>`;
|
|
15
|
+
return html `<slot @slotchange="${this.#handleSlotChange}"></slot>`;
|
|
15
16
|
}
|
|
16
17
|
// Different from those in the popoverController, these timers are used to
|
|
17
18
|
// manage the delay before showing/hiding the tooltip.
|
|
18
19
|
#openTimer;
|
|
19
20
|
#closeTimer;
|
|
20
|
-
constructor(){
|
|
21
|
-
super()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
popover: ()=>this,
|
|
40
|
-
trigger: ()=>this.$control,
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
this._delays = {
|
|
24
|
+
mouse: { show: 500, hide: 0 },
|
|
25
|
+
focus: { show: 100, hide: 0 },
|
|
26
|
+
touch: { show: 700, hide: 1500 },
|
|
27
|
+
recentlyShowed: 800,
|
|
28
|
+
};
|
|
29
|
+
this._durations = { show: 100, hide: 100 };
|
|
30
|
+
this.align = 'top';
|
|
31
|
+
this.offset = 4;
|
|
32
|
+
this.forceInvisible = false;
|
|
33
|
+
// Different from those in the popoverController, these timers are used to
|
|
34
|
+
// manage the delay before showing/hiding the tooltip.
|
|
35
|
+
this.#openTimer = null;
|
|
36
|
+
this.#closeTimer = null;
|
|
37
|
+
this.popoverController = new PopoverController(this, {
|
|
38
|
+
popover: () => this,
|
|
39
|
+
trigger: () => this.$control,
|
|
41
40
|
positioning: {
|
|
42
|
-
placement: ()=>this.align,
|
|
43
|
-
strategy: ()=>'absolute',
|
|
44
|
-
offset: ()=>this.offset,
|
|
45
|
-
windowPadding: ()=>16
|
|
41
|
+
placement: () => this.align,
|
|
42
|
+
strategy: () => 'absolute',
|
|
43
|
+
offset: () => this.offset,
|
|
44
|
+
windowPadding: () => 16,
|
|
46
45
|
},
|
|
47
46
|
durations: {
|
|
48
|
-
open: ()=>this._durations.show,
|
|
49
|
-
close: ()=>this._durations.hide
|
|
47
|
+
open: () => this._durations.show,
|
|
48
|
+
close: () => this._durations.hide,
|
|
50
49
|
},
|
|
51
|
-
onClickAway: ()=>{
|
|
50
|
+
onClickAway: () => {
|
|
52
51
|
this.visible = false;
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
this.#handleSlotChange = () => {
|
|
55
|
+
if (!this.visible)
|
|
56
|
+
this.$control.setAttribute('aria-label', this.textContent ?? '');
|
|
57
|
+
};
|
|
58
|
+
this.#handleFocusIn = () => {
|
|
59
|
+
if (!focusVisible)
|
|
60
|
+
return;
|
|
58
61
|
this.#show(this._delays.focus.show);
|
|
59
|
-
}
|
|
62
|
+
};
|
|
63
|
+
this.#handleFocusOut = () => {
|
|
60
64
|
this.#hide(this._delays.focus.hide);
|
|
61
|
-
}
|
|
65
|
+
};
|
|
66
|
+
this.#handlePointerEnter = (e) => {
|
|
62
67
|
const evt = e;
|
|
63
|
-
if (evt.pointerType === 'touch')
|
|
68
|
+
if (evt.pointerType === 'touch')
|
|
69
|
+
return;
|
|
64
70
|
this.#show(this._delays.mouse.show);
|
|
65
|
-
}
|
|
71
|
+
};
|
|
72
|
+
this.#handlePointerLeave = (e) => {
|
|
66
73
|
const evt = e;
|
|
67
|
-
if (evt.pointerType === 'touch')
|
|
74
|
+
if (evt.pointerType === 'touch')
|
|
75
|
+
return;
|
|
68
76
|
this.#hide(this._delays.mouse.hide);
|
|
69
|
-
}
|
|
77
|
+
};
|
|
78
|
+
this.#handleTouchStart = () => {
|
|
70
79
|
this.#show(this._delays.touch.show);
|
|
71
|
-
}
|
|
80
|
+
};
|
|
81
|
+
this.#handleTouchEnd = () => {
|
|
72
82
|
this.#hide(this._delays.touch.hide);
|
|
73
83
|
};
|
|
74
84
|
this[internals].role = 'tooltip';
|
|
@@ -80,19 +90,22 @@ const Base = Attachable(InternalsAttached(LitElement));
|
|
|
80
90
|
pointerenter: this.#handlePointerEnter,
|
|
81
91
|
pointerleave: this.#handlePointerLeave,
|
|
82
92
|
touchstart: this.#handleTouchStart,
|
|
83
|
-
touchend: this.#handleTouchEnd
|
|
93
|
+
touchend: this.#handleTouchEnd,
|
|
84
94
|
};
|
|
85
|
-
Object.keys(eventHandlers).forEach((key)=>{
|
|
95
|
+
Object.keys(eventHandlers).forEach((key) => {
|
|
86
96
|
prev?.removeEventListener(key, eventHandlers[key]);
|
|
87
97
|
next?.addEventListener(key, eventHandlers[key]);
|
|
88
98
|
});
|
|
89
|
-
if (prev)
|
|
90
|
-
|
|
99
|
+
if (prev)
|
|
100
|
+
prev.removeAttribute('aria-label');
|
|
101
|
+
if (next)
|
|
102
|
+
next.setAttribute('aria-label', this.textContent ?? '');
|
|
91
103
|
}
|
|
92
104
|
set visible(value) {
|
|
93
105
|
if (value) {
|
|
94
106
|
this.popoverController.animateOpen();
|
|
95
|
-
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
96
109
|
this.popoverController.animateClose();
|
|
97
110
|
}
|
|
98
111
|
}
|
|
@@ -105,7 +118,7 @@ const Base = Attachable(InternalsAttached(LitElement));
|
|
|
105
118
|
#handleTouchEnd;
|
|
106
119
|
#show(delay) {
|
|
107
120
|
clearTimeout(this.#closeTimer);
|
|
108
|
-
this.#openTimer = setTimeout(()=>{
|
|
121
|
+
this.#openTimer = setTimeout(() => {
|
|
109
122
|
this.visible = true;
|
|
110
123
|
}, Math.max(Date.now() - lastHidingTime < this._delays.recentlyShowed ? 0 : delay));
|
|
111
124
|
}
|
|
@@ -114,28 +127,20 @@ const Base = Attachable(InternalsAttached(LitElement));
|
|
|
114
127
|
lastHidingTime = Date.now();
|
|
115
128
|
}
|
|
116
129
|
clearTimeout(this.#openTimer);
|
|
117
|
-
this.#closeTimer = setTimeout(()=>{
|
|
130
|
+
this.#closeTimer = setTimeout(() => {
|
|
118
131
|
this.visible = false;
|
|
119
132
|
}, delay);
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
|
-
|
|
123
|
-
property({
|
|
124
|
-
reflect: true
|
|
125
|
-
})
|
|
135
|
+
__decorate([
|
|
136
|
+
property({ reflect: true })
|
|
126
137
|
], Tooltip.prototype, "align", void 0);
|
|
127
|
-
|
|
128
|
-
property({
|
|
129
|
-
type: Number,
|
|
130
|
-
reflect: true
|
|
131
|
-
})
|
|
138
|
+
__decorate([
|
|
139
|
+
property({ type: Number, reflect: true })
|
|
132
140
|
], Tooltip.prototype, "offset", void 0);
|
|
133
|
-
|
|
134
|
-
property({
|
|
135
|
-
type: Boolean,
|
|
136
|
-
reflect: true
|
|
137
|
-
})
|
|
141
|
+
__decorate([
|
|
142
|
+
property({ type: Boolean, reflect: true })
|
|
138
143
|
], Tooltip.prototype, "forceInvisible", void 0);
|
|
139
|
-
|
|
144
|
+
__decorate([
|
|
140
145
|
query('slot')
|
|
141
146
|
], Tooltip.prototype, "$slot", void 0);
|
package/src/core/decorators.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isServer } from 'lit';
|
|
2
2
|
import { customElement } from 'lit/decorators.js';
|
|
3
|
-
const wrappedCustomElement = (tagName, allowSSR = true)=>{
|
|
3
|
+
const wrappedCustomElement = (tagName, allowSSR = true) => {
|
|
4
4
|
if (isServer && !allowSSR) {
|
|
5
5
|
console.log(`[seele] <${tagName}> will not be rendered server-side`);
|
|
6
|
-
return (cls)=>cls;
|
|
7
|
-
}
|
|
6
|
+
return (cls) => cls;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
8
9
|
return customElement(tagName);
|
|
9
10
|
}
|
|
10
11
|
};
|