godown 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/godown+lit.iife.js +12 -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 +10 -10
- package/build/godown.js +10 -10
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +10 -10
- package/build/godown.umd.js.map +1 -1
- package/components/alert.d.ts +1 -3
- 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 +5 -4
- 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 +10 -2
- package/components/badge.d.ts.map +1 -1
- package/components/badge.js.map +1 -1
- package/components/breath.d.ts +2 -3
- 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 +8 -3
- 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 +6 -0
- 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 +7 -13
- 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 +3 -3
- package/components/details.d.ts.map +1 -1
- package/components/dialog.d.ts +9 -6
- 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 +1 -1
- package/components/heading.d.ts +2 -0
- package/components/heading.d.ts.map +1 -1
- package/components/heading.js.map +1 -1
- package/components/input.d.ts +2 -2
- package/components/input.d.ts.map +1 -1
- package/components/input.js +1 -1
- package/components/input.js.map +1 -1
- package/components/link.d.ts +1 -1
- package/components/link.d.ts.map +1 -1
- package/components/link.js +1 -1
- package/components/link.js.map +1 -1
- package/components/progress.d.ts +0 -7
- 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 +48 -19
- 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 +6 -4
- package/components/rotate.d.ts.map +1 -1
- package/components/rotate.js.map +1 -1
- 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 +4 -2
- package/components/select.d.ts.map +1 -1
- package/components/select.js +1 -1
- package/components/select.js.map +1 -1
- package/components/split.d.ts +2 -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 +5 -7
- package/components/switch.d.ts.map +1 -1
- package/components/switch.js +1 -1
- package/components/switch.js.map +1 -1
- package/components/text.js +1 -1
- package/components/text.js.map +1 -1
- package/components/time.d.ts +2 -5
- package/components/time.d.ts.map +1 -1
- package/components/time.js +1 -1
- package/components/time.js.map +1 -1
- package/components/tooltip.d.ts +3 -2
- 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/direction.d.ts +27 -0
- package/core/direction.d.ts.map +1 -0
- package/core/direction.js +2 -0
- package/core/direction.js.map +1 -0
- package/core/global-style.d.ts +1 -2
- 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/outline.d.ts +20 -0
- package/core/outline.d.ts.map +1 -0
- package/core/outline.js +2 -0
- package/core/outline.js.map +1 -0
- package/core/super-anchor.d.ts +2 -2
- 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 +2 -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 +0 -4
- package/core/super-openable.d.ts.map +1 -1
- package/custom-elements.json +1 -1
- package/dev/components/alert.d.ts +1 -3
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +33 -57
- package/dev/components/alert.js.map +1 -1
- package/dev/components/avatar.d.ts +5 -4
- package/dev/components/avatar.d.ts.map +1 -1
- package/dev/components/avatar.js +5 -4
- package/dev/components/avatar.js.map +1 -1
- package/dev/components/badge.d.ts +10 -2
- package/dev/components/badge.d.ts.map +1 -1
- package/dev/components/badge.js +8 -0
- package/dev/components/badge.js.map +1 -1
- package/dev/components/breath.d.ts +2 -3
- package/dev/components/breath.d.ts.map +1 -1
- package/dev/components/breath.js +3 -14
- package/dev/components/breath.js.map +1 -1
- package/dev/components/button.d.ts +8 -3
- package/dev/components/button.d.ts.map +1 -1
- package/dev/components/button.js +19 -5
- package/dev/components/button.js.map +1 -1
- package/dev/components/card.d.ts +6 -0
- package/dev/components/card.d.ts.map +1 -1
- package/dev/components/card.js +11 -11
- package/dev/components/card.js.map +1 -1
- package/dev/components/carousel.d.ts +7 -13
- package/dev/components/carousel.d.ts.map +1 -1
- package/dev/components/carousel.js +40 -39
- package/dev/components/carousel.js.map +1 -1
- package/dev/components/details.d.ts +3 -3
- package/dev/components/details.d.ts.map +1 -1
- package/dev/components/details.js +3 -3
- package/dev/components/details.js.map +1 -1
- package/dev/components/dialog.d.ts +9 -6
- package/dev/components/dialog.d.ts.map +1 -1
- package/dev/components/dialog.js +58 -62
- package/dev/components/dialog.js.map +1 -1
- package/dev/components/divider.d.ts +1 -1
- package/dev/components/divider.js +1 -1
- package/dev/components/heading.d.ts +2 -0
- package/dev/components/heading.d.ts.map +1 -1
- package/dev/components/heading.js +2 -0
- package/dev/components/heading.js.map +1 -1
- package/dev/components/input.d.ts +2 -2
- package/dev/components/input.d.ts.map +1 -1
- package/dev/components/input.js +30 -9
- package/dev/components/input.js.map +1 -1
- package/dev/components/link.d.ts +1 -1
- package/dev/components/link.d.ts.map +1 -1
- package/dev/components/link.js +2 -2
- package/dev/components/link.js.map +1 -1
- package/dev/components/progress.d.ts +0 -7
- package/dev/components/progress.d.ts.map +1 -1
- package/dev/components/progress.js +4 -25
- package/dev/components/progress.js.map +1 -1
- package/dev/components/range.d.ts +48 -19
- package/dev/components/range.d.ts.map +1 -1
- package/dev/components/range.js +83 -61
- package/dev/components/range.js.map +1 -1
- package/dev/components/rotate.d.ts +6 -4
- package/dev/components/rotate.d.ts.map +1 -1
- package/dev/components/rotate.js +6 -4
- package/dev/components/rotate.js.map +1 -1
- package/dev/components/router.d.ts.map +1 -1
- package/dev/components/router.js +2 -3
- package/dev/components/router.js.map +1 -1
- package/dev/components/select.d.ts +4 -2
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +27 -24
- package/dev/components/select.js.map +1 -1
- package/dev/components/split.d.ts +2 -1
- package/dev/components/split.d.ts.map +1 -1
- package/dev/components/split.js +11 -7
- package/dev/components/split.js.map +1 -1
- package/dev/components/switch.d.ts +5 -7
- package/dev/components/switch.d.ts.map +1 -1
- package/dev/components/switch.js +23 -45
- package/dev/components/switch.js.map +1 -1
- package/dev/components/text.js +2 -2
- package/dev/components/time.d.ts +2 -5
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js +6 -20
- package/dev/components/time.js.map +1 -1
- package/dev/components/tooltip.d.ts +3 -2
- package/dev/components/tooltip.d.ts.map +1 -1
- package/dev/components/tooltip.js +7 -19
- package/dev/components/tooltip.js.map +1 -1
- package/dev/components/typewriter.d.ts.map +1 -1
- package/dev/components/typewriter.js +2 -2
- package/dev/components/typewriter.js.map +1 -1
- package/dev/core/direction.d.ts +27 -0
- package/dev/core/direction.d.ts.map +1 -0
- package/dev/core/direction.js +56 -0
- package/dev/core/direction.js.map +1 -0
- package/dev/core/global-style.d.ts +1 -2
- package/dev/core/global-style.d.ts.map +1 -1
- package/dev/core/global-style.js +11 -11
- package/dev/core/global-style.js.map +1 -1
- package/dev/core/outline.d.ts +20 -0
- package/dev/core/outline.d.ts.map +1 -0
- package/dev/core/outline.js +44 -0
- package/dev/core/outline.js.map +1 -0
- package/dev/core/super-anchor.d.ts +2 -2
- package/dev/core/super-anchor.d.ts.map +1 -1
- package/dev/core/super-anchor.js +0 -1
- package/dev/core/super-anchor.js.map +1 -1
- package/dev/core/super-input.d.ts +2 -0
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +19 -30
- package/dev/core/super-input.js.map +1 -1
- package/dev/core/super-openable.d.ts +0 -4
- package/dev/core/super-openable.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/alert.ts +34 -65
- package/src/components/avatar.ts +7 -5
- package/src/components/badge.ts +10 -3
- package/src/components/breath.ts +5 -17
- package/src/components/button.ts +19 -6
- package/src/components/card.ts +11 -11
- package/src/components/carousel.ts +45 -44
- package/src/components/details.ts +3 -3
- package/src/components/dialog.ts +66 -65
- package/src/components/divider.ts +1 -1
- package/src/components/heading.ts +2 -0
- package/src/components/input.ts +30 -9
- package/src/components/link.ts +2 -2
- package/src/components/progress.ts +4 -25
- package/src/components/range.ts +92 -70
- package/src/components/rotate.ts +6 -4
- package/src/components/router.ts +2 -3
- package/src/components/select.ts +33 -26
- package/src/components/split.ts +12 -7
- package/src/components/switch.ts +26 -41
- package/src/components/text.ts +2 -2
- package/src/components/time.ts +10 -25
- package/src/components/tooltip.ts +8 -20
- package/src/components/typewriter.ts +9 -7
- package/src/core/direction.ts +65 -0
- package/src/core/global-style.ts +12 -14
- package/src/core/outline.ts +54 -0
- package/src/core/super-anchor.ts +3 -2
- package/src/core/super-input.ts +22 -30
- package/src/core/super-openable.ts +0 -8
- package/vscode.html-custom-data.json +1 -1
- package/web-types.json +1 -1
package/src/components/range.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { attr,
|
1
|
+
import { attr, tokenList, godown, isNil, joinProperties, loop, part, styles, Ranger, omit } from "@godown/element";
|
2
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";
|
6
|
-
import SuperInput from "../core/super-input.js";
|
6
|
+
import { SuperInput } from "../core/super-input.js";
|
7
7
|
|
8
8
|
const protoName = "range";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
@@ -13,7 +13,7 @@ const cssScope = scopePrefix(protoName);
|
|
13
13
|
*
|
14
14
|
* Value accepts number, or array.
|
15
15
|
*
|
16
|
-
* Number has 1 handle, the array has the number of its elements
|
16
|
+
* Number has 1 handle, the array has the number of its elements.
|
17
17
|
*
|
18
18
|
* @fires input - Fires when the input value changes.
|
19
19
|
* @fires change - Fires when the input value changes.
|
@@ -29,7 +29,7 @@ const cssScope = scopePrefix(protoName);
|
|
29
29
|
${cssScope}--handle-active: var(${cssGlobalVars.active});
|
30
30
|
${cssScope}--track-width: .5em;
|
31
31
|
${cssScope}--length: var(${cssGlobalVars.input}-width);
|
32
|
-
background: var(${cssGlobalVars.
|
32
|
+
background: var(${cssGlobalVars.passive});
|
33
33
|
width: var(${cssScope}--length);
|
34
34
|
display: block;
|
35
35
|
}
|
@@ -136,7 +136,7 @@ class Range extends SuperInput {
|
|
136
136
|
step: number;
|
137
137
|
|
138
138
|
/**
|
139
|
-
*
|
139
|
+
* Whether to display the range vertically.
|
140
140
|
*/
|
141
141
|
@property({ type: Boolean, reflect: true })
|
142
142
|
vertical = false;
|
@@ -164,18 +164,9 @@ class Range extends SuperInput {
|
|
164
164
|
@state()
|
165
165
|
lastFocus?: number;
|
166
166
|
|
167
|
+
protected _ranger: Ranger;
|
167
168
|
private __focusStack: number[] = [];
|
168
169
|
|
169
|
-
/**
|
170
|
-
* Returns true when the second number is greater than the first number.
|
171
|
-
*/
|
172
|
-
get reverse(): boolean {
|
173
|
-
return this.range ? this.value[0] > this.value[1] : false;
|
174
|
-
}
|
175
|
-
|
176
|
-
/**
|
177
|
-
* If value is array.
|
178
|
-
*/
|
179
170
|
get range(): boolean {
|
180
171
|
return Array.isArray(this.value);
|
181
172
|
}
|
@@ -188,9 +179,7 @@ class Range extends SuperInput {
|
|
188
179
|
}
|
189
180
|
|
190
181
|
/**
|
191
|
-
*
|
192
|
-
* @param value Fill value.
|
193
|
-
* @returns Array with length of len.
|
182
|
+
* Pad the value to the specified length.
|
194
183
|
*/
|
195
184
|
padValue(len: number, value = 0): number[] {
|
196
185
|
const { rangeValue } = this;
|
@@ -201,26 +190,35 @@ class Range extends SuperInput {
|
|
201
190
|
return rangeValue;
|
202
191
|
}
|
203
192
|
|
193
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
|
194
|
+
super.attributeChangedCallback(name, _old, value);
|
195
|
+
if (name === "max" || name === "min" || name === "step") {
|
196
|
+
this._ranger = new Ranger(this.min, this.max, this.step);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
get observedRecord(): Record<string, any> {
|
201
|
+
return omit(super.observedRecord, "outline-type");
|
202
|
+
}
|
203
|
+
|
204
204
|
protected render(): TemplateResult<1> {
|
205
205
|
const rangeValue = this.padValue(2);
|
206
206
|
const from = Math.min(...rangeValue);
|
207
207
|
const to = Math.max(...rangeValue);
|
208
|
-
const gap = this.
|
208
|
+
const gap = this._ranger.diff;
|
209
209
|
|
210
210
|
return html`
|
211
211
|
<div
|
212
212
|
part="root"
|
213
213
|
${attr(this.observedRecord)}
|
214
214
|
@mousedown="${this.disabled ? null : this._handleMousedownRoot}"
|
215
|
-
style="${joinProperties(
|
216
|
-
"--from"
|
217
|
-
"--to"
|
218
|
-
...(
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
: {}),
|
223
|
-
})}"
|
215
|
+
style="${joinProperties([
|
216
|
+
["--from", `${((from - this.min) / gap) * 100}%`],
|
217
|
+
["--to", `${((to - this.min) / gap) * 100}%`],
|
218
|
+
...rangeValue.map(
|
219
|
+
(value, index) => [`--handle-${index}`, `${((value - this.min) / gap) * 100}%`] as [string, string],
|
220
|
+
),
|
221
|
+
])}"
|
224
222
|
>
|
225
223
|
<div part="track"></div>
|
226
224
|
${loop(this.rangeValue.length, (index) => this._renderHandle(index))}
|
@@ -229,26 +227,32 @@ class Range extends SuperInput {
|
|
229
227
|
}
|
230
228
|
|
231
229
|
protected _renderHandle(index: number): TemplateResult<1> {
|
232
|
-
const { range } = this;
|
233
|
-
|
230
|
+
const { disabled, range, rangeValue } = this;
|
231
|
+
|
232
|
+
// in single-handle mod (value is a number or an array with length 1),
|
233
|
+
const end = !range || (range && index === rangeValue.length - 1 && rangeValue.length === 1);
|
234
234
|
return html`
|
235
235
|
<i
|
236
236
|
tabindex="0"
|
237
237
|
part="handle"
|
238
|
-
class="${
|
239
|
-
@mousedown="${
|
240
|
-
@focus="${
|
241
|
-
@blur="${
|
242
|
-
style="
|
243
|
-
|
244
|
-
|
245
|
-
})"
|
238
|
+
class="${tokenList({ "last-focus": this.lastFocus === index })}"
|
239
|
+
@mousedown="${disabled ? null : this.createMouseDown(index)}"
|
240
|
+
@focus="${disabled ? null : () => this.focusHandle(index)}"
|
241
|
+
@blur="${disabled ? null : this.blurHandle}"
|
242
|
+
style="${joinProperties({
|
243
|
+
"z-index": this.__focusStack.indexOf(index) + 1,
|
244
|
+
"--handle": `var(--${end ? "to" : `handle-${index}`})`,
|
245
|
+
})}"
|
246
246
|
></i>
|
247
247
|
`;
|
248
248
|
}
|
249
249
|
|
250
250
|
private __keydownEvent: EventListenerOrEventListenerObject;
|
251
251
|
|
252
|
+
/**
|
253
|
+
* Focuses the handle at the given index, updates the focus stack, and dispatches a "focus" event.
|
254
|
+
* @param index - The index of the handle to focus.
|
255
|
+
*/
|
252
256
|
focusHandle(index: number): void {
|
253
257
|
this.lastFocus = index;
|
254
258
|
const indexOfFocusStack = this.__focusStack.indexOf(index);
|
@@ -264,44 +268,61 @@ class Range extends SuperInput {
|
|
264
268
|
this.dispatchEvent(new CustomEvent("focus", { detail: index }));
|
265
269
|
}
|
266
270
|
|
271
|
+
/**
|
272
|
+
* Removes the focus from the currently focused handle and dispatches a "blur" event.
|
273
|
+
*/
|
267
274
|
blurHandle(): void {
|
268
275
|
this.lastFocus = undefined;
|
269
276
|
this.__keydownEvent = this.events.remove(document, "keydown", this.__keydownEvent);
|
270
277
|
this.dispatchEvent(new CustomEvent("blur"));
|
271
278
|
}
|
272
279
|
|
280
|
+
/**
|
281
|
+
* Creates a keydown event handler that updates the value of the range based on arrow key presses.
|
282
|
+
* @param index - The index of the handle to update.
|
283
|
+
* @returns A function that handles the keydown event and updates the range value.
|
284
|
+
*/
|
273
285
|
protected createKeydownEvent(index: number) {
|
274
|
-
|
286
|
+
const { rangeValue, step } = this;
|
287
|
+
if (rangeValue.length < 2) {
|
275
288
|
index = 0;
|
276
289
|
}
|
277
290
|
return (e: KeyboardEvent): void => {
|
291
|
+
const old = rangeValue[index];
|
278
292
|
if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
279
293
|
e.preventDefault();
|
280
|
-
this.createSetValue(index)(
|
294
|
+
this.createSetValue(index)(old - step);
|
281
295
|
} else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
282
296
|
e.preventDefault();
|
283
|
-
this.createSetValue(index)(
|
297
|
+
this.createSetValue(index)(old + step);
|
284
298
|
}
|
285
299
|
};
|
286
300
|
}
|
287
301
|
|
288
|
-
|
302
|
+
/**
|
303
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
304
|
+
* @param index - The index of the handle to focus.
|
305
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
306
|
+
*/
|
307
|
+
protected createMouseDown(index: number) {
|
289
308
|
return (e: MouseEvent): void => {
|
290
309
|
this.focusHandle(index);
|
291
310
|
this.createMousedownListener(this.createSetValue(index))(e);
|
292
311
|
};
|
293
312
|
}
|
294
313
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
314
|
+
/**
|
315
|
+
* Creates a function that sets the value of the range at the given index.
|
316
|
+
* @param index - The index of the value to set.
|
317
|
+
* @returns A function that sets the value of the range.
|
318
|
+
*/
|
319
|
+
protected createSetValue(index: number) {
|
320
|
+
return (value: number): void => {
|
321
|
+
const normalizeValue = this._ranger.normalize(value);
|
322
|
+
let newValue: number | number[] = normalizeValue;
|
302
323
|
if (this.range) {
|
303
|
-
newValue = [...this.
|
304
|
-
newValue[index] =
|
324
|
+
newValue = [...(this.value as number[])];
|
325
|
+
newValue[index] = normalizeValue;
|
305
326
|
}
|
306
327
|
this.value = newValue;
|
307
328
|
this.dispatchEvent(new CustomEvent("range", { detail: this.value }));
|
@@ -310,26 +331,18 @@ class Range extends SuperInput {
|
|
310
331
|
|
311
332
|
/**
|
312
333
|
* Compute value from event.
|
334
|
+
* @returns The value closest to the event client position.
|
313
335
|
*/
|
314
|
-
protected _computeValue(
|
315
|
-
const
|
316
|
-
|
317
|
-
const value = Math.round((div * (this.max - this.min)) / this.step) * this.step;
|
318
|
-
return this.normalizeValue(value);
|
336
|
+
protected _computeValue({ clientX, clientY }: MouseEvent): number {
|
337
|
+
const { top, left, height, width } = this._root.getBoundingClientRect();
|
338
|
+
return this._ranger.present(this.vertical ? (clientY - top) / height : (clientX - left) / width);
|
319
339
|
}
|
320
340
|
|
321
341
|
/**
|
322
|
-
*
|
342
|
+
* Handles the mouse down event on the root element of the range component.
|
343
|
+
* Computes the closest value to the mouse position, sets the value, and focuses the corresponding handle.
|
344
|
+
* @param e - The mouse down event object.
|
323
345
|
*/
|
324
|
-
normalizeValue(value: number): number {
|
325
|
-
if (value > this.max) {
|
326
|
-
value -= this.step;
|
327
|
-
} else if (value < this.min) {
|
328
|
-
value += this.step;
|
329
|
-
}
|
330
|
-
return value;
|
331
|
-
}
|
332
|
-
|
333
346
|
protected _handleMousedownRoot(e: MouseEvent): void {
|
334
347
|
const value = this._computeValue(e);
|
335
348
|
const index = this.range
|
@@ -345,7 +358,11 @@ class Range extends SuperInput {
|
|
345
358
|
this.createMousedownListener(set)(e);
|
346
359
|
this.focusHandle(index);
|
347
360
|
}
|
348
|
-
|
361
|
+
/**
|
362
|
+
* Creates a mouse down event handler that focuses the handle at the given index and sets the value of the range.
|
363
|
+
* @param index - The index of the handle to focus.
|
364
|
+
* @returns A function that handles the mouse down event and updates the range value.
|
365
|
+
*/
|
349
366
|
protected createMousedownListener(mouseMoveCallback: (arg0: number) => void) {
|
350
367
|
return (e: MouseEvent): void => {
|
351
368
|
e.preventDefault();
|
@@ -360,10 +377,15 @@ class Range extends SuperInput {
|
|
360
377
|
};
|
361
378
|
}
|
362
379
|
|
363
|
-
|
380
|
+
/**
|
381
|
+
* Creates a mouse move event handler that updates the range value based on the mouse position.
|
382
|
+
* @param callback - A function to call with the new value when the mouse is moved.
|
383
|
+
* @returns A function that handles the mouse move event and updates the range value.
|
384
|
+
*/
|
385
|
+
protected createMousemoveListener(callback: (newValue: number) => void) {
|
364
386
|
return (e: MouseEvent): void => {
|
365
387
|
const value = this._computeValue(e);
|
366
|
-
if (value
|
388
|
+
if (value !== this._ranger.restrict(value)) {
|
367
389
|
return;
|
368
390
|
}
|
369
391
|
callback?.call(this, value);
|
@@ -371,7 +393,7 @@ class Range extends SuperInput {
|
|
371
393
|
}
|
372
394
|
|
373
395
|
protected _connectedInit(): void {
|
374
|
-
const gap = this.
|
396
|
+
const gap = this._ranger.diff;
|
375
397
|
this.step ||= gap / 100;
|
376
398
|
if (isNil(this.value)) {
|
377
399
|
if (!isNil(this.default)) {
|
package/src/components/rotate.ts
CHANGED
@@ -73,11 +73,13 @@ class Rotate extends GlobalStyle {
|
|
73
73
|
|
74
74
|
/**
|
75
75
|
* Compute offset.
|
76
|
-
*
|
77
|
-
* `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`
|
78
|
-
* ```
|
79
|
-
* @param e Mouse move event.
|
76
|
+
*
|
80
77
|
* @returns rotateX, rotateY
|
78
|
+
* @example
|
79
|
+
* ```ts
|
80
|
+
* const { rotateX, rotateY } = this._computeOffset(e);
|
81
|
+
* `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`;
|
82
|
+
* ```
|
81
83
|
*/
|
82
84
|
protected _computeOffset(e: MouseEvent): {
|
83
85
|
rotateX: number;
|
package/src/components/router.ts
CHANGED
@@ -160,10 +160,9 @@ class Router extends GlobalStyle {
|
|
160
160
|
Router.routerInstances.add(this);
|
161
161
|
|
162
162
|
if (this.type !== "field") {
|
163
|
-
|
164
|
-
mutationObserver.observe(this, {
|
165
|
-
attributeFilter: ["slot"],
|
163
|
+
this.observers.add(this, MutationObserver, this.collectSlottedRoutes, {
|
166
164
|
attributes: true,
|
165
|
+
attributeFilter: ["slot"],
|
167
166
|
subtree: true,
|
168
167
|
});
|
169
168
|
this.collectSlottedRoutes();
|
package/src/components/select.ts
CHANGED
@@ -4,6 +4,8 @@ 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";
|
7
|
+
import { cssGlobalVars } from "../core/global-style.js";
|
8
|
+
import { type DirectionCardinalY, directionOutsetPlace } from "../core/direction.js";
|
7
9
|
|
8
10
|
function contain(a: string, b: string): boolean {
|
9
11
|
return a && b && a.toLowerCase().includes(b.toLowerCase());
|
@@ -46,29 +48,29 @@ const protoName = "select";
|
|
46
48
|
* @category input
|
47
49
|
*/
|
48
50
|
@godown(protoName)
|
49
|
-
@styles(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
width: 100%;
|
57
|
-
visibility: hidden;
|
58
|
-
}
|
51
|
+
@styles(
|
52
|
+
directionOutsetPlace,
|
53
|
+
css`
|
54
|
+
:host(:focus-within),
|
55
|
+
.outline {
|
56
|
+
${cssGlobalVars.input}-outline-color: var(${cssGlobalVars.active});
|
57
|
+
}
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
[part="input"] {
|
60
|
+
text-overflow: ellipsis;
|
61
|
+
}
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
[part="content"] {
|
64
|
+
position: absolute;
|
65
|
+
width: 100%;
|
66
|
+
visibility: hidden;
|
67
|
+
}
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
[visible] [part="content"] {
|
70
|
+
visibility: visible;
|
71
|
+
}
|
72
|
+
`,
|
73
|
+
)
|
72
74
|
class Select extends Input {
|
73
75
|
// @ts-ignore
|
74
76
|
value: string | string[];
|
@@ -83,7 +85,7 @@ class Select extends Input {
|
|
83
85
|
protected _content: HTMLElement;
|
84
86
|
|
85
87
|
@property()
|
86
|
-
direction:
|
88
|
+
direction: DirectionCardinalY;
|
87
89
|
|
88
90
|
@property({ type: Boolean })
|
89
91
|
multiple = false;
|
@@ -92,21 +94,25 @@ class Select extends Input {
|
|
92
94
|
visible = false;
|
93
95
|
|
94
96
|
@state()
|
95
|
-
protected autoDirection:
|
97
|
+
protected autoDirection: DirectionCardinalY = "bottom";
|
96
98
|
|
97
99
|
protected lastChecked: HTMLElement;
|
98
100
|
protected defaultText: string;
|
99
101
|
protected defaultChecked: HTMLElement[];
|
100
102
|
private __store: { value: string; text: string }[] = [];
|
101
103
|
|
104
|
+
get observedRecord(): Record<string, any> {
|
105
|
+
return {
|
106
|
+
...super.observedRecord,
|
107
|
+
direction: this.direction || this.autoDirection,
|
108
|
+
};
|
109
|
+
}
|
110
|
+
|
102
111
|
protected render(): TemplateResult<1> {
|
103
112
|
return html`
|
104
113
|
<div
|
105
114
|
part="root"
|
106
|
-
${attr(
|
107
|
-
...this.observedRecord,
|
108
|
-
direction: this.direction || this.autoDirection,
|
109
|
-
})}
|
115
|
+
${attr(this.observedRecord)}
|
110
116
|
class="input-field"
|
111
117
|
>
|
112
118
|
${[
|
@@ -138,6 +144,7 @@ class Select extends Input {
|
|
138
144
|
<label
|
139
145
|
for="${this.makeId}"
|
140
146
|
part="content"
|
147
|
+
direction-outset-place
|
141
148
|
>
|
142
149
|
${htmlSlot()}
|
143
150
|
</label>
|
package/src/components/split.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { type HandlerEvent, attr,
|
1
|
+
import { type HandlerEvent, attr, tokenList, godown, styles, loop, omit } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property, state } from "lit/decorators.js";
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
6
|
-
import SuperInput from "../core/super-input.js";
|
6
|
+
import { SuperInput } from "../core/super-input.js";
|
7
7
|
|
8
8
|
const protoName = "split";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
@@ -24,7 +24,6 @@ const cssScope = scopePrefix(protoName);
|
|
24
24
|
@godown(protoName)
|
25
25
|
@styles(css`
|
26
26
|
:host {
|
27
|
-
color: var(${cssGlobalVars.foreground});
|
28
27
|
display: block;
|
29
28
|
border-radius: 1px;
|
30
29
|
width: fit-content;
|
@@ -50,9 +49,10 @@ const cssScope = scopePrefix(protoName);
|
|
50
49
|
width: var(${cssScope}--size);
|
51
50
|
height: var(${cssScope}--size);
|
52
51
|
vertical-align: top;
|
53
|
-
text-align: center;
|
54
|
-
background-color: var(${cssGlobalVars.input}-background);
|
55
52
|
border-radius: inherit;
|
53
|
+
display: inline-flex;
|
54
|
+
align-items: center;
|
55
|
+
justify-content: center;
|
56
56
|
}
|
57
57
|
|
58
58
|
[part="input"] {
|
@@ -65,7 +65,7 @@ const cssScope = scopePrefix(protoName);
|
|
65
65
|
}
|
66
66
|
|
67
67
|
.focus {
|
68
|
-
|
68
|
+
${cssGlobalVars.input}-outline-color: var(${cssGlobalVars.active});
|
69
69
|
}
|
70
70
|
`)
|
71
71
|
class Split extends SuperInput {
|
@@ -87,6 +87,10 @@ class Split extends SuperInput {
|
|
87
87
|
@state()
|
88
88
|
currentValue: (string | void)[] = [];
|
89
89
|
|
90
|
+
get observedRecord(): Record<string, any> {
|
91
|
+
return omit(super.observedRecord, "outline-type");
|
92
|
+
}
|
93
|
+
|
90
94
|
protected render(): TemplateResult<1> {
|
91
95
|
return html`
|
92
96
|
<div
|
@@ -98,7 +102,8 @@ class Split extends SuperInput {
|
|
98
102
|
(index: number) => html`
|
99
103
|
<span
|
100
104
|
part="input-box"
|
101
|
-
|
105
|
+
outline-type="${this.outlineType}"
|
106
|
+
class="${tokenList({ focus: this.current === index })}"
|
102
107
|
@click="${this.disabled ? null : () => this.focusAt(index)}"
|
103
108
|
>
|
104
109
|
${this.currentValue[index]}
|
package/src/components/switch.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { attr, godown, styles } from "@godown/element";
|
1
|
+
import { attr, godown, omit, styles } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property, query } from "lit/decorators.js";
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
6
|
-
import SuperInput from "../core/super-input.js";
|
6
|
+
import { SuperInput } from "../core/super-input.js";
|
7
7
|
|
8
8
|
const protoName = "switch";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
@@ -11,9 +11,6 @@ const cssScope = scopePrefix(protoName);
|
|
11
11
|
/**
|
12
12
|
* {@linkcode Switch} renders a switch.
|
13
13
|
*
|
14
|
-
* The switch is rectangular by default,
|
15
|
-
* set the round property to rounded switch.
|
16
|
-
*
|
17
14
|
* @fires change - Fires when the switch is switched.
|
18
15
|
* @category input
|
19
16
|
*/
|
@@ -32,18 +29,23 @@ const cssScope = scopePrefix(protoName);
|
|
32
29
|
${cssScope}-handle-size: 1.25em;
|
33
30
|
${cssScope}-handle-space: .125em;
|
34
31
|
${cssScope}-transition: .2s ease-in-out;
|
35
|
-
|
32
|
+
border-radius: calc(var(${cssScope}-height) / 2);
|
33
|
+
background: var(${cssGlobalVars.passive});
|
36
34
|
vertical-align: bottom;
|
37
|
-
|
35
|
+
transition: 0.2s ease-in-out;
|
36
|
+
transition-property: background, left;
|
37
|
+
}
|
38
|
+
|
39
|
+
:host([checked]) {
|
40
|
+
background: var(${cssGlobalVars.active});
|
38
41
|
}
|
39
42
|
|
40
43
|
[part="root"],
|
41
44
|
[part="handle"] {
|
42
|
-
transition:
|
45
|
+
transition: inherit;
|
43
46
|
}
|
44
47
|
|
45
48
|
[part="root"] {
|
46
|
-
border-radius: inherit;
|
47
49
|
position: relative;
|
48
50
|
height: inherit;
|
49
51
|
}
|
@@ -52,7 +54,6 @@ const cssScope = scopePrefix(protoName);
|
|
52
54
|
opacity: 0;
|
53
55
|
width: 100%;
|
54
56
|
height: 100%;
|
55
|
-
appearance: none;
|
56
57
|
}
|
57
58
|
|
58
59
|
[part="handle"] {
|
@@ -64,45 +65,26 @@ const cssScope = scopePrefix(protoName);
|
|
64
65
|
left: 0;
|
65
66
|
width: 50%;
|
66
67
|
pointer-events: none;
|
67
|
-
border-radius: inherit;
|
68
|
-
}
|
69
|
-
|
70
|
-
:host([round]) {
|
71
|
-
border-radius: calc(var(${cssScope}-height) / 2);
|
72
|
-
background: var(${cssGlobalVars.passive});
|
73
68
|
}
|
74
69
|
|
75
70
|
:host([checked]) [part="handle"] {
|
76
71
|
left: 50%;
|
77
72
|
}
|
78
73
|
|
79
|
-
|
80
|
-
background: var(${cssGlobalVars.active});
|
81
|
-
}
|
82
|
-
|
83
|
-
.rect .false {
|
84
|
-
background: var(${cssGlobalVars.passive});
|
85
|
-
}
|
86
|
-
|
87
|
-
.round [part="handle"] {
|
74
|
+
[part="handle"] {
|
88
75
|
--size: var(${cssScope}-handle-size);
|
89
76
|
border-radius: 100%;
|
90
|
-
background:
|
77
|
+
background: currentColor;
|
91
78
|
width: var(--size);
|
92
79
|
height: var(--size);
|
93
80
|
margin: var(${cssScope}-handle-space);
|
94
81
|
}
|
95
|
-
|
96
|
-
:host([checked]) .round {
|
97
|
-
background: var(${cssGlobalVars.active});
|
98
|
-
}
|
99
82
|
`)
|
100
83
|
class Switch extends SuperInput {
|
101
84
|
/**
|
102
|
-
*
|
85
|
+
* @deprecated
|
103
86
|
*/
|
104
|
-
|
105
|
-
round = false;
|
87
|
+
round: boolean;
|
106
88
|
|
107
89
|
/**
|
108
90
|
* Whether this element is selected or not.
|
@@ -119,8 +101,8 @@ class Switch extends SuperInput {
|
|
119
101
|
/**
|
120
102
|
* Default checked state.
|
121
103
|
*/
|
122
|
-
@property()
|
123
|
-
default =
|
104
|
+
@property({ type: Boolean })
|
105
|
+
default = false;
|
124
106
|
|
125
107
|
/**
|
126
108
|
* Input value.
|
@@ -131,12 +113,16 @@ class Switch extends SuperInput {
|
|
131
113
|
@query("input")
|
132
114
|
protected _input: HTMLInputElement;
|
133
115
|
|
116
|
+
get observedRecord(): Record<string, any> {
|
117
|
+
return omit(super.observedRecord, "outline-type");
|
118
|
+
}
|
119
|
+
|
134
120
|
protected render(): TemplateResult<1> {
|
135
121
|
return html`
|
136
122
|
<div
|
137
123
|
part="root"
|
138
124
|
${attr(this.observedRecord)}
|
139
|
-
class="
|
125
|
+
class="round"
|
140
126
|
>
|
141
127
|
<input
|
142
128
|
part="input"
|
@@ -156,16 +142,15 @@ class Switch extends SuperInput {
|
|
156
142
|
}
|
157
143
|
|
158
144
|
reset(): void {
|
159
|
-
this.checked = this.default
|
145
|
+
this.checked = this.default;
|
160
146
|
this._input.checked = this.checked;
|
161
147
|
}
|
162
148
|
|
163
|
-
|
164
|
-
super.connectedCallback();
|
149
|
+
protected _connectedInit(): void {
|
165
150
|
if (this.checked) {
|
166
|
-
this.default =
|
151
|
+
this.default = true;
|
167
152
|
}
|
168
|
-
if (this.default ===
|
153
|
+
if (this.default === true) {
|
169
154
|
this.checked = true;
|
170
155
|
}
|
171
156
|
}
|
package/src/components/text.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { attr,
|
1
|
+
import { attr, tokenList, godown, htmlSlot, styles } from "@godown/element";
|
2
2
|
import { type TemplateResult, css, html } from "lit";
|
3
3
|
import { property } from "lit/decorators.js";
|
4
4
|
|
@@ -80,7 +80,7 @@ class Text extends GlobalStyle {
|
|
80
80
|
<span
|
81
81
|
part="root"
|
82
82
|
${attr(this.observedRecord)}
|
83
|
-
class="${
|
83
|
+
class="${tokenList(this.underline)}"
|
84
84
|
>
|
85
85
|
${htmlSlot()}
|
86
86
|
</span>
|