svelte-ant-design 0.5.1 → 0.5.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/README.md +1 -1
- package/dist/Select/Select.svelte +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/clickable.d.ts +1 -0
- package/dist/internal/clickable.js +13 -0
- package/dist/internal/popup/layers.d.ts +4 -0
- package/dist/internal/popup/layers.js +54 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Ant Design.
|
|
|
18
18
|
|
|
19
19
|
## Status
|
|
20
20
|
|
|
21
|
-
Version `0.5.
|
|
21
|
+
Version `0.5.2`. Available components: `Button`, `Checkbox` (with `CheckboxGroup`), `Input` (with `InputTextArea`, `InputPassword`, `InputSearch` and `InputOTP`), `Select` (with `SelectOption` and `SelectOptGroup`), `Switch`. More components are planned.
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { onMount, untrack, type Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
import Popup from '../internal/popup/Popup.svelte';
|
|
5
|
+
import { clickable } from '../internal/clickable.js';
|
|
5
6
|
import { resolveOption } from '../internal/options.js';
|
|
6
7
|
import { classList, styleText } from '../internal/semantic.js';
|
|
7
8
|
import { setSelectContext, type Registration } from './context.js';
|
|
@@ -799,6 +800,7 @@
|
|
|
799
800
|
classNames?.listItem
|
|
800
801
|
)}
|
|
801
802
|
style={styleText(styles?.listItem)}
|
|
803
|
+
use:clickable
|
|
802
804
|
onclick={() => selectEntry(entry)}
|
|
803
805
|
onmousemove={() => {
|
|
804
806
|
if (activeValue === entry.value || isDisabled) return;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.5.
|
|
1
|
+
export declare const VERSION = "0.5.2";
|
|
2
2
|
export { default as Button } from './Button/Button.svelte';
|
|
3
3
|
export { default as Switch } from './Switch/Switch.svelte';
|
|
4
4
|
export { default as Checkbox } from './Checkbox/Checkbox.svelte';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Public API of the library. Components are re-exported from here.
|
|
2
|
-
export const VERSION = '0.5.
|
|
2
|
+
export const VERSION = '0.5.2';
|
|
3
3
|
export { default as Button } from './Button/Button.svelte';
|
|
4
4
|
export { default as Switch } from './Switch/Switch.svelte';
|
|
5
5
|
export { default as Checkbox } from './Checkbox/Checkbox.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clickable(node: HTMLElement): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes WebKit send the `click` of a tap to an element that is not a link, a button or a field.
|
|
3
|
+
*
|
|
4
|
+
* In WebKit a tap on such an element sends no `click` (and no `mousedown`) unless the element has a click listener
|
|
5
|
+
* of its own, a `tabindex` or an `onclick` attribute. Svelte does not put the listener of `onclick` on the element:
|
|
6
|
+
* it puts one on the document (event delegation), which WebKit does not count, so a `div` with an `onclick` in
|
|
7
|
+
* Svelte cannot be tapped. An empty listener on the element itself is enough; the real handler stays where it is.
|
|
8
|
+
* Use it as `use:clickable` on an element whose `onclick` is the only way to act on it, such as an option of a list.
|
|
9
|
+
*/
|
|
10
|
+
const noop = () => { };
|
|
11
|
+
export function clickable(node) {
|
|
12
|
+
node.addEventListener('click', noop);
|
|
13
|
+
}
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* are open: a press outside closes the popups it is outside of, and Escape closes the topmost one only.
|
|
6
6
|
* A popup opened from inside another popup (a Select inside a Popover) is its child: a press in the child
|
|
7
7
|
* is inside the parent as well, so the parent stays open while the child is used.
|
|
8
|
+
*
|
|
9
|
+
* A mouse or a pen presses on `pointerdown`. A finger is decided when it comes up, and only if it was a tap:
|
|
10
|
+
* a finger that goes down may be about to scroll the page, and closing at that moment would close the popup
|
|
11
|
+
* under the user's hand (decision 14).
|
|
8
12
|
*/
|
|
9
13
|
export type DismissReason = 'outsidePress' | 'escape';
|
|
10
14
|
export interface Layer {
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* are open: a press outside closes the popups it is outside of, and Escape closes the topmost one only.
|
|
6
6
|
* A popup opened from inside another popup (a Select inside a Popover) is its child: a press in the child
|
|
7
7
|
* is inside the parent as well, so the parent stays open while the child is used.
|
|
8
|
+
*
|
|
9
|
+
* A mouse or a pen presses on `pointerdown`. A finger is decided when it comes up, and only if it was a tap:
|
|
10
|
+
* a finger that goes down may be about to scroll the page, and closing at that moment would close the popup
|
|
11
|
+
* under the user's hand (decision 14).
|
|
8
12
|
*/
|
|
9
13
|
const stack = [];
|
|
10
14
|
/** The open popups, the oldest first. The last one is the topmost. */
|
|
@@ -32,14 +36,58 @@ export function isInsideLayer(layer, target) {
|
|
|
32
36
|
return true;
|
|
33
37
|
return stack.some((other) => other !== layer && parentOf(other) === layer && isInsideLayer(other, target));
|
|
34
38
|
}
|
|
39
|
+
/** How far a finger may move and still be a tap, in CSS pixels. */
|
|
40
|
+
const TAP_SLOP = 10;
|
|
41
|
+
let touch = null;
|
|
42
|
+
function outsideLayers(target) {
|
|
43
|
+
return [...stack].reverse().filter((layer) => layer.outsidePress() && !isInsideLayer(layer, target));
|
|
44
|
+
}
|
|
45
|
+
function endTouch() {
|
|
46
|
+
touch = null;
|
|
47
|
+
document.removeEventListener('pointermove', onTouchMove, true);
|
|
48
|
+
document.removeEventListener('pointerup', onTouchUp, true);
|
|
49
|
+
document.removeEventListener('pointercancel', endTouch, true);
|
|
50
|
+
}
|
|
51
|
+
/** A finger that moves is scrolling or dragging, not pressing. */
|
|
52
|
+
function onTouchMove(event) {
|
|
53
|
+
const { id, x, y } = touch;
|
|
54
|
+
if (event.pointerId === id && Math.hypot(event.clientX - x, event.clientY - y) > TAP_SLOP)
|
|
55
|
+
endTouch();
|
|
56
|
+
}
|
|
57
|
+
function onTouchUp(event) {
|
|
58
|
+
const { id, layers } = touch;
|
|
59
|
+
if (event.pointerId !== id)
|
|
60
|
+
return;
|
|
61
|
+
endTouch();
|
|
62
|
+
// A popup may have closed since the finger went down.
|
|
63
|
+
for (const layer of layers)
|
|
64
|
+
if (stack.includes(layer))
|
|
65
|
+
layer.dismiss('outsidePress');
|
|
66
|
+
}
|
|
35
67
|
function onPointerDown(event) {
|
|
36
68
|
// A press on the document always has a node as its target.
|
|
37
69
|
const target = event.target;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
layer.
|
|
70
|
+
if (event.pointerType !== 'touch') {
|
|
71
|
+
// Topmost first. A copy, because a dismissal may unregister a layer.
|
|
72
|
+
for (const layer of [...stack].reverse()) {
|
|
73
|
+
if (layer.outsidePress() && !isInsideLayer(layer, target))
|
|
74
|
+
layer.dismiss('outsidePress');
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
42
77
|
}
|
|
78
|
+
// A second finger: a pinch, or a scroll with two fingers.
|
|
79
|
+
if (touch) {
|
|
80
|
+
endTouch();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const layers = outsideLayers(target);
|
|
84
|
+
if (layers.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
touch = { id: event.pointerId, x: event.clientX, y: event.clientY, layers };
|
|
87
|
+
document.addEventListener('pointermove', onTouchMove, { capture: true, passive: true });
|
|
88
|
+
document.addEventListener('pointerup', onTouchUp, true);
|
|
89
|
+
// The browser takes the touch for scrolling the page: it cancels the pointer.
|
|
90
|
+
document.addEventListener('pointercancel', endTouch, true);
|
|
43
91
|
}
|
|
44
92
|
function onKeyDown(event) {
|
|
45
93
|
if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing)
|
|
@@ -56,6 +104,8 @@ function listen() {
|
|
|
56
104
|
document.addEventListener('keydown', onKeyDown);
|
|
57
105
|
}
|
|
58
106
|
function unlisten() {
|
|
107
|
+
if (touch)
|
|
108
|
+
endTouch();
|
|
59
109
|
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
60
110
|
document.removeEventListener('keydown', onKeyDown);
|
|
61
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-ant-design",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "An independent UI component library for Svelte 5, inspired by Ant Design.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"test:coverage": "vitest run --coverage",
|
|
60
60
|
"test:watch": "vitest",
|
|
61
61
|
"test:e2e": "playwright test",
|
|
62
|
+
"test:floor": "node scripts/floor/run.mjs",
|
|
62
63
|
"test:docs": "npm run verify -w docs && npm run test:e2e -w docs",
|
|
63
64
|
"test:mutation": "node scripts/mutation-test.mjs",
|
|
64
65
|
"lint": "eslint ."
|