godown 3.0.0 → 3.0.2
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 +3 -2
- 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 +21 -26
- 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 +1 -0
- 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 -13
- 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 +3 -2
- package/dev/components/dialog.d.ts.map +1 -1
- package/dev/components/dialog.js +63 -65
- 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 +21 -26
- package/dev/components/router.d.ts.map +1 -1
- package/dev/components/router.js +22 -18
- 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 +1 -0
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +87 -69
- 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 +3 -3
- 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 -14
- 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 +69 -66
- 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 +46 -46
- 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 +91 -74
- package/src/core/super-openable.ts +2 -8
- package/vscode.html-custom-data.json +1 -1
- package/web-types.json +1 -1
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
|
/**
|
@@ -13,7 +30,7 @@ const protoName = "router";
|
|
13
30
|
*
|
14
31
|
* It has two methods to collect routes.
|
15
32
|
*
|
16
|
-
* 1. From field `routes`, an array, each elements require "path"
|
33
|
+
* 1. From field `routes`, an array, each elements require "path".
|
17
34
|
* 2. From child elements, which have the slot attribute for matching routes.
|
18
35
|
*
|
19
36
|
* If only the method 1 is used, set `type` to `"field"`.
|
@@ -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,24 @@ class Router extends GlobalStyle {
|
|
53
68
|
/**
|
54
69
|
* Dynamic parameters record.
|
55
70
|
*/
|
56
|
-
|
57
|
-
|
71
|
+
get params(): Record<string, string> {
|
72
|
+
if (!this.path) {
|
73
|
+
return {};
|
74
|
+
}
|
75
|
+
return RouteTree.parseParams(this.pathname, this.path);
|
76
|
+
}
|
58
77
|
|
59
78
|
/**
|
60
79
|
* Value of matched path in routes.
|
61
80
|
*/
|
62
81
|
@state()
|
63
|
-
path
|
82
|
+
path?: string;
|
64
83
|
|
65
84
|
/**
|
66
85
|
* Current pathname (equals to location.pathname).
|
67
86
|
*/
|
68
87
|
@property()
|
69
|
-
pathname: string;
|
88
|
+
pathname: string = location.pathname;
|
70
89
|
|
71
90
|
/**
|
72
91
|
* Rendered content when there is no match.
|
@@ -98,11 +117,7 @@ class Router extends GlobalStyle {
|
|
98
117
|
this.collectFieldRoutes(value);
|
99
118
|
}
|
100
119
|
|
101
|
-
get routes():
|
102
|
-
path: string;
|
103
|
-
render?: (ur: ReturnType<Router["useRouter"]>) => unknown;
|
104
|
-
component?: unknown;
|
105
|
-
})[] {
|
120
|
+
get routes(): RouteItem[] {
|
106
121
|
return this.__routes;
|
107
122
|
}
|
108
123
|
|
@@ -111,7 +126,6 @@ class Router extends GlobalStyle {
|
|
111
126
|
}
|
112
127
|
|
113
128
|
protected render(): unknown {
|
114
|
-
this.params = {};
|
115
129
|
if (this.cache) {
|
116
130
|
const cached = this.__cacheRecord.get(this.pathname);
|
117
131
|
if (cached) {
|
@@ -129,13 +143,12 @@ class Router extends GlobalStyle {
|
|
129
143
|
default:
|
130
144
|
this.component = this.fieldComponent() ?? this.slottedComponent();
|
131
145
|
}
|
132
|
-
return this.component ?? this.default
|
146
|
+
return this.component ?? this.default;
|
133
147
|
}
|
134
148
|
|
135
149
|
connectedCallback(): void {
|
136
150
|
super.connectedCallback();
|
137
151
|
Router.routerInstances.add(this);
|
138
|
-
this.pathname ??= location.pathname;
|
139
152
|
|
140
153
|
if (this.type !== "field") {
|
141
154
|
const mutationObserver = new MutationObserver(this.collectSlottedRoutes);
|
@@ -153,12 +166,7 @@ class Router extends GlobalStyle {
|
|
153
166
|
Router.routerInstances.delete(this);
|
154
167
|
}
|
155
168
|
|
156
|
-
useRouter(): {
|
157
|
-
pathname: string;
|
158
|
-
params: Record<string, string>;
|
159
|
-
path: string;
|
160
|
-
component: unknown;
|
161
|
-
} {
|
169
|
+
useRouter(): RouteResult {
|
162
170
|
return {
|
163
171
|
pathname: this.pathname,
|
164
172
|
params: this.params,
|
@@ -170,12 +178,7 @@ class Router extends GlobalStyle {
|
|
170
178
|
/**
|
171
179
|
* Callback function when the route changes.
|
172
180
|
*/
|
173
|
-
routeChangeCallback: (params:
|
174
|
-
pathname: string;
|
175
|
-
params: Record<string, string>;
|
176
|
-
path: string;
|
177
|
-
component: unknown | TemplateResult;
|
178
|
-
}, first: boolean) => void = null;
|
181
|
+
routeChangeCallback: (params: RouteResult, first: boolean) => void = null;
|
179
182
|
|
180
183
|
protected updated(changedProperties: PropertyValueMap<this>): void {
|
181
184
|
const shouldDispatch = changedProperties.has("pathname") || changedProperties.has("path");
|
@@ -201,14 +204,15 @@ class Router extends GlobalStyle {
|
|
201
204
|
return null;
|
202
205
|
}
|
203
206
|
|
204
|
-
this.params = this.parseParams(this.path, this.pathname);
|
205
207
|
const route = this.routes.find((r) => r.path === query);
|
206
208
|
if (!route) {
|
207
209
|
return null;
|
208
210
|
}
|
209
211
|
|
212
|
+
console.log(this.path);
|
213
|
+
|
210
214
|
if ("render" in route) {
|
211
|
-
return route.render?.(this.useRouter()) || null;
|
215
|
+
return route.render?.(omit(this.useRouter(), "component")) || null;
|
212
216
|
}
|
213
217
|
|
214
218
|
return route.component;
|
@@ -230,7 +234,7 @@ class Router extends GlobalStyle {
|
|
230
234
|
if (!this.path) {
|
231
235
|
return null;
|
232
236
|
}
|
233
|
-
|
237
|
+
|
234
238
|
return htmlSlot(this.path);
|
235
239
|
}
|
236
240
|
|
@@ -240,7 +244,7 @@ class Router extends GlobalStyle {
|
|
240
244
|
collectSlottedRoutes(): void {
|
241
245
|
this.__slottedRouteTree = new RouteTree();
|
242
246
|
this.clear();
|
243
|
-
this._slottedNames.forEach(slotName => {
|
247
|
+
this._slottedNames.forEach((slotName) => {
|
244
248
|
this.__slottedRouteTree.insert(slotName);
|
245
249
|
});
|
246
250
|
}
|
@@ -256,19 +260,15 @@ class Router extends GlobalStyle {
|
|
256
260
|
});
|
257
261
|
}
|
258
262
|
|
259
|
-
parseParams(routeTemplate: string, path: string = this.pathname): Record<string, string> {
|
260
|
-
return RouteTree.parseParams(path, routeTemplate);
|
261
|
-
}
|
262
|
-
|
263
263
|
static updateAll(): void {
|
264
264
|
this.routerInstances.forEach((i) => {
|
265
265
|
i.handlePopstate();
|
266
266
|
});
|
267
267
|
}
|
268
268
|
|
269
|
-
handlePopstate = this.events.add(window, "popstate", () => {
|
269
|
+
handlePopstate: () => void = this.events.add(window, "popstate", () => {
|
270
270
|
this.pathname = location.pathname;
|
271
|
-
})
|
271
|
+
});
|
272
272
|
}
|
273
273
|
|
274
274
|
export default Router;
|
package/src/components/select.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { attr, godown,
|
1
|
+
import { type HandlerEvent, attr, godown, htmlSlot, part, styles } from "@godown/element";
|
2
2
|
import svgCaretDown from "@godown/f7-icon/icons/chevron-down.js";
|
3
|
-
import { css, html, nothing
|
3
|
+
import { type TemplateResult, css, html, nothing } from "lit";
|
4
4
|
import { property, state } from "lit/decorators.js";
|
5
5
|
|
6
6
|
import Input from "./input.js";
|
@@ -46,31 +46,29 @@ const protoName = "select";
|
|
46
46
|
* @category input
|
47
47
|
*/
|
48
48
|
@godown(protoName)
|
49
|
-
@styles(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
49
|
+
@styles(css`
|
50
|
+
[part="input"] {
|
51
|
+
text-overflow: ellipsis;
|
52
|
+
}
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
[part="content"] {
|
55
|
+
position: absolute;
|
56
|
+
width: 100%;
|
57
|
+
visibility: hidden;
|
58
|
+
}
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
[direction="bottom"] [part="content"] {
|
61
|
+
top: 100%;
|
62
|
+
}
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
[direction="top"] [part="content"] {
|
65
|
+
bottom: 100%;
|
66
|
+
}
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
)
|
68
|
+
[visible] [part="content"] {
|
69
|
+
visibility: visible;
|
70
|
+
}
|
71
|
+
`)
|
74
72
|
class Select extends Input {
|
75
73
|
// @ts-ignore
|
76
74
|
value: string | string[];
|
@@ -99,41 +97,54 @@ class Select extends Input {
|
|
99
97
|
protected lastChecked: HTMLElement;
|
100
98
|
protected defaultText: string;
|
101
99
|
protected defaultChecked: HTMLElement[];
|
102
|
-
private _store: { value: string; text: string
|
100
|
+
private _store: { value: string; text: string }[] = [];
|
103
101
|
|
104
102
|
protected render(): TemplateResult<1> {
|
105
|
-
return html
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
103
|
+
return html`
|
104
|
+
<div
|
105
|
+
part="root"
|
106
|
+
${attr({
|
107
|
+
...this.observedRecord,
|
108
|
+
direction: this.direction || this.autoDirection,
|
109
|
+
})}
|
110
|
+
class="input-field"
|
111
|
+
>
|
112
|
+
${[
|
113
|
+
this._renderPrefix(),
|
114
|
+
html`
|
115
|
+
<input
|
116
|
+
part="input"
|
117
|
+
type="${this.type}"
|
118
|
+
.value="${this.text}"
|
119
|
+
?autofocus="${this.autofocus}"
|
120
|
+
?disabled="${this.disabled}"
|
121
|
+
autocapitalize="${this.autocapitalize || nothing}"
|
122
|
+
autocomplete="${this.autocomplete || nothing}"
|
123
|
+
placeholder="${this.placeholder || nothing}"
|
124
|
+
id="${this.makeId}"
|
125
|
+
@focus="${this._handleFocus}"
|
126
|
+
@input="${this._handleInput}"
|
127
|
+
/>
|
128
|
+
`,
|
129
|
+
html`
|
130
|
+
<label
|
131
|
+
for="${this.makeId}"
|
132
|
+
part="suffix"
|
133
|
+
>
|
134
|
+
<i part="icon">${svgCaretDown()}</i>
|
135
|
+
</label>
|
136
|
+
`,
|
137
|
+
html`
|
138
|
+
<label
|
139
|
+
for="${this.makeId}"
|
140
|
+
part="content"
|
141
|
+
>
|
142
|
+
${htmlSlot()}
|
143
|
+
</label>
|
144
|
+
`,
|
145
|
+
]}
|
146
|
+
</div>
|
147
|
+
`;
|
137
148
|
}
|
138
149
|
|
139
150
|
protected _handleFocus(): void {
|
@@ -177,11 +188,7 @@ class Select extends Input {
|
|
177
188
|
protected _connectedInit(): void {
|
178
189
|
if (!this.value) {
|
179
190
|
const checked = [...this.querySelectorAll<HTMLElement>("[checked]")];
|
180
|
-
const list = this.multiple
|
181
|
-
? checked
|
182
|
-
: checked.length
|
183
|
-
? [this.lastChecked = checked[0]]
|
184
|
-
: [];
|
191
|
+
const list = this.multiple ? checked : checked.length ? [(this.lastChecked = checked[0])] : [];
|
185
192
|
list.forEach((element: HTMLElement) => {
|
186
193
|
const operation = this.select(this.optionValue(element), element.textContent);
|
187
194
|
updateChecked(element, operation);
|
@@ -199,23 +206,23 @@ class Select extends Input {
|
|
199
206
|
reset(): void {
|
200
207
|
this.value = this.default;
|
201
208
|
this.text = this.defaultText;
|
202
|
-
this.querySelectorAll<HTMLElement>("[checked]").forEach(element => updateChecked(element, 0));
|
203
|
-
this.defaultChecked.forEach(element => updateChecked(element, 1));
|
209
|
+
this.querySelectorAll<HTMLElement>("[checked]").forEach((element) => updateChecked(element, 0));
|
210
|
+
this.defaultChecked.forEach((element) => updateChecked(element, 1));
|
204
211
|
}
|
205
212
|
|
206
213
|
select(value: string, text?: string): 0 | 1 {
|
207
214
|
text ||= value;
|
208
215
|
let operation: 0 | 1 = 0;
|
209
216
|
if (this.multiple) {
|
210
|
-
const i = this._store.findIndex(s => s.value === value);
|
217
|
+
const i = this._store.findIndex((s) => s.value === value);
|
211
218
|
if (i > -1) {
|
212
219
|
this._store.splice(i, 1);
|
213
220
|
} else {
|
214
221
|
this._store.push({ value, text });
|
215
222
|
operation = 1;
|
216
223
|
}
|
217
|
-
this.value = this._store.map(s => s.value);
|
218
|
-
this.text = this._store.map(s => s.text).join(", ");
|
224
|
+
this.value = this._store.map((s) => s.value);
|
225
|
+
this.text = this._store.map((s) => s.text).join(", ");
|
219
226
|
} else {
|
220
227
|
if (this.value === value) {
|
221
228
|
this.value = "";
|
@@ -236,15 +243,12 @@ class Select extends Input {
|
|
236
243
|
[...this.children].forEach((element: HTMLElement) => {
|
237
244
|
this.filterCallback(
|
238
245
|
element,
|
239
|
-
!query
|
240
|
-
|| contain(this.optionValue(element), query)
|
241
|
-
|| contain(element.textContent, query),
|
246
|
+
!query || contain(this.optionValue(element), query) || contain(element.textContent, query),
|
242
247
|
query,
|
243
248
|
);
|
244
249
|
});
|
245
250
|
}
|
246
251
|
|
247
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
248
252
|
filterCallback(element: HTMLElement, match: boolean, query: string): void {
|
249
253
|
element.style.display = match ? "" : "none";
|
250
254
|
}
|