godown 3.0.0 → 3.0.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 -12
- package/build/godown+lit.iife.js.map +1 -1
- package/build/godown+lit.js +12 -12
- package/build/godown+lit.js.map +1 -1
- package/build/godown+lit.umd.js +12 -12
- package/build/godown+lit.umd.js.map +1 -1
- package/build/godown.iife.js +11 -11
- package/build/godown.js +11 -11
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +11 -11
- package/build/godown.umd.js.map +1 -1
- package/components/alert.d.ts.map +1 -1
- package/components/alert.js +1 -1
- package/components/alert.js.map +1 -1
- package/components/avatar.d.ts.map +1 -1
- package/components/avatar.js +1 -1
- package/components/avatar.js.map +1 -1
- package/components/badge.d.ts.map +1 -1
- package/components/badge.js +1 -1
- package/components/badge.js.map +1 -1
- package/components/breath.d.ts.map +1 -1
- package/components/breath.js +1 -1
- package/components/breath.js.map +1 -1
- package/components/button.d.ts.map +1 -1
- package/components/button.js +1 -1
- package/components/button.js.map +1 -1
- package/components/card.d.ts.map +1 -1
- package/components/card.js +1 -1
- package/components/card.js.map +1 -1
- package/components/carousel.d.ts.map +1 -1
- package/components/carousel.js +1 -1
- package/components/carousel.js.map +1 -1
- package/components/details.d.ts.map +1 -1
- package/components/details.js +1 -1
- package/components/details.js.map +1 -1
- package/components/dialog.d.ts.map +1 -1
- package/components/dialog.js +1 -1
- package/components/dialog.js.map +1 -1
- package/components/divider.d.ts.map +1 -1
- package/components/divider.js +1 -1
- package/components/divider.js.map +1 -1
- package/components/dragbox.d.ts.map +1 -1
- package/components/dragbox.js +1 -1
- package/components/dragbox.js.map +1 -1
- package/components/flex.d.ts.map +1 -1
- package/components/flex.js.map +1 -1
- package/components/form.d.ts.map +1 -1
- package/components/form.js.map +1 -1
- package/components/grid.d.ts.map +1 -1
- package/components/grid.js.map +1 -1
- package/components/heading.d.ts.map +1 -1
- package/components/heading.js +1 -1
- package/components/heading.js.map +1 -1
- package/components/input.d.ts.map +1 -1
- package/components/input.js +1 -1
- package/components/input.js.map +1 -1
- package/components/layout.d.ts.map +1 -1
- package/components/layout.js +1 -1
- package/components/layout.js.map +1 -1
- package/components/link.js.map +1 -1
- package/components/progress.d.ts.map +1 -1
- package/components/progress.js +1 -1
- package/components/progress.js.map +1 -1
- package/components/range.d.ts.map +1 -1
- package/components/range.js +1 -1
- package/components/range.js.map +1 -1
- package/components/rotate.d.ts.map +1 -1
- package/components/rotate.js +1 -1
- package/components/rotate.js.map +1 -1
- package/components/router.d.ts +20 -25
- package/components/router.d.ts.map +1 -1
- package/components/router.js +1 -1
- package/components/router.js.map +1 -1
- package/components/select.d.ts.map +1 -1
- package/components/select.js +1 -1
- package/components/select.js.map +1 -1
- package/components/skeleton.d.ts.map +1 -1
- package/components/skeleton.js +1 -1
- package/components/skeleton.js.map +1 -1
- package/components/split.d.ts.map +1 -1
- package/components/split.js +1 -1
- package/components/split.js.map +1 -1
- package/components/switch.d.ts.map +1 -1
- package/components/switch.js +1 -1
- package/components/switch.js.map +1 -1
- package/components/text.d.ts.map +1 -1
- package/components/text.js +1 -1
- package/components/text.js.map +1 -1
- package/components/time.d.ts.map +1 -1
- package/components/time.js.map +1 -1
- package/components/tooltip.d.ts.map +1 -1
- package/components/tooltip.js +1 -1
- package/components/tooltip.js.map +1 -1
- package/components/typewriter.d.ts.map +1 -1
- package/components/typewriter.js +1 -1
- package/components/typewriter.js.map +1 -1
- package/core/global-style.d.ts.map +1 -1
- package/core/global-style.js +1 -1
- package/core/global-style.js.map +1 -1
- package/core/super-anchor.d.ts.map +1 -1
- package/core/super-anchor.js +1 -1
- package/core/super-anchor.js.map +1 -1
- package/core/super-input.d.ts.map +1 -1
- package/core/super-input.js +1 -1
- package/core/super-input.js.map +1 -1
- package/core/super-openable.d.ts.map +1 -1
- package/core/super-openable.js.map +1 -1
- package/custom-elements.json +1 -1
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +82 -69
- package/dev/components/alert.js.map +1 -1
- package/dev/components/avatar.d.ts.map +1 -1
- package/dev/components/avatar.js +52 -36
- package/dev/components/avatar.js.map +1 -1
- package/dev/components/badge.d.ts.map +1 -1
- package/dev/components/badge.js +57 -50
- package/dev/components/badge.js.map +1 -1
- package/dev/components/breath.d.ts.map +1 -1
- package/dev/components/breath.js +20 -14
- package/dev/components/breath.js.map +1 -1
- package/dev/components/button.d.ts.map +1 -1
- package/dev/components/button.js +13 -10
- package/dev/components/button.js.map +1 -1
- package/dev/components/card.d.ts.map +1 -1
- package/dev/components/card.js +40 -35
- package/dev/components/card.js.map +1 -1
- package/dev/components/carousel.d.ts.map +1 -1
- package/dev/components/carousel.js +63 -43
- package/dev/components/carousel.js.map +1 -1
- package/dev/components/details.d.ts.map +1 -1
- package/dev/components/details.js +72 -61
- package/dev/components/details.js.map +1 -1
- package/dev/components/dialog.d.ts.map +1 -1
- package/dev/components/dialog.js +61 -57
- package/dev/components/dialog.js.map +1 -1
- package/dev/components/divider.d.ts.map +1 -1
- package/dev/components/divider.js +28 -23
- package/dev/components/divider.js.map +1 -1
- package/dev/components/dragbox.d.ts.map +1 -1
- package/dev/components/dragbox.js +19 -17
- package/dev/components/dragbox.js.map +1 -1
- package/dev/components/flex.d.ts.map +1 -1
- package/dev/components/flex.js +16 -11
- package/dev/components/flex.js.map +1 -1
- package/dev/components/form.d.ts.map +1 -1
- package/dev/components/form.js +4 -4
- package/dev/components/form.js.map +1 -1
- package/dev/components/grid.d.ts.map +1 -1
- package/dev/components/grid.js +16 -11
- package/dev/components/grid.js.map +1 -1
- package/dev/components/heading.d.ts.map +1 -1
- package/dev/components/heading.js +62 -40
- package/dev/components/heading.js.map +1 -1
- package/dev/components/input.d.ts.map +1 -1
- package/dev/components/input.js +32 -24
- package/dev/components/input.js.map +1 -1
- package/dev/components/layout.d.ts.map +1 -1
- package/dev/components/layout.js +43 -30
- package/dev/components/layout.js.map +1 -1
- package/dev/components/link.js +1 -1
- package/dev/components/link.js.map +1 -1
- package/dev/components/progress.d.ts.map +1 -1
- package/dev/components/progress.js +51 -42
- package/dev/components/progress.js.map +1 -1
- package/dev/components/range.d.ts.map +1 -1
- package/dev/components/range.js +33 -30
- package/dev/components/range.js.map +1 -1
- package/dev/components/rotate.d.ts.map +1 -1
- package/dev/components/rotate.js +12 -5
- package/dev/components/rotate.js.map +1 -1
- package/dev/components/router.d.ts +20 -25
- package/dev/components/router.d.ts.map +1 -1
- package/dev/components/router.js +17 -17
- package/dev/components/router.js.map +1 -1
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +65 -57
- package/dev/components/select.js.map +1 -1
- package/dev/components/skeleton.d.ts.map +1 -1
- package/dev/components/skeleton.js +65 -61
- package/dev/components/skeleton.js.map +1 -1
- package/dev/components/split.d.ts.map +1 -1
- package/dev/components/split.js +66 -58
- package/dev/components/split.js.map +1 -1
- package/dev/components/switch.d.ts.map +1 -1
- package/dev/components/switch.js +88 -79
- package/dev/components/switch.js.map +1 -1
- package/dev/components/text.d.ts.map +1 -1
- package/dev/components/text.js +51 -45
- package/dev/components/text.js.map +1 -1
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js +13 -2
- package/dev/components/time.js.map +1 -1
- package/dev/components/tooltip.d.ts.map +1 -1
- package/dev/components/tooltip.js +31 -23
- package/dev/components/tooltip.js.map +1 -1
- package/dev/components/typewriter.d.ts.map +1 -1
- package/dev/components/typewriter.js +35 -27
- package/dev/components/typewriter.js.map +1 -1
- package/dev/core/global-style.d.ts.map +1 -1
- package/dev/core/global-style.js +9 -9
- package/dev/core/global-style.js.map +1 -1
- package/dev/core/super-anchor.d.ts.map +1 -1
- package/dev/core/super-anchor.js +27 -26
- package/dev/core/super-anchor.js.map +1 -1
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +83 -68
- package/dev/core/super-input.js.map +1 -1
- package/dev/core/super-openable.d.ts.map +1 -1
- package/dev/core/super-openable.js +1 -2
- package/dev/core/super-openable.js.map +1 -1
- package/package.json +5 -5
- package/src/components/alert.ts +84 -75
- package/src/components/avatar.ts +54 -40
- package/src/components/badge.ts +68 -65
- package/src/components/breath.ts +23 -19
- package/src/components/button.ts +14 -11
- package/src/components/card.ts +42 -40
- package/src/components/carousel.ts +65 -47
- package/src/components/details.ts +74 -65
- package/src/components/dialog.ts +64 -62
- package/src/components/divider.ts +33 -30
- package/src/components/dragbox.ts +22 -22
- package/src/components/flex.ts +31 -28
- package/src/components/form.ts +7 -9
- package/src/components/grid.ts +31 -28
- package/src/components/heading.ts +67 -49
- package/src/components/input.ts +37 -31
- package/src/components/layout.ts +45 -34
- package/src/components/link.ts +1 -1
- package/src/components/progress.ts +53 -46
- package/src/components/range.ts +58 -52
- package/src/components/rotate.ts +15 -10
- package/src/components/router.ts +40 -45
- package/src/components/select.ts +74 -70
- package/src/components/skeleton.ts +67 -65
- package/src/components/split.ts +73 -69
- package/src/components/switch.ts +90 -83
- package/src/components/text.ts +53 -49
- package/src/components/time.ts +14 -3
- package/src/components/tooltip.ts +32 -24
- package/src/components/typewriter.ts +37 -31
- package/src/core/global-style.ts +11 -12
- package/src/core/super-anchor.ts +29 -30
- package/src/core/super-input.ts +86 -73
- package/src/core/super-openable.ts +2 -8
- package/web-types.json +1 -1
@@ -1,8 +1,8 @@
|
|
1
1
|
import { attr, godown, isNil, styles } from "@godown/element";
|
2
|
-
import { css, html
|
2
|
+
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property } from "lit/decorators.js";
|
4
4
|
|
5
|
-
import {
|
5
|
+
import { GlobalStyle, cssGlobalVars } from "../core/global-style.js";
|
6
6
|
|
7
7
|
const protoName = "progress";
|
8
8
|
|
@@ -12,54 +12,52 @@ const protoName = "progress";
|
|
12
12
|
* @category feedback
|
13
13
|
*/
|
14
14
|
@godown(protoName)
|
15
|
-
@styles(
|
16
|
-
|
17
|
-
:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
15
|
+
@styles(css`
|
16
|
+
:host {
|
17
|
+
width: 100%;
|
18
|
+
height: 0.5em;
|
19
|
+
border-radius: 0.25em;
|
20
|
+
background: var(${cssGlobalVars.passive});
|
21
|
+
color: var(${cssGlobalVars.active});
|
22
|
+
}
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
:host,
|
25
|
+
[part="root"] {
|
26
|
+
display: block;
|
27
|
+
}
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
[part="root"] {
|
30
|
+
height: inherit;
|
31
|
+
z-index: 1;
|
32
|
+
position: relative;
|
33
|
+
border-radius: inherit;
|
34
|
+
}
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
[part="value"] {
|
37
|
+
position: absolute;
|
38
|
+
z-index: 2;
|
39
|
+
top: 0;
|
40
|
+
left: 0;
|
41
|
+
height: 100%;
|
42
|
+
border-radius: inherit;
|
43
|
+
transition: all 0.3s;
|
44
|
+
animation: progress 1.8s ease-in-out infinite alternate;
|
45
|
+
background: currentColor;
|
46
|
+
}
|
47
|
+
|
48
|
+
@keyframes progress {
|
49
|
+
from {
|
41
50
|
left: 0;
|
42
|
-
height: 100%;
|
43
|
-
border-radius: inherit;
|
44
|
-
transition: all 0.3s;
|
45
|
-
animation: progress 1.8s ease-in-out infinite alternate;
|
46
|
-
background: currentColor;
|
47
51
|
}
|
48
|
-
|
49
|
-
|
50
|
-
from {
|
51
|
-
left: 0;
|
52
|
-
}
|
53
|
-
to {
|
54
|
-
left: 80%;
|
55
|
-
}
|
52
|
+
to {
|
53
|
+
left: 80%;
|
56
54
|
}
|
55
|
+
}
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
)
|
57
|
+
.static [part="value"] {
|
58
|
+
animation: none;
|
59
|
+
}
|
60
|
+
`)
|
63
61
|
class Progress extends GlobalStyle {
|
64
62
|
@property({ type: Number })
|
65
63
|
max = 1;
|
@@ -77,9 +75,18 @@ class Progress extends GlobalStyle {
|
|
77
75
|
width = this.parsePercent(this.value);
|
78
76
|
className = "static";
|
79
77
|
}
|
80
|
-
return html
|
81
|
-
<
|
82
|
-
|
78
|
+
return html`
|
79
|
+
<div
|
80
|
+
part="root"
|
81
|
+
${attr(this.observedRecord)}
|
82
|
+
class="${className}"
|
83
|
+
>
|
84
|
+
<i
|
85
|
+
part="value"
|
86
|
+
style="width:${width}%;"
|
87
|
+
></i>
|
88
|
+
</div>
|
89
|
+
`;
|
83
90
|
}
|
84
91
|
|
85
92
|
/**
|
package/src/components/range.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { attr, classList, godown, isNil, joinProperties, part, styles } from "@godown/element";
|
2
|
-
import { css, html
|
2
|
+
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property, queryAll, state } from "lit/decorators.js";
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
@@ -34,7 +34,7 @@ const cssScope = scopePrefix(protoName);
|
|
34
34
|
display: block;
|
35
35
|
}
|
36
36
|
|
37
|
-
:host([contents]) [part=root] {
|
37
|
+
:host([contents]) [part="root"] {
|
38
38
|
width: inherit;
|
39
39
|
}
|
40
40
|
|
@@ -48,7 +48,7 @@ const cssScope = scopePrefix(protoName);
|
|
48
48
|
background: var(${cssScope}--handle-active);
|
49
49
|
}
|
50
50
|
|
51
|
-
[part=root] {
|
51
|
+
[part="root"] {
|
52
52
|
min-height: inherit;
|
53
53
|
position: relative;
|
54
54
|
border-radius: inherit;
|
@@ -58,9 +58,9 @@ const cssScope = scopePrefix(protoName);
|
|
58
58
|
height: var(${cssScope}--track-width);
|
59
59
|
}
|
60
60
|
|
61
|
-
[part=track] {
|
61
|
+
[part="track"] {
|
62
62
|
height: 100%;
|
63
|
-
min-height:inherit;
|
63
|
+
min-height: inherit;
|
64
64
|
display: flex;
|
65
65
|
position: absolute;
|
66
66
|
pointer-events: none;
|
@@ -71,7 +71,7 @@ const cssScope = scopePrefix(protoName);
|
|
71
71
|
width: max(calc(var(--to) - var(--from)), calc(var(--from) - var(--to)));
|
72
72
|
}
|
73
73
|
|
74
|
-
[part=handle] {
|
74
|
+
[part="handle"] {
|
75
75
|
width: 1em;
|
76
76
|
height: 1em;
|
77
77
|
display: flex;
|
@@ -97,7 +97,7 @@ const cssScope = scopePrefix(protoName);
|
|
97
97
|
transform: translate(-25%, -50%);
|
98
98
|
}
|
99
99
|
|
100
|
-
[vertical] [part=track] {
|
100
|
+
[vertical] [part="track"] {
|
101
101
|
width: 100%;
|
102
102
|
height: max(calc(var(--to) - var(--from)), calc(var(--from) - var(--to)));
|
103
103
|
top: min(var(--from), var(--to));
|
@@ -105,12 +105,12 @@ const cssScope = scopePrefix(protoName);
|
|
105
105
|
}
|
106
106
|
`,
|
107
107
|
css`
|
108
|
-
[part=handle] {
|
108
|
+
[part="handle"] {
|
109
109
|
left: var(--handle);
|
110
110
|
top: 0;
|
111
111
|
}
|
112
112
|
|
113
|
-
[vertical] [part=handle] {
|
113
|
+
[vertical] [part="handle"] {
|
114
114
|
top: var(--handle);
|
115
115
|
left: 0;
|
116
116
|
}
|
@@ -207,42 +207,44 @@ class Range extends SuperInput {
|
|
207
207
|
const to = Math.max(...rangeValue);
|
208
208
|
const gap = this.max - this.min;
|
209
209
|
|
210
|
-
return html
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
210
|
+
return html`
|
211
|
+
<div
|
212
|
+
part="root"
|
213
|
+
${attr(this.observedRecord)}
|
214
|
+
@mousedown="${this.disabled ? null : this._handleMousedownRoot}"
|
215
|
+
style="${joinProperties({
|
216
|
+
"--from": `${((from - this.min) / gap) * 100}%`,
|
217
|
+
"--to": `${((to - this.min) / gap) * 100}%`,
|
218
|
+
...(this.range
|
219
|
+
? Object.fromEntries(
|
220
|
+
rangeValue.map((value, index) => [`--handle-${index}`, `${((value - this.min) / gap) * 100}%`]),
|
221
|
+
)
|
222
|
+
: {}),
|
223
|
+
})}"
|
224
|
+
>
|
225
|
+
<div part="track"></div>
|
226
|
+
${this.range ? (this.value as number[]).map((_, index) => this.renderHandle(index)) : this.renderHandle(0)}
|
227
|
+
</div>
|
228
|
+
`;
|
229
229
|
}
|
230
230
|
|
231
231
|
protected renderHandle(index: number): TemplateResult<1> {
|
232
232
|
const { range } = this;
|
233
233
|
const end = !range || index === (this.value as number[]).length - 1;
|
234
|
-
return html
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
234
|
+
return html`
|
235
|
+
<i
|
236
|
+
tabindex="0"
|
237
|
+
part="handle"
|
238
|
+
class="${classList({ "last-focus": this.lastFocus === index })}"
|
239
|
+
@mousedown="${this.disabled ? null : this.createMouseDown(index)}"
|
240
|
+
@focus="${this.disabled ? null : () => this.focusHandle(index)}"
|
241
|
+
@blur="${this.disabled ? null : this.blurHandle}"
|
242
|
+
style="z-index:${this._focusStack.indexOf(index) + 1};--handle:var(--${
|
243
|
+
/* In single-handle mod or end, it is max value */
|
244
|
+
!range && end ? "to" : `handle-${index}`
|
245
|
+
})"
|
244
246
|
></i>
|
245
|
-
|
247
|
+
`;
|
246
248
|
}
|
247
249
|
|
248
250
|
private _keydownEvent: EventListenerOrEventListenerObject;
|
@@ -275,10 +277,10 @@ class Range extends SuperInput {
|
|
275
277
|
return (e: KeyboardEvent): void => {
|
276
278
|
if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
277
279
|
e.preventDefault();
|
278
|
-
this.createSetValue(index)(old => old - this.step);
|
280
|
+
this.createSetValue(index)((old) => old - this.step);
|
279
281
|
} else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
280
282
|
e.preventDefault();
|
281
|
-
this.createSetValue(index)(old => old + this.step);
|
283
|
+
this.createSetValue(index)((old) => old + this.step);
|
282
284
|
}
|
283
285
|
};
|
284
286
|
}
|
@@ -292,9 +294,10 @@ class Range extends SuperInput {
|
|
292
294
|
|
293
295
|
createSetValue(index: number) {
|
294
296
|
return (numberOrModifier: number | ((value: number) => number)): void => {
|
295
|
-
const number =
|
296
|
-
|
297
|
-
|
297
|
+
const number =
|
298
|
+
typeof numberOrModifier === "number"
|
299
|
+
? this.normalizeValue(numberOrModifier)
|
300
|
+
: numberOrModifier(this.rangeValue[index]);
|
298
301
|
let newValue: any = number;
|
299
302
|
if (this.range) {
|
300
303
|
newValue = [...this.rangeValue];
|
@@ -319,8 +322,11 @@ class Range extends SuperInput {
|
|
319
322
|
* Ensure that the values do not exceed the range of max and min.
|
320
323
|
*/
|
321
324
|
protected normalizeValue(value: number): number {
|
322
|
-
if (value > this.max) {
|
323
|
-
|
325
|
+
if (value > this.max) {
|
326
|
+
value -= this.step;
|
327
|
+
} else if (value < this.min) {
|
328
|
+
value += this.step;
|
329
|
+
}
|
324
330
|
return value;
|
325
331
|
}
|
326
332
|
|
@@ -328,10 +334,10 @@ class Range extends SuperInput {
|
|
328
334
|
const value = this._computeValue(e);
|
329
335
|
const index = this.range
|
330
336
|
? this.rangeValue.reduce((acc, item, index) => {
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
337
|
+
const diff = Math.abs(value - item);
|
338
|
+
const prevDiff = Math.abs(value - this.rangeValue[acc]);
|
339
|
+
return diff < prevDiff ? index : acc;
|
340
|
+
}, 0)
|
335
341
|
: 0;
|
336
342
|
|
337
343
|
const set = this.createSetValue(index);
|
@@ -382,12 +388,12 @@ class Range extends SuperInput {
|
|
382
388
|
}
|
383
389
|
|
384
390
|
sort(): number | number[] {
|
385
|
-
return this.value = this.toSorted();
|
391
|
+
return (this.value = this.toSorted());
|
386
392
|
}
|
387
393
|
|
388
394
|
toSorted(): number | number[] {
|
389
395
|
if (this.range) {
|
390
|
-
return [...this.value as number[]].sort((a, b) => a - b);
|
396
|
+
return [...(this.value as number[])].sort((a, b) => a - b);
|
391
397
|
}
|
392
398
|
return this.value;
|
393
399
|
}
|
package/src/components/rotate.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { godown, htmlSlot, part, styles } from "@godown/element";
|
2
|
-
import { css, html
|
2
|
+
import { type TemplateResult, css, html } from "lit";
|
3
3
|
|
4
4
|
import { GlobalStyle, scopePrefix } from "../core/global-style.js";
|
5
5
|
|
@@ -12,8 +12,7 @@ const cssScope = scopePrefix(protoName);
|
|
12
12
|
* @category wrapper
|
13
13
|
*/
|
14
14
|
@godown(protoName)
|
15
|
-
@styles(
|
16
|
-
css`
|
15
|
+
@styles(css`
|
17
16
|
:host {
|
18
17
|
display: block;
|
19
18
|
width: -moz-fit-content;
|
@@ -39,20 +38,26 @@ const cssScope = scopePrefix(protoName);
|
|
39
38
|
margin: calc(-1 * var(${cssScope}--offset));
|
40
39
|
}
|
41
40
|
|
42
|
-
[part=slot] {
|
41
|
+
[part="slot"] {
|
43
42
|
z-index: 2;
|
44
43
|
}
|
45
|
-
|
46
|
-
)
|
44
|
+
`)
|
47
45
|
class Rotate extends GlobalStyle {
|
48
46
|
@part("root")
|
49
47
|
protected _root: HTMLElement;
|
50
48
|
|
51
49
|
protected render(): TemplateResult<1> {
|
52
|
-
return html
|
53
|
-
<div part="
|
54
|
-
|
55
|
-
|
50
|
+
return html`
|
51
|
+
<div part="root">
|
52
|
+
<div
|
53
|
+
part="slot"
|
54
|
+
@mousemove="${this._handleRotate}"
|
55
|
+
>
|
56
|
+
${htmlSlot()}
|
57
|
+
</div>
|
58
|
+
<i @mouseleave="${this.reset}"></i>
|
59
|
+
</div>
|
60
|
+
`;
|
56
61
|
}
|
57
62
|
|
58
63
|
reset(): void {
|
package/src/components/router.ts
CHANGED
@@ -1,9 +1,26 @@
|
|
1
|
-
import { godown, htmlSlot,
|
2
|
-
import {
|
1
|
+
import { RouteTree, godown, htmlSlot, omit, styles } from "@godown/element";
|
2
|
+
import { type PropertyValueMap, type TemplateResult, css } from "lit";
|
3
3
|
import { property, state } from "lit/decorators.js";
|
4
4
|
|
5
5
|
import { GlobalStyle } from "../core/global-style.js";
|
6
6
|
|
7
|
+
interface RouteState {
|
8
|
+
pathname: string;
|
9
|
+
params: Record<string, string>;
|
10
|
+
path: string;
|
11
|
+
}
|
12
|
+
|
13
|
+
interface RouteResult extends RouteState {
|
14
|
+
component: unknown;
|
15
|
+
}
|
16
|
+
|
17
|
+
interface RouteItem {
|
18
|
+
[key: PropertyKey]: unknown;
|
19
|
+
path: string;
|
20
|
+
render?: (state?: RouteState) => unknown;
|
21
|
+
component?: unknown;
|
22
|
+
}
|
23
|
+
|
7
24
|
const protoName = "router";
|
8
25
|
|
9
26
|
/**
|
@@ -29,20 +46,18 @@ const protoName = "router";
|
|
29
46
|
* @category navigation
|
30
47
|
*/
|
31
48
|
@godown(protoName)
|
32
|
-
@styles(css
|
49
|
+
@styles(css`
|
50
|
+
:host {
|
51
|
+
display: contents;
|
52
|
+
}
|
53
|
+
`)
|
33
54
|
class Router extends GlobalStyle {
|
34
55
|
static routerInstances: Set<Router> = new Set<Router>();
|
35
56
|
|
36
57
|
private __fieldRouteTree: RouteTree = new RouteTree();
|
37
58
|
private __slottedRouteTree: RouteTree = new RouteTree();
|
38
|
-
private __cacheRecord = new Map<string,
|
39
|
-
private __routes:
|
40
|
-
& Record<string, any>
|
41
|
-
& {
|
42
|
-
path: string;
|
43
|
-
component?: unknown;
|
44
|
-
}
|
45
|
-
)[];
|
59
|
+
private __cacheRecord = new Map<string, RouteResult>();
|
60
|
+
private __routes: RouteItem[];
|
46
61
|
|
47
62
|
/**
|
48
63
|
* Render result.
|
@@ -53,20 +68,21 @@ class Router extends GlobalStyle {
|
|
53
68
|
/**
|
54
69
|
* Dynamic parameters record.
|
55
70
|
*/
|
56
|
-
|
57
|
-
|
71
|
+
get params(): Record<string, string> {
|
72
|
+
return RouteTree.parseParams(this.pathname, this.path);
|
73
|
+
}
|
58
74
|
|
59
75
|
/**
|
60
76
|
* Value of matched path in routes.
|
61
77
|
*/
|
62
78
|
@state()
|
63
|
-
path
|
79
|
+
path?: string;
|
64
80
|
|
65
81
|
/**
|
66
82
|
* Current pathname (equals to location.pathname).
|
67
83
|
*/
|
68
84
|
@property()
|
69
|
-
pathname: string;
|
85
|
+
pathname: string = location.pathname;
|
70
86
|
|
71
87
|
/**
|
72
88
|
* Rendered content when there is no match.
|
@@ -98,11 +114,7 @@ class Router extends GlobalStyle {
|
|
98
114
|
this.collectFieldRoutes(value);
|
99
115
|
}
|
100
116
|
|
101
|
-
get routes():
|
102
|
-
path: string;
|
103
|
-
render?: (ur: ReturnType<Router["useRouter"]>) => unknown;
|
104
|
-
component?: unknown;
|
105
|
-
})[] {
|
117
|
+
get routes(): RouteItem[] {
|
106
118
|
return this.__routes;
|
107
119
|
}
|
108
120
|
|
@@ -111,7 +123,6 @@ class Router extends GlobalStyle {
|
|
111
123
|
}
|
112
124
|
|
113
125
|
protected render(): unknown {
|
114
|
-
this.params = {};
|
115
126
|
if (this.cache) {
|
116
127
|
const cached = this.__cacheRecord.get(this.pathname);
|
117
128
|
if (cached) {
|
@@ -129,13 +140,12 @@ class Router extends GlobalStyle {
|
|
129
140
|
default:
|
130
141
|
this.component = this.fieldComponent() ?? this.slottedComponent();
|
131
142
|
}
|
132
|
-
return this.component ?? this.default
|
143
|
+
return this.component ?? this.default;
|
133
144
|
}
|
134
145
|
|
135
146
|
connectedCallback(): void {
|
136
147
|
super.connectedCallback();
|
137
148
|
Router.routerInstances.add(this);
|
138
|
-
this.pathname ??= location.pathname;
|
139
149
|
|
140
150
|
if (this.type !== "field") {
|
141
151
|
const mutationObserver = new MutationObserver(this.collectSlottedRoutes);
|
@@ -153,12 +163,7 @@ class Router extends GlobalStyle {
|
|
153
163
|
Router.routerInstances.delete(this);
|
154
164
|
}
|
155
165
|
|
156
|
-
useRouter(): {
|
157
|
-
pathname: string;
|
158
|
-
params: Record<string, string>;
|
159
|
-
path: string;
|
160
|
-
component: unknown;
|
161
|
-
} {
|
166
|
+
useRouter(): RouteResult {
|
162
167
|
return {
|
163
168
|
pathname: this.pathname,
|
164
169
|
params: this.params,
|
@@ -170,12 +175,7 @@ class Router extends GlobalStyle {
|
|
170
175
|
/**
|
171
176
|
* Callback function when the route changes.
|
172
177
|
*/
|
173
|
-
routeChangeCallback: (params:
|
174
|
-
pathname: string;
|
175
|
-
params: Record<string, string>;
|
176
|
-
path: string;
|
177
|
-
component: unknown | TemplateResult;
|
178
|
-
}, first: boolean) => void = null;
|
178
|
+
routeChangeCallback: (params: RouteResult, first: boolean) => void = null;
|
179
179
|
|
180
180
|
protected updated(changedProperties: PropertyValueMap<this>): void {
|
181
181
|
const shouldDispatch = changedProperties.has("pathname") || changedProperties.has("path");
|
@@ -201,14 +201,13 @@ class Router extends GlobalStyle {
|
|
201
201
|
return null;
|
202
202
|
}
|
203
203
|
|
204
|
-
this.params = this.parseParams(this.path, this.pathname);
|
205
204
|
const route = this.routes.find((r) => r.path === query);
|
206
205
|
if (!route) {
|
207
206
|
return null;
|
208
207
|
}
|
209
208
|
|
210
209
|
if ("render" in route) {
|
211
|
-
return route.render?.(this.useRouter()) || null;
|
210
|
+
return route.render?.(omit(this.useRouter(), "component")) || null;
|
212
211
|
}
|
213
212
|
|
214
213
|
return route.component;
|
@@ -230,7 +229,7 @@ class Router extends GlobalStyle {
|
|
230
229
|
if (!this.path) {
|
231
230
|
return null;
|
232
231
|
}
|
233
|
-
|
232
|
+
|
234
233
|
return htmlSlot(this.path);
|
235
234
|
}
|
236
235
|
|
@@ -240,7 +239,7 @@ class Router extends GlobalStyle {
|
|
240
239
|
collectSlottedRoutes(): void {
|
241
240
|
this.__slottedRouteTree = new RouteTree();
|
242
241
|
this.clear();
|
243
|
-
this._slottedNames.forEach(slotName => {
|
242
|
+
this._slottedNames.forEach((slotName) => {
|
244
243
|
this.__slottedRouteTree.insert(slotName);
|
245
244
|
});
|
246
245
|
}
|
@@ -256,19 +255,15 @@ class Router extends GlobalStyle {
|
|
256
255
|
});
|
257
256
|
}
|
258
257
|
|
259
|
-
parseParams(routeTemplate: string, path: string = this.pathname): Record<string, string> {
|
260
|
-
return RouteTree.parseParams(path, routeTemplate);
|
261
|
-
}
|
262
|
-
|
263
258
|
static updateAll(): void {
|
264
259
|
this.routerInstances.forEach((i) => {
|
265
260
|
i.handlePopstate();
|
266
261
|
});
|
267
262
|
}
|
268
263
|
|
269
|
-
handlePopstate = this.events.add(window, "popstate", () => {
|
264
|
+
handlePopstate: () => void = this.events.add(window, "popstate", () => {
|
270
265
|
this.pathname = location.pathname;
|
271
|
-
})
|
266
|
+
});
|
272
267
|
}
|
273
268
|
|
274
269
|
export default Router;
|