@alulore/kumiko 0.19.1 → 0.20.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/dist/board/board-api.d.ts +2 -1
- package/dist/board/board-api.js +1 -1
- package/dist/board/board-motion.js +29 -1
- package/dist/board/board-slots.d.ts +14 -7
- package/dist/board/board-slots.js +5 -3
- package/dist/board/board.d.ts +20 -5
- package/dist/board/board.js +28 -5
- package/dist/board/keep-capture.d.ts +10 -5
- package/dist/board/keep-capture.js +48 -13
- package/dist/cooldown/cooldown-button.d.ts +30 -0
- package/dist/cooldown/cooldown-button.js +75 -0
- package/dist/cooldown/cooldown-labels.d.ts +8 -0
- package/dist/cooldown/cooldown-labels.js +4 -0
- package/dist/cooldown/cooldown-time.d.ts +8 -0
- package/dist/cooldown/cooldown-time.js +20 -0
- package/dist/cooldown/cooldown.css +21 -0
- package/dist/cooldown/index.d.ts +4 -0
- package/dist/cooldown/index.js +4 -0
- package/dist/cooldown/use-cooldown.d.ts +30 -0
- package/dist/cooldown/use-cooldown.js +63 -0
- package/dist/dialog/dialog-content.d.ts +5 -0
- package/dist/dialog/dialog-content.js +7 -0
- package/dist/empty-state/empty-state-labels.d.ts +14 -0
- package/dist/empty-state/empty-state-labels.js +10 -0
- package/dist/empty-state/empty-state.css +134 -0
- package/dist/empty-state/empty-state.d.ts +34 -0
- package/dist/empty-state/empty-state.js +61 -0
- package/dist/empty-state/index.d.ts +2 -0
- package/dist/empty-state/index.js +2 -0
- package/dist/form/choice-fields.d.ts +34 -0
- package/dist/form/choice-fields.js +41 -0
- package/dist/form/error-line.d.ts +8 -0
- package/dist/form/error-line.js +47 -0
- package/dist/form/field-props.d.ts +12 -0
- package/dist/form/field-props.js +8 -0
- package/dist/form/field-shell.d.ts +18 -0
- package/dist/form/field-shell.js +51 -0
- package/dist/form/focus-invalid.d.ts +5 -0
- package/dist/form/focus-invalid.js +17 -0
- package/dist/form/form-context.d.ts +2 -0
- package/dist/form/form-context.js +3 -0
- package/dist/form/form-parts.d.ts +20 -0
- package/dist/form/form-parts.js +73 -0
- package/dist/form/form.css +128 -0
- package/dist/form/index.d.ts +10 -0
- package/dist/form/index.js +9 -0
- package/dist/form/shown-error.d.ts +12 -0
- package/dist/form/shown-error.js +27 -0
- package/dist/form/submit-errors.d.ts +36 -0
- package/dist/form/submit-errors.js +46 -0
- package/dist/form/text-fields.d.ts +18 -0
- package/dist/form/text-fields.js +21 -0
- package/dist/form/use-app-form.d.ts +1655 -0
- package/dist/form/use-app-form.js +94 -0
- package/dist/form/use-dialog-link.d.ts +5 -0
- package/dist/form/use-dialog-link.js +30 -0
- package/dist/form/value-fields.d.ts +16 -0
- package/dist/form/value-fields.js +15 -0
- package/dist/map/geo.d.ts +20 -0
- package/dist/map/geo.js +41 -0
- package/dist/map/index.d.ts +5 -0
- package/dist/map/index.js +4 -0
- package/dist/map/label-overlap.d.ts +13 -0
- package/dist/map/label-overlap.js +23 -0
- package/dist/map/load-map.d.ts +12 -0
- package/dist/map/load-map.js +22 -0
- package/dist/map/location-map.d.ts +39 -0
- package/dist/map/location-map.js +171 -0
- package/dist/map/map-frame.d.ts +18 -0
- package/dist/map/map-frame.js +6 -0
- package/dist/map/map-pin.d.ts +4 -0
- package/dist/map/map-pin.js +38 -0
- package/dist/map/map-popup.d.ts +17 -0
- package/dist/map/map-popup.js +101 -0
- package/dist/map/map-source.d.ts +52 -0
- package/dist/map/map-source.js +59 -0
- package/dist/map/map.css +311 -0
- package/dist/map/marker-pins.d.ts +29 -0
- package/dist/map/marker-pins.js +144 -0
- package/dist/map/markers-map.d.ts +57 -0
- package/dist/map/markers-map.js +154 -0
- package/dist/map/use-label-overlap.d.ts +9 -0
- package/dist/map/use-label-overlap.js +55 -0
- package/dist/map/use-map.d.ts +49 -0
- package/dist/map/use-map.js +201 -0
- package/dist/media/encoding.d.ts +32 -0
- package/dist/media/encoding.js +59 -0
- package/dist/media/errors.d.ts +33 -0
- package/dist/media/errors.js +26 -0
- package/dist/media/image.d.ts +9 -0
- package/dist/media/image.js +35 -0
- package/dist/media/index.d.ts +10 -0
- package/dist/media/index.js +10 -0
- package/dist/media/load-mediabunny.d.ts +7 -0
- package/dist/media/load-mediabunny.js +13 -0
- package/dist/media/media-upload.d.ts +40 -0
- package/dist/media/media-upload.js +132 -0
- package/dist/media/media.css +101 -0
- package/dist/media/probe.d.ts +19 -0
- package/dist/media/probe.js +49 -0
- package/dist/media/sizes.d.ts +28 -0
- package/dist/media/sizes.js +51 -0
- package/dist/media/slideshow.d.ts +43 -0
- package/dist/media/slideshow.js +174 -0
- package/dist/media/timeline.d.ts +59 -0
- package/dist/media/timeline.js +105 -0
- package/dist/media/transcode.d.ts +35 -0
- package/dist/media/transcode.js +132 -0
- package/dist/media/upload.d.ts +21 -0
- package/dist/media/upload.js +54 -0
- package/dist/media/use-media-job.d.ts +79 -0
- package/dist/media/use-media-job.js +143 -0
- package/dist/server-render.test.js +93 -0
- package/dist/smooth-caret/caret-controller.js +16 -3
- package/dist/table/table-labels.d.ts +2 -0
- package/dist/table/table-labels.js +1 -0
- package/dist/table/table-sections.js +10 -2
- package/dist/table/table.css +1 -0
- package/dist/theme/define-theme.d.ts +38 -0
- package/dist/theme/define-theme.js +56 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +3 -0
- package/dist/theme/theme-style.d.ts +6 -0
- package/dist/theme/theme-style.js +11 -0
- package/dist/theme/theme-types.d.ts +1 -0
- package/dist/theme/theme-types.js +26 -0
- package/dist/theme/tokens-1.generated.d.ts +1 -0
- package/dist/theme/tokens-1.generated.js +404 -0
- package/dist/theme/tokens-2.generated.d.ts +1 -0
- package/dist/theme/tokens-2.generated.js +404 -0
- package/dist/theme/tokens-3.generated.d.ts +1 -0
- package/dist/theme/tokens-3.generated.js +158 -0
- package/dist/theme/tokens.generated.d.ts +2 -0
- package/dist/theme/tokens.generated.js +6 -0
- package/dist/undo/undo-provider.js +24 -9
- package/package.json +82 -5
|
@@ -58,7 +58,8 @@ export declare function createBoardApi(context: BoardContext): {
|
|
|
58
58
|
}) => boolean;
|
|
59
59
|
capture: {
|
|
60
60
|
pressed(event: PointerEvent, key: string): void;
|
|
61
|
-
mounted(el: HTMLElement, key: string): void;
|
|
61
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
62
|
+
bind(root: HTMLElement): () => void;
|
|
62
63
|
};
|
|
63
64
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
64
65
|
allows: Allows;
|
package/dist/board/board-api.js
CHANGED
|
@@ -119,7 +119,7 @@ export function createBoardApi(context) {
|
|
|
119
119
|
},
|
|
120
120
|
transfer,
|
|
121
121
|
handleRepeat: repeatGate(),
|
|
122
|
-
capture: keepCapture(),
|
|
122
|
+
capture: keepCapture((card) => transfer.dragging(context.store.get(), card)),
|
|
123
123
|
keepFocus: keepFocus(),
|
|
124
124
|
allows,
|
|
125
125
|
hold,
|
|
@@ -67,6 +67,34 @@ function dressCopies(root) {
|
|
|
67
67
|
observer.disconnect();
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/* What can move items: a selection only does while it's carried along. */
|
|
71
|
+
function layoutOf(state) {
|
|
72
|
+
const { moving } = state;
|
|
73
|
+
return [
|
|
74
|
+
state.lanes,
|
|
75
|
+
state.rows,
|
|
76
|
+
state.cells,
|
|
77
|
+
state.folded,
|
|
78
|
+
state.laneDraft,
|
|
79
|
+
state.rowDraft,
|
|
80
|
+
state.pulling,
|
|
81
|
+
moving?.lists,
|
|
82
|
+
moving?.key,
|
|
83
|
+
moving?.pointer,
|
|
84
|
+
moving ? state.selected : null
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
/* Hears only the changes that can move items, so focus and selection don't measure every card. */
|
|
88
|
+
function onLayoutChange(store, listener) {
|
|
89
|
+
let last = layoutOf(store.get());
|
|
90
|
+
return store.subscribe(() => {
|
|
91
|
+
const next = layoutOf(store.get());
|
|
92
|
+
if (next.some((value, index) => value !== last[index])) {
|
|
93
|
+
last = next;
|
|
94
|
+
listener();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
70
98
|
export function bindBoardMotion(el, store) {
|
|
71
99
|
let released = null;
|
|
72
100
|
const remember = () => {
|
|
@@ -76,7 +104,7 @@ export function bindBoardMotion(el, store) {
|
|
|
76
104
|
};
|
|
77
105
|
window.addEventListener("pointerup", remember, { capture: true });
|
|
78
106
|
const unbind = bindFlip(el, {
|
|
79
|
-
subscribe: (listener) => store
|
|
107
|
+
subscribe: (listener) => onLayoutChange(store, listener),
|
|
80
108
|
items: () => el.querySelectorAll("[data-flip-key]:not([data-drag-preview])"),
|
|
81
109
|
prepare: keepInView(el, store),
|
|
82
110
|
enter: (entering) => {
|
|
@@ -59,7 +59,8 @@ export declare function rootSlot(slot: Slot): import("@ui-sdk/core").SlotDefinit
|
|
|
59
59
|
}) => boolean;
|
|
60
60
|
capture: {
|
|
61
61
|
pressed(event: PointerEvent, key: string): void;
|
|
62
|
-
mounted(el: HTMLElement, key: string): void;
|
|
62
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
63
|
+
bind(root: HTMLElement): () => void;
|
|
63
64
|
};
|
|
64
65
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
65
66
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -201,7 +202,8 @@ export declare function sortableSlot(slot: Slot, axis: Axis): import("@ui-sdk/co
|
|
|
201
202
|
}) => boolean;
|
|
202
203
|
capture: {
|
|
203
204
|
pressed(event: PointerEvent, key: string): void;
|
|
204
|
-
mounted(el: HTMLElement, key: string): void;
|
|
205
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
206
|
+
bind(root: HTMLElement): () => void;
|
|
205
207
|
};
|
|
206
208
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
207
209
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -345,7 +347,8 @@ export declare function handleSlot(slot: Slot, axis: Axis): import("@ui-sdk/core
|
|
|
345
347
|
}) => boolean;
|
|
346
348
|
capture: {
|
|
347
349
|
pressed(event: PointerEvent, key: string): void;
|
|
348
|
-
mounted(el: HTMLElement, key: string): void;
|
|
350
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
351
|
+
bind(root: HTMLElement): () => void;
|
|
349
352
|
};
|
|
350
353
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
351
354
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -489,7 +492,8 @@ export declare function insertSlot(slot: Slot): import("@ui-sdk/core").SlotDefin
|
|
|
489
492
|
}) => boolean;
|
|
490
493
|
capture: {
|
|
491
494
|
pressed(event: PointerEvent, key: string): void;
|
|
492
|
-
mounted(el: HTMLElement, key: string): void;
|
|
495
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
496
|
+
bind(root: HTMLElement): () => void;
|
|
493
497
|
};
|
|
494
498
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
495
499
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -631,7 +635,8 @@ export declare function foldSlot(slot: Slot): import("@ui-sdk/core").SlotDefinit
|
|
|
631
635
|
}) => boolean;
|
|
632
636
|
capture: {
|
|
633
637
|
pressed(event: PointerEvent, key: string): void;
|
|
634
|
-
mounted(el: HTMLElement, key: string): void;
|
|
638
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
639
|
+
bind(root: HTMLElement): () => void;
|
|
635
640
|
};
|
|
636
641
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
637
642
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -775,7 +780,8 @@ export declare function cellSlot(slot: Slot): import("@ui-sdk/core").SlotDefinit
|
|
|
775
780
|
}) => boolean;
|
|
776
781
|
capture: {
|
|
777
782
|
pressed(event: PointerEvent, key: string): void;
|
|
778
|
-
mounted(el: HTMLElement, key: string): void;
|
|
783
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
784
|
+
bind(root: HTMLElement): () => void;
|
|
779
785
|
};
|
|
780
786
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
781
787
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -919,7 +925,8 @@ export declare function cardSlot(slot: Slot): import("@ui-sdk/core").SlotDefinit
|
|
|
919
925
|
}) => boolean;
|
|
920
926
|
capture: {
|
|
921
927
|
pressed(event: PointerEvent, key: string): void;
|
|
922
|
-
mounted(el: HTMLElement, key: string): void;
|
|
928
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
929
|
+
bind(root: HTMLElement): () => void;
|
|
923
930
|
};
|
|
924
931
|
keepFocus: (el: HTMLElement, key: string) => (() => void);
|
|
925
932
|
allows: (card: string, cell: string) => boolean;
|
|
@@ -24,7 +24,9 @@ export function rootSlot(slot) {
|
|
|
24
24
|
const unbindPress = bindPressToDrop(store, api.transfer);
|
|
25
25
|
const unbindHome = bindRefusedHome(el, store, api);
|
|
26
26
|
const unbindGutter = bindScrollbarGutter(el);
|
|
27
|
+
const unbindCapture = api.capture.bind(el);
|
|
27
28
|
return () => {
|
|
29
|
+
unbindCapture();
|
|
28
30
|
unbindGutter();
|
|
29
31
|
unbindHome();
|
|
30
32
|
unbindPress();
|
|
@@ -87,7 +89,7 @@ export function sortableSlot(slot, axis) {
|
|
|
87
89
|
}
|
|
88
90
|
export function handleSlot(slot, axis) {
|
|
89
91
|
return slot({
|
|
90
|
-
props: { value:
|
|
92
|
+
props: { value: "string" },
|
|
91
93
|
attrs: (state, part) => ({
|
|
92
94
|
type: "button",
|
|
93
95
|
"aria-roledescription": axis === "lanes" ? "sortable lane" : "sortable row",
|
|
@@ -117,7 +119,7 @@ export function insertSlot(slot) {
|
|
|
117
119
|
}
|
|
118
120
|
export function foldSlot(slot) {
|
|
119
121
|
return slot({
|
|
120
|
-
props: { value:
|
|
122
|
+
props: { value: "string" },
|
|
121
123
|
attrs: (state, { api, key }) => ({
|
|
122
124
|
type: "button",
|
|
123
125
|
"aria-expanded": String(!api.fold.isFolded(state, key))
|
|
@@ -181,8 +183,8 @@ function cardView(state, api, key) {
|
|
|
181
183
|
};
|
|
182
184
|
}
|
|
183
185
|
function bindCard(el, part) {
|
|
184
|
-
part.api.capture.mounted(el, part.key);
|
|
185
186
|
const cleanups = [
|
|
187
|
+
part.api.capture.mounted(el, part.key),
|
|
186
188
|
part.api.keepFocus(el, part.key),
|
|
187
189
|
part.api.roving.bind(el, part),
|
|
188
190
|
part.api.transfer.bindItem(el, part.key),
|
package/dist/board/board.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
declare const parts: import("@ui-sdk/react/primitive").Parts<import("./board-primitive").BoardPrimitive, {
|
|
3
|
+
root: "div";
|
|
4
|
+
lane: "section";
|
|
5
|
+
"lane-handle": "button";
|
|
6
|
+
row: "section";
|
|
7
|
+
"row-handle": "button";
|
|
8
|
+
"row-fold": "button";
|
|
9
|
+
cell: "div";
|
|
10
|
+
insert: "div";
|
|
11
|
+
card: "div";
|
|
12
|
+
}>;
|
|
13
|
+
type LaneProps = ComponentProps<typeof parts.Lane>;
|
|
14
|
+
type RowProps = ComponentProps<typeof parts.Row>;
|
|
15
|
+
export declare function BoardLane(props: LaneProps): React.JSX.Element;
|
|
16
|
+
export declare function BoardRow(props: RowProps): React.JSX.Element;
|
|
17
|
+
export declare function BoardLaneHandle(props: ComponentProps<typeof parts.LaneHandle>): React.JSX.Element;
|
|
18
|
+
export declare function BoardRowHandle(props: ComponentProps<typeof parts.RowHandle>): React.JSX.Element;
|
|
19
|
+
export declare function BoardRowFold(props: ComponentProps<typeof parts.RowFold>): React.JSX.Element;
|
|
1
20
|
export declare const Board: (props: import("@ui-sdk/core").OptionsOf<import("./board-primitive").BoardPrimitive> & object & import("@ui-sdk/core/renderer").BaseSlotProps & {
|
|
2
21
|
key?: import("react").Key | null | undefined;
|
|
3
22
|
ref?: import("react").Ref<HTMLDivElement> | undefined;
|
|
@@ -280,11 +299,7 @@ export declare const Board: (props: import("@ui-sdk/core").OptionsOf<import("./b
|
|
|
280
299
|
render?: import("@ui-sdk/react/primitive").RenderProp<import("./board-types").BoardView> | undefined;
|
|
281
300
|
children?: ((state: import("./board-types").BoardView) => React.ReactNode) | import("react").ReactNode;
|
|
282
301
|
}) => React.ReactElement | null;
|
|
283
|
-
export declare const BoardLane: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "lane", "section">;
|
|
284
|
-
export declare const BoardLaneHandle: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "lane-handle", "button">;
|
|
285
|
-
export declare const BoardRow: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "row", "section">;
|
|
286
|
-
export declare const BoardRowHandle: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "row-handle", "button">;
|
|
287
|
-
export declare const BoardRowFold: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "row-fold", "button">;
|
|
288
302
|
export declare const BoardCell: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "cell", "div">;
|
|
289
303
|
export declare const BoardInsert: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "insert", "div">;
|
|
290
304
|
export declare const BoardCard: import("@ui-sdk/react/primitive").PartComponent<import("./board-primitive").BoardPrimitive, "card", "div">;
|
|
305
|
+
export {};
|
package/dist/board/board.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { createParts } from "@ui-sdk/react/primitive";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
3
5
|
import { board } from "./board-primitive";
|
|
4
6
|
const parts = createParts(board, {
|
|
5
7
|
root: "div",
|
|
@@ -12,12 +14,33 @@ const parts = createParts(board, {
|
|
|
12
14
|
insert: "div",
|
|
13
15
|
card: "div"
|
|
14
16
|
});
|
|
17
|
+
/*
|
|
18
|
+
* Handles and folds take their lane or row from the one around them. ui-sdk
|
|
19
|
+
* would pass it down in its own context, which is a new object on every lane
|
|
20
|
+
* and row render and so re-renders every card inside, memoized or not. The key
|
|
21
|
+
* alone, in a context of our own, only changes when the lane or row does.
|
|
22
|
+
*/
|
|
23
|
+
const LaneKey = createContext(undefined);
|
|
24
|
+
const RowKey = createContext(undefined);
|
|
25
|
+
export function BoardLane(props) {
|
|
26
|
+
return (_jsx(LaneKey.Provider, { value: props.value, children: _jsx(parts.Lane, { ...props }) }));
|
|
27
|
+
}
|
|
28
|
+
export function BoardRow(props) {
|
|
29
|
+
return (_jsx(RowKey.Provider, { value: props.value, children: _jsx(parts.Row, { ...props }) }));
|
|
30
|
+
}
|
|
31
|
+
export function BoardLaneHandle(props) {
|
|
32
|
+
const lane = useContext(LaneKey);
|
|
33
|
+
return _jsx(parts.LaneHandle, { ...props, value: props.value ?? lane });
|
|
34
|
+
}
|
|
35
|
+
export function BoardRowHandle(props) {
|
|
36
|
+
const row = useContext(RowKey);
|
|
37
|
+
return _jsx(parts.RowHandle, { ...props, value: props.value ?? row });
|
|
38
|
+
}
|
|
39
|
+
export function BoardRowFold(props) {
|
|
40
|
+
const row = useContext(RowKey);
|
|
41
|
+
return _jsx(parts.RowFold, { ...props, value: props.value ?? row });
|
|
42
|
+
}
|
|
15
43
|
export const Board = parts.Root;
|
|
16
|
-
export const BoardLane = parts.Lane;
|
|
17
|
-
export const BoardLaneHandle = parts.LaneHandle;
|
|
18
|
-
export const BoardRow = parts.Row;
|
|
19
|
-
export const BoardRowHandle = parts.RowHandle;
|
|
20
|
-
export const BoardRowFold = parts.RowFold;
|
|
21
44
|
export const BoardCell = parts.Cell;
|
|
22
45
|
export const BoardInsert = parts.Insert;
|
|
23
46
|
export const BoardCard = parts.Card;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A card dragged into another cell becomes a new element, and
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* A card dragged into another cell becomes a new element, and one reordered
|
|
3
|
+
* within its cell is moved in the page. Either way the pointer's capture is
|
|
4
|
+
* dropped: a finger's events keep going to the old, detached element, so the
|
|
5
|
+
* drop never arrives, and a mouse's go to whatever is under it, which shows
|
|
6
|
+
* its cursor. The card takes the capture back right after the page changes,
|
|
7
|
+
* before the next pointer event, so there's no gap. `dragging` says whether a
|
|
8
|
+
* pointer is dragging that card.
|
|
5
9
|
*/
|
|
6
|
-
export declare function keepCapture(): {
|
|
10
|
+
export declare function keepCapture(dragging: (key: string) => boolean): {
|
|
7
11
|
pressed(event: PointerEvent, key: string): void;
|
|
8
|
-
mounted(el: HTMLElement, key: string): void;
|
|
12
|
+
mounted(el: HTMLElement, key: string): () => void;
|
|
13
|
+
bind(root: HTMLElement): () => void;
|
|
9
14
|
};
|
|
10
15
|
/**
|
|
11
16
|
* A focused card moved into another cell is a new element. ui-sdk focuses it
|
|
@@ -1,24 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A card dragged into another cell becomes a new element, and
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* A card dragged into another cell becomes a new element, and one reordered
|
|
3
|
+
* within its cell is moved in the page. Either way the pointer's capture is
|
|
4
|
+
* dropped: a finger's events keep going to the old, detached element, so the
|
|
5
|
+
* drop never arrives, and a mouse's go to whatever is under it, which shows
|
|
6
|
+
* its cursor. The card takes the capture back right after the page changes,
|
|
7
|
+
* before the next pointer event, so there's no gap. `dragging` says whether a
|
|
8
|
+
* pointer is dragging that card.
|
|
5
9
|
*/
|
|
6
|
-
export function keepCapture() {
|
|
10
|
+
export function keepCapture(dragging) {
|
|
7
11
|
let held = null;
|
|
12
|
+
const cards = new Map();
|
|
13
|
+
const take = () => {
|
|
14
|
+
const el = held && cards.get(held.key);
|
|
15
|
+
if (!held || !el?.isConnected || !dragging(held.key)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
if (!el.hasPointerCapture(held.pointerId)) {
|
|
20
|
+
el.setPointerCapture(held.pointerId);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
held = null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const done = (event) => {
|
|
28
|
+
if (event.pointerId === held?.pointerId) {
|
|
29
|
+
held = null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
8
32
|
return {
|
|
9
33
|
pressed(event, key) {
|
|
10
34
|
held = { key, pointerId: event.pointerId };
|
|
11
35
|
},
|
|
12
36
|
mounted(el, key) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
cards.set(key, el);
|
|
38
|
+
take();
|
|
39
|
+
return () => {
|
|
40
|
+
if (cards.get(key) === el) {
|
|
41
|
+
cards.delete(key);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
/* Watches the board for moved cards, and forgets the pointer once it lets go. */
|
|
46
|
+
bind(root) {
|
|
47
|
+
const observer = new MutationObserver(take);
|
|
48
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
49
|
+
const doc = root.ownerDocument;
|
|
50
|
+
doc.addEventListener("pointerup", done, true);
|
|
51
|
+
doc.addEventListener("pointercancel", done, true);
|
|
52
|
+
return () => {
|
|
53
|
+
observer.disconnect();
|
|
54
|
+
doc.removeEventListener("pointerup", done, true);
|
|
55
|
+
doc.removeEventListener("pointercancel", done, true);
|
|
56
|
+
};
|
|
22
57
|
}
|
|
23
58
|
};
|
|
24
59
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ButtonProps } from "../button";
|
|
2
|
+
import { type CooldownLabels } from "./cooldown-labels";
|
|
3
|
+
import type { Cooldown } from "./use-cooldown";
|
|
4
|
+
/** What `onPress` may return: a wait the server asked for, in seconds. */
|
|
5
|
+
export type CooldownResult = {
|
|
6
|
+
retryAfter?: number;
|
|
7
|
+
} | undefined;
|
|
8
|
+
export type CooldownButtonProps = Omit<ButtonProps, "onClick" | "status" | "feedback" | "disabled" | "children"> & {
|
|
9
|
+
/** The wait this button starts and shows. From `useCooldown`. */
|
|
10
|
+
cooldown: Cooldown;
|
|
11
|
+
/**
|
|
12
|
+
* What pressing does, such as sending a code. When it resolves the wait
|
|
13
|
+
* starts, for `retryAfter` seconds if it returns that, else the hook's
|
|
14
|
+
* length. When it throws or rejects there is no wait, so the person can try
|
|
15
|
+
* again. Show your own error.
|
|
16
|
+
*/
|
|
17
|
+
onPress: () => CooldownResult | PromiseLike<CooldownResult>;
|
|
18
|
+
/** Its words, in English by default. */
|
|
19
|
+
labels?: Partial<CooldownLabels>;
|
|
20
|
+
/** The button's text when it can be pressed. */
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A button that starts a wait after it is pressed, such as "Resend code".
|
|
25
|
+
* It shows loading while `onPress` runs, then counts down as `Resend in 1:27`
|
|
26
|
+
* and cannot be pressed. It uses `aria-disabled`, so it stays focusable and
|
|
27
|
+
* its name tells a screen reader the time left. When the wait ends, a polite
|
|
28
|
+
* live region says so once. Nothing is announced on each tick.
|
|
29
|
+
*/
|
|
30
|
+
export declare function CooldownButton({ cooldown, onPress, labels, children, ...props }: CooldownButtonProps): React.JSX.Element;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Button } from "../button";
|
|
4
|
+
import { defaultCooldownLabels } from "./cooldown-labels";
|
|
5
|
+
import { formatWait } from "./cooldown-time";
|
|
6
|
+
/** Says the ready message once, when a wait runs out, and clears it when one starts. */
|
|
7
|
+
function useReadyNote(active) {
|
|
8
|
+
const [ready, setReady] = useState(false);
|
|
9
|
+
const wasActive = useRef(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (wasActive.current && !active) {
|
|
12
|
+
setReady(true);
|
|
13
|
+
}
|
|
14
|
+
else if (active) {
|
|
15
|
+
setReady(false);
|
|
16
|
+
}
|
|
17
|
+
wasActive.current = active;
|
|
18
|
+
}, [active]);
|
|
19
|
+
return ready;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs `onPress` once at a time and starts the wait when it resolves. A send
|
|
23
|
+
* that finishes after unmount starts nothing and sets nothing.
|
|
24
|
+
*/
|
|
25
|
+
function useSend(cooldown, onPress) {
|
|
26
|
+
const [phase, setPhase] = useState("idle");
|
|
27
|
+
const sending = useRef(false);
|
|
28
|
+
const mounted = useRef(false);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
mounted.current = true;
|
|
31
|
+
return () => {
|
|
32
|
+
mounted.current = false;
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
async function press() {
|
|
36
|
+
/* A disabled look is a hint, not a guard: refuse here too. */
|
|
37
|
+
if (sending.current || cooldown.active) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
sending.current = true;
|
|
41
|
+
setPhase("sending");
|
|
42
|
+
try {
|
|
43
|
+
const result = await onPress();
|
|
44
|
+
if (mounted.current) {
|
|
45
|
+
cooldown.start(result?.retryAfter);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
/* No wait: the person can try again. The app shows its own error. */
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
sending.current = false;
|
|
53
|
+
if (mounted.current) {
|
|
54
|
+
setPhase("idle");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { phase, press };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A button that starts a wait after it is pressed, such as "Resend code".
|
|
62
|
+
* It shows loading while `onPress` runs, then counts down as `Resend in 1:27`
|
|
63
|
+
* and cannot be pressed. It uses `aria-disabled`, so it stays focusable and
|
|
64
|
+
* its name tells a screen reader the time left. When the wait ends, a polite
|
|
65
|
+
* live region says so once. Nothing is announced on each tick.
|
|
66
|
+
*/
|
|
67
|
+
export function CooldownButton({ cooldown, onPress, labels, children, ...props }) {
|
|
68
|
+
const words = { ...defaultCooldownLabels, ...labels };
|
|
69
|
+
const { phase, press } = useSend(cooldown, onPress);
|
|
70
|
+
const ready = useReadyNote(cooldown.active);
|
|
71
|
+
const waiting = phase === "idle" && cooldown.active;
|
|
72
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { ...props, feedback: false, status: phase === "sending" ? "loading" : undefined, "aria-disabled": waiting ? true : undefined, "data-cooldown": waiting ? "waiting" : undefined, onClick: () => {
|
|
73
|
+
void press();
|
|
74
|
+
}, children: waiting ? words.waiting(formatWait(cooldown.remaining)) : children }), _jsx("span", { "data-slot": "cooldown-live", role: "status", "aria-live": "polite", children: ready ? words.ready : "" })] }));
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The words a cooldown button says. */
|
|
2
|
+
export interface CooldownLabels {
|
|
3
|
+
/** The button's text while waiting. `time` is `m:ss`, like `1:27`. */
|
|
4
|
+
waiting: (time: string) => string;
|
|
5
|
+
/** What a screen reader hears, once, when the wait ends. */
|
|
6
|
+
ready: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const defaultCooldownLabels: CooldownLabels;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Whole seconds left until `endsAt` (epoch ms), rounded up. 0 once it has passed. */
|
|
2
|
+
export declare function remainingSeconds(endsAt: number, now: number): number;
|
|
3
|
+
/** Milliseconds until the remaining time next drops by a whole second. */
|
|
4
|
+
export declare function msToNextSecond(endsAt: number, now: number): number;
|
|
5
|
+
/** Seconds as `m:ss`: 28 is `0:28`, 87 is `1:27`. */
|
|
6
|
+
export declare function formatWait(seconds: number): string;
|
|
7
|
+
/** Whether a server-given wait is usable: a positive, finite number of seconds. */
|
|
8
|
+
export declare function isUsableWait(seconds: unknown): seconds is number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Whole seconds left until `endsAt` (epoch ms), rounded up. 0 once it has passed. */
|
|
2
|
+
export function remainingSeconds(endsAt, now) {
|
|
3
|
+
return endsAt > now ? Math.ceil((endsAt - now) / 1000) : 0;
|
|
4
|
+
}
|
|
5
|
+
/** Milliseconds until the remaining time next drops by a whole second. */
|
|
6
|
+
export function msToNextSecond(endsAt, now) {
|
|
7
|
+
const left = endsAt - now;
|
|
8
|
+
return left > 0 ? ((left - 1) % 1000) + 1 : 0;
|
|
9
|
+
}
|
|
10
|
+
/** Seconds as `m:ss`: 28 is `0:28`, 87 is `1:27`. */
|
|
11
|
+
export function formatWait(seconds) {
|
|
12
|
+
const whole = Math.max(0, Math.ceil(seconds));
|
|
13
|
+
const minutes = Math.floor(whole / 60);
|
|
14
|
+
const rest = String(whole % 60).padStart(2, "0");
|
|
15
|
+
return `${minutes}:${rest}`;
|
|
16
|
+
}
|
|
17
|
+
/** Whether a server-given wait is usable: a positive, finite number of seconds. */
|
|
18
|
+
export function isUsableWait(seconds) {
|
|
19
|
+
return typeof seconds === "number" && Number.isFinite(seconds) && seconds > 0;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@layer kumiko {
|
|
2
|
+
/*
|
|
3
|
+
* The seconds change often: equal-width digits keep the button from jittering. Not in :where(), so the
|
|
4
|
+
* waiting look beats the button's own cursor whatever order the stylesheets load in.
|
|
5
|
+
*/
|
|
6
|
+
[data-slot="button"][data-cooldown="waiting"] {
|
|
7
|
+
font-variant-numeric: tabular-nums;
|
|
8
|
+
opacity: var(--kumiko-button-disabled-opacity, 0.5);
|
|
9
|
+
cursor: not-allowed;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* Heard by a screen reader, never seen. */
|
|
13
|
+
:where([data-slot="cooldown-live"]) {
|
|
14
|
+
position: absolute;
|
|
15
|
+
inline-size: 1px;
|
|
16
|
+
block-size: 1px;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
clip-path: inset(50%);
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CooldownButton, type CooldownButtonProps, type CooldownResult } from "./cooldown-button";
|
|
2
|
+
export { type CooldownLabels } from "./cooldown-labels";
|
|
3
|
+
export { formatWait, remainingSeconds } from "./cooldown-time";
|
|
4
|
+
export { useCooldown, type Cooldown, type CooldownOptions } from "./use-cooldown";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface CooldownOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the wait across a reload and in other tabs, under this key, such as
|
|
4
|
+
* `reset:${email}`. The key is the app's to choose. Without one, the wait
|
|
5
|
+
* lives in memory.
|
|
6
|
+
*/
|
|
7
|
+
key?: string;
|
|
8
|
+
/** How long a wait lasts when `start` is called with no length, in seconds. */
|
|
9
|
+
seconds: number;
|
|
10
|
+
/** The clock, in epoch milliseconds. For tests. @defaultValue Date.now */
|
|
11
|
+
now?: () => number;
|
|
12
|
+
}
|
|
13
|
+
export interface Cooldown {
|
|
14
|
+
/** Whole seconds left, rounded up. 0 when nothing is waiting. */
|
|
15
|
+
remaining: number;
|
|
16
|
+
/** Whether a wait is running. */
|
|
17
|
+
active: boolean;
|
|
18
|
+
/** Starts the wait, or restarts it. `seconds` is used only if it is a positive finite number. */
|
|
19
|
+
start: (seconds?: number) => void;
|
|
20
|
+
/** Ends the wait and forgets it. */
|
|
21
|
+
clear: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A wait that counts down to an end time, such as "resend the code in 0:27".
|
|
25
|
+
*
|
|
26
|
+
* The end time is the truth, so a tab that slept shows the right time at once.
|
|
27
|
+
* Phases: idle, or counting until `endsAt`. It goes back to idle by itself when
|
|
28
|
+
* the time passes, or on `clear`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useCooldown(options: CooldownOptions): Cooldown;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
|
|
2
|
+
import { defineStored, numberBetween, useStored } from "../stored";
|
|
3
|
+
import { isUsableWait, msToNextSecond, remainingSeconds } from "./cooldown-time";
|
|
4
|
+
/* The wait's end, in epoch ms. 0 is no wait, which is also what the server renders. */
|
|
5
|
+
const endings = defineStored({
|
|
6
|
+
key: "kumiko.cooldown",
|
|
7
|
+
fallback: 0,
|
|
8
|
+
validate: numberBetween(0, Number.MAX_SAFE_INTEGER),
|
|
9
|
+
invalid: "remove"
|
|
10
|
+
});
|
|
11
|
+
/* A hook with no key still reads one stored value; this scope is never written. */
|
|
12
|
+
const unusedScope = "-unused-";
|
|
13
|
+
/**
|
|
14
|
+
* A wait that counts down to an end time, such as "resend the code in 0:27".
|
|
15
|
+
*
|
|
16
|
+
* The end time is the truth, so a tab that slept shows the right time at once.
|
|
17
|
+
* Phases: idle, or counting until `endsAt`. It goes back to idle by itself when
|
|
18
|
+
* the time passes, or on `clear`.
|
|
19
|
+
*/
|
|
20
|
+
export function useCooldown(options) {
|
|
21
|
+
const { key, seconds } = options;
|
|
22
|
+
const [kept, keep, , forget] = useStored(endings, key ?? unusedScope);
|
|
23
|
+
const [loose, setLoose] = useState(0);
|
|
24
|
+
const [beat, tick] = useReducer((count) => count + 1, 0);
|
|
25
|
+
const clockRef = useRef(options.now ?? Date.now);
|
|
26
|
+
clockRef.current = options.now ?? Date.now;
|
|
27
|
+
const endsAt = key === undefined ? loose : kept;
|
|
28
|
+
const now = clockRef.current();
|
|
29
|
+
const remaining = remainingSeconds(endsAt, now);
|
|
30
|
+
const set = useCallback((value) => {
|
|
31
|
+
if (key === undefined) {
|
|
32
|
+
setLoose(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
keep(value);
|
|
36
|
+
}
|
|
37
|
+
}, [key, keep]);
|
|
38
|
+
const start = useCallback((length) => {
|
|
39
|
+
set(clockRef.current() + (isUsableWait(length) ? length : seconds) * 1000);
|
|
40
|
+
}, [set, seconds]);
|
|
41
|
+
const clear = useCallback(() => {
|
|
42
|
+
if (key === undefined) {
|
|
43
|
+
setLoose(0);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
forget();
|
|
47
|
+
}
|
|
48
|
+
}, [key, forget]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (endsAt === 0) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const wait = msToNextSecond(endsAt, clockRef.current());
|
|
54
|
+
if (wait === 0) {
|
|
55
|
+
/* An end that has passed, saved or not, is removed. */
|
|
56
|
+
clear();
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const timer = setTimeout(tick, wait);
|
|
60
|
+
return () => clearTimeout(timer);
|
|
61
|
+
}, [endsAt, beat, clear]);
|
|
62
|
+
return { remaining, active: remaining > 0, start, clear };
|
|
63
|
+
}
|
|
@@ -19,5 +19,10 @@ export interface DialogContentApi<Result = unknown> {
|
|
|
19
19
|
export declare const DialogContentContext: import("react").Context<DialogContentApi<unknown> | null>;
|
|
20
20
|
/** Reads the dialog the content is shown in. It throws outside a dialog `openDialog()` opened. */
|
|
21
21
|
export declare function useDialogContent<Result = unknown>(): DialogContentApi<Result>;
|
|
22
|
+
/**
|
|
23
|
+
* Like `useDialogContent`, but null outside a dialog `openDialog()` opened instead of throwing. For parts, like a
|
|
24
|
+
* form, that work in a dialog or on a page. Kept out of the package entry on purpose.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useOptionalDialogContent(): DialogContentApi | null;
|
|
22
27
|
/** The row of buttons at the end of a form in an opened dialog. */
|
|
23
28
|
export declare function DialogActions(props: React.ComponentProps<"div">): React.JSX.Element;
|