@unisim/sdk 0.229.0 → 0.230.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/README.md +122 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/phone/SwipeRow.d.ts +62 -0
- package/dist/phone/SwipeRow.d.ts.map +1 -0
- package/dist/phone/SwipeRow.js +192 -0
- package/dist/phone/SwipeRow.js.map +1 -0
- package/dist/phone/TabReorder.d.ts +125 -0
- package/dist/phone/TabReorder.d.ts.map +1 -0
- package/dist/phone/TabReorder.js +245 -0
- package/dist/phone/TabReorder.js.map +1 -0
- package/dist/phone/hold.d.ts +87 -0
- package/dist/phone/hold.d.ts.map +1 -0
- package/dist/phone/hold.js +250 -0
- package/dist/phone/hold.js.map +1 -0
- package/dist/phone/index.d.ts +12 -0
- package/dist/phone/index.d.ts.map +1 -1
- package/dist/phone/index.js +12 -0
- package/dist/phone/index.js.map +1 -1
- package/dist/phone/listCopy.d.ts +28 -0
- package/dist/phone/listCopy.d.ts.map +1 -0
- package/dist/phone/listCopy.js +115 -0
- package/dist/phone/listCopy.js.map +1 -0
- package/dist/phone/listStyles.d.ts +4 -0
- package/dist/phone/listStyles.d.ts.map +1 -0
- package/dist/phone/listStyles.js +105 -0
- package/dist/phone/listStyles.js.map +1 -0
- package/dist/phone/swipeGeometry.d.ts +62 -0
- package/dist/phone/swipeGeometry.d.ts.map +1 -0
- package/dist/phone/swipeGeometry.js +96 -0
- package/dist/phone/swipeGeometry.js.map +1 -0
- package/dist/phone/tabOrder.d.ts +19 -0
- package/dist/phone/tabOrder.d.ts.map +1 -0
- package/dist/phone/tabOrder.js +46 -0
- package/dist/phone/tabOrder.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type ReactNode, type RefObject, type TouchEvent as ReactTouchEvent } from 'react';
|
|
2
|
+
/** How long a tab is held before it lifts, ms. */
|
|
3
|
+
export declare const TAB_HOLD_MS = 500;
|
|
4
|
+
export interface TabReorderOptions<T extends string> {
|
|
5
|
+
/**
|
|
6
|
+
* The tabs on the bar that can move, in order — not Tune this app, which
|
|
7
|
+
* stays last and is never given `tabProps`.
|
|
8
|
+
*/
|
|
9
|
+
tabs: readonly T[];
|
|
10
|
+
/**
|
|
11
|
+
* Let go somewhere new: the moved tabs, in their new order. Write it back
|
|
12
|
+
* with `withShownOrder(fullOrder, order)` if the bar hides some tabs.
|
|
13
|
+
*/
|
|
14
|
+
onReorder: (order: T[]) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Dropped on the bin: switch this tab off (and offer Undo). Without it
|
|
17
|
+
* there is no bin.
|
|
18
|
+
*/
|
|
19
|
+
onBin?: (tab: T) => void;
|
|
20
|
+
/** Which tabs may be binned. Default: every tab, while `onBin` is given. Never the last one shown. */
|
|
21
|
+
canBin?: (tab: T) => boolean;
|
|
22
|
+
/** Hold time, ms. Default 500. */
|
|
23
|
+
holdMs?: number;
|
|
24
|
+
/** Off (e.g. on the website, which drags with the mouse). Default true. */
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface TabReorder<T extends string> {
|
|
28
|
+
/** The tabs in the order to draw them: the live order while one is lifted. */
|
|
29
|
+
order: T[];
|
|
30
|
+
/** The tab being dragged, or null. */
|
|
31
|
+
dragging: T | null;
|
|
32
|
+
/** The finger is over the bin. */
|
|
33
|
+
overBin: boolean;
|
|
34
|
+
/** Show the bin: a tab that may be binned is lifted. */
|
|
35
|
+
showBin: boolean;
|
|
36
|
+
/** On the bar (`<nav ref={barRef}>`): the lifting finger's click is swallowed only there. */
|
|
37
|
+
barRef: RefObject<HTMLElement>;
|
|
38
|
+
/** On the bin (<TabBin> takes it as `binRef`). */
|
|
39
|
+
binRef: RefObject<HTMLDivElement>;
|
|
40
|
+
/**
|
|
41
|
+
* Spread on each movable tab's button: its touch start, no system menu on
|
|
42
|
+
* a hold, `data-reorder-tab`, and `data-reorder-lifted` while it is dragged
|
|
43
|
+
* (the SDK draws it raised; the app's own CSS may restyle it).
|
|
44
|
+
*/
|
|
45
|
+
tabProps: (tab: T) => {
|
|
46
|
+
'data-reorder-tab': T;
|
|
47
|
+
'data-reorder-lifted'?: '';
|
|
48
|
+
onTouchStart: (e: ReactTouchEvent) => void;
|
|
49
|
+
onContextMenu: (e: ReactMouseEvent) => void;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Hold a tab and drag it along the bar. While one is lifted, `order` is where
|
|
54
|
+
* it would land; letting go calls `onReorder` (if it moved) or `onBin` (over
|
|
55
|
+
* the bin). The click the lifting finger makes on the bar is swallowed, so a
|
|
56
|
+
* hold is never a tap (nor half of a double tap); a quick tap elsewhere — an
|
|
57
|
+
* Undo — still counts.
|
|
58
|
+
*
|
|
59
|
+
* const r = useTabReorder({ tabs: shown, onReorder: (o) => save(withShownOrder(all, o)), onBin: hide })
|
|
60
|
+
* <nav ref={r.barRef}>{[...r.order, 'tune'].map((t) => <button {...(t === 'tune' ? {} : r.tabProps(t))} … />)}</nav>
|
|
61
|
+
* {r.showBin && <TabBin binRef={r.binRef} over={r.overBin} />}
|
|
62
|
+
*/
|
|
63
|
+
export declare function useTabReorder<T extends string>({ tabs, onReorder, onBin, canBin, holdMs, enabled, }: TabReorderOptions<T>): TabReorder<T>;
|
|
64
|
+
export interface TabBinProps {
|
|
65
|
+
/** From {@link useTabReorder}. */
|
|
66
|
+
binRef: RefObject<HTMLDivElement>;
|
|
67
|
+
/** The finger is over it: red, "Let go to hide". */
|
|
68
|
+
over: boolean;
|
|
69
|
+
/** The words, if not the SDK's ("Drop here to hide" / "Let go to hide"). */
|
|
70
|
+
hint?: string;
|
|
71
|
+
drop?: string;
|
|
72
|
+
icon?: ReactNode;
|
|
73
|
+
language?: string;
|
|
74
|
+
/** Its place, if not just above the tab bar. */
|
|
75
|
+
className?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The bin a held tab can be dropped on, to hide it. Show it while
|
|
79
|
+
* `showBin`. Fixed above the foot of the screen; `className` moves it.
|
|
80
|
+
*/
|
|
81
|
+
export declare function TabBin({ binRef, over, hint, drop, icon, language, className }: TabBinProps): import("react/jsx-runtime").JSX.Element;
|
|
82
|
+
export interface TabOrderListState<T extends string> {
|
|
83
|
+
/** The tab whose grip is held, or null. */
|
|
84
|
+
held: T | null;
|
|
85
|
+
/** On the list (`<ol ref={listRef}>`); its children are the rows, in order. */
|
|
86
|
+
listRef: RefObject<HTMLOListElement>;
|
|
87
|
+
/** Spread on a row's grip: drag it (mouse or finger) up and down the list. */
|
|
88
|
+
gripProps: (tab: T) => {
|
|
89
|
+
onPointerDown: (e: ReactPointerEvent<HTMLElement>) => void;
|
|
90
|
+
onPointerMove: (e: ReactPointerEvent<HTMLElement>) => void;
|
|
91
|
+
onPointerUp: () => void;
|
|
92
|
+
onPointerCancel: () => void;
|
|
93
|
+
};
|
|
94
|
+
/** Move one tab to an index (Move up: `move(tab, i - 1)`). */
|
|
95
|
+
move: (tab: T, to: number) => void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Tune this app ▸ Tab order, without the drawing: a grip per row to drag (the
|
|
99
|
+
* row under the pointer takes the tab's place) and `move` for the Move up /
|
|
100
|
+
* Move down buttons. `order` is the whole order, hidden tabs included, so a
|
|
101
|
+
* tab switched back on returns to its place.
|
|
102
|
+
*/
|
|
103
|
+
export declare function useTabOrderList<T extends string>(order: readonly T[], onChange: (order: T[]) => void): TabOrderListState<T>;
|
|
104
|
+
export interface TabOrderListProps<T extends string> {
|
|
105
|
+
/** The whole order, hidden tabs included. */
|
|
106
|
+
order: readonly T[];
|
|
107
|
+
onChange: (order: T[]) => void;
|
|
108
|
+
/** A tab's name, in the app's language. */
|
|
109
|
+
label: (tab: T) => string;
|
|
110
|
+
/** Tabs switched off just now: listed, marked "hidden". */
|
|
111
|
+
hidden?: (tab: T) => boolean;
|
|
112
|
+
/** The heading and the line under it, if not the SDK's. `note={null}` drops the line. */
|
|
113
|
+
title?: string;
|
|
114
|
+
note?: string | null;
|
|
115
|
+
language?: string;
|
|
116
|
+
className?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Tune this app ▸ Tab order: the tab bar's order as a list, each row with a
|
|
120
|
+
* grip to drag and Move up / Move down buttons — the accessible way to do
|
|
121
|
+
* what a hold and a drag do on the bar. Reset to defaults is the app's (it
|
|
122
|
+
* puts its stored order back).
|
|
123
|
+
*/
|
|
124
|
+
export declare function TabOrderList<T extends string>({ order, onChange, label, hidden, title, note, language, className }: TabOrderListProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
125
|
+
//# sourceMappingURL=TabReorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TabReorder.d.ts","sourceRoot":"","sources":["../../src/phone/TabReorder.tsx"],"names":[],"mappings":"AAqBA,OAAO,EAKL,KAAK,UAAU,IAAI,eAAe,EAClC,KAAK,YAAY,IAAI,iBAAiB,EACtC,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,IAAI,eAAe,EACnC,MAAM,OAAO,CAAA;AAOd,kDAAkD;AAClD,eAAO,MAAM,WAAW,MAAM,CAAA;AAW9B,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM;IACjD;;;OAGG;IACH,IAAI,EAAE,SAAS,CAAC,EAAE,CAAA;IAClB;;;OAGG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,CAAA;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAA;IACxB,sGAAsG;IACtG,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAA;IAC5B,kCAAkC;IAClC,M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AAC,KAAK,MAAM,CAAA;IACzB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAA;IAC5B,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAkBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,2CA8CxI"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Tabs reorder: hold and drag (BRANDING.md ▸ "Tabs reorder: hold and drag",
|
|
4
|
+
// owner rules 2026-10-25 and 2026-10-26). Hold a tab ~0.5 s (a light haptic)
|
|
5
|
+
// and drag it along the bar; let go to drop it. A tab that Tune can switch off
|
|
6
|
+
// can be dropped on a bin that rises above the bar instead, which switches it
|
|
7
|
+
// off (with Undo). Tune this app stays last, and its Tab order list is the
|
|
8
|
+
// same order for the website, the keyboard and anybody who cannot drag.
|
|
9
|
+
//
|
|
10
|
+
// Moved here in 0.230.0 from Universal BlackBook (`src/native/NativeApp.tsx`,
|
|
11
|
+
// the bar; `TabOrderPreference.tsx`, the list), the first and fullest of three
|
|
12
|
+
// copies — Universal Jukebox and Workplace Assess (`native/TabBar.jsx`) built
|
|
13
|
+
// the same hold-and-drag without the bin.
|
|
14
|
+
//
|
|
15
|
+
// - useTabReorder() the bar's gesture: the live order while dragging,
|
|
16
|
+
// which tab is lifted, whether the finger is over the
|
|
17
|
+
// bin. The app keeps its own bar and its own tap.
|
|
18
|
+
// - <TabBin> the bin, in the SDK's words (or the app's).
|
|
19
|
+
// - useTabOrderList() Tune ▸ Tab order, headless: grips and Move up / down.
|
|
20
|
+
// - <TabOrderList> the same, drawn.
|
|
21
|
+
import { useEffect, useInsertionEffect, useRef, useState, } from 'react';
|
|
22
|
+
import { useOptionalLanguage } from '../provider.js';
|
|
23
|
+
import { phoneListCopy } from './listCopy.js';
|
|
24
|
+
import { injectPhoneListStyles } from './listStyles.js';
|
|
25
|
+
import { cx } from './styles.js';
|
|
26
|
+
import { moveTab } from './tabOrder.js';
|
|
27
|
+
/** How long a tab is held before it lifts, ms. */
|
|
28
|
+
export const TAB_HOLD_MS = 500;
|
|
29
|
+
/** Movement before that which makes it a scroll or a tap instead, px. */
|
|
30
|
+
const TAB_HOLD_SLOP_PX = 10;
|
|
31
|
+
/** The bin counts a finger this close as over it, px. */
|
|
32
|
+
const BIN_PAD_PX = 18;
|
|
33
|
+
function useLang(language) {
|
|
34
|
+
const fromProvider = useOptionalLanguage();
|
|
35
|
+
return language ?? fromProvider ?? (typeof document !== 'undefined' ? document.documentElement.lang || null : null);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hold a tab and drag it along the bar. While one is lifted, `order` is where
|
|
39
|
+
* it would land; letting go calls `onReorder` (if it moved) or `onBin` (over
|
|
40
|
+
* the bin). The click the lifting finger makes on the bar is swallowed, so a
|
|
41
|
+
* hold is never a tap (nor half of a double tap); a quick tap elsewhere — an
|
|
42
|
+
* Undo — still counts.
|
|
43
|
+
*
|
|
44
|
+
* const r = useTabReorder({ tabs: shown, onReorder: (o) => save(withShownOrder(all, o)), onBin: hide })
|
|
45
|
+
* <nav ref={r.barRef}>{[...r.order, 'tune'].map((t) => <button {...(t === 'tune' ? {} : r.tabProps(t))} … />)}</nav>
|
|
46
|
+
* {r.showBin && <TabBin binRef={r.binRef} over={r.overBin} />}
|
|
47
|
+
*/
|
|
48
|
+
export function useTabReorder({ tabs, onReorder, onBin, canBin, holdMs = TAB_HOLD_MS, enabled = true, }) {
|
|
49
|
+
const [drag, setDrag] = useState(null);
|
|
50
|
+
const barRef = useRef(null);
|
|
51
|
+
const binRef = useRef(null);
|
|
52
|
+
const hold = useRef(null);
|
|
53
|
+
const live = useRef({ drag, tabs, onReorder, onBin, canBin });
|
|
54
|
+
live.current = { drag, tabs, onReorder, onBin, canBin };
|
|
55
|
+
const binnable = (tab) => Boolean(live.current.onBin) && live.current.tabs.length > 1 && (live.current.canBin?.(tab) ?? true);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const move = (e) => {
|
|
58
|
+
const h = hold.current;
|
|
59
|
+
if (!h)
|
|
60
|
+
return;
|
|
61
|
+
const t0 = e.touches[0];
|
|
62
|
+
if (!h.active) {
|
|
63
|
+
if (!t0 || Math.hypot(t0.clientX - h.x0, t0.clientY - h.y0) > TAB_HOLD_SLOP_PX) {
|
|
64
|
+
clearTimeout(h.timer);
|
|
65
|
+
hold.current = null;
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (e.cancelable)
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
const d = live.current.drag;
|
|
72
|
+
if (!d || !t0)
|
|
73
|
+
return;
|
|
74
|
+
// Over the bin (with a finger's width to spare): the order holds still.
|
|
75
|
+
const b = binnable(d.tab) ? binRef.current?.getBoundingClientRect() : undefined;
|
|
76
|
+
const overBin = Boolean(b &&
|
|
77
|
+
t0.clientX >= b.left - BIN_PAD_PX &&
|
|
78
|
+
t0.clientX <= b.right + BIN_PAD_PX &&
|
|
79
|
+
t0.clientY >= b.top - BIN_PAD_PX &&
|
|
80
|
+
t0.clientY <= b.bottom + BIN_PAD_PX);
|
|
81
|
+
if (overBin !== d.bin) {
|
|
82
|
+
navigator.vibrate?.(8);
|
|
83
|
+
const next = { ...d, bin: overBin };
|
|
84
|
+
live.current.drag = next;
|
|
85
|
+
setDrag(next);
|
|
86
|
+
}
|
|
87
|
+
if (overBin)
|
|
88
|
+
return;
|
|
89
|
+
// Which slot the finger is over, among the tabs that can move.
|
|
90
|
+
const slots = [...(barRef.current?.querySelectorAll('[data-reorder-tab]') ?? [])];
|
|
91
|
+
const at = slots.findIndex((el) => {
|
|
92
|
+
const r = el.getBoundingClientRect();
|
|
93
|
+
return t0.clientX >= r.left && t0.clientX <= r.right;
|
|
94
|
+
});
|
|
95
|
+
if (at < 0)
|
|
96
|
+
return;
|
|
97
|
+
const order = moveTab(d.order, d.tab, at);
|
|
98
|
+
if (order.join('\u0000') !== d.order.join('\u0000')) {
|
|
99
|
+
const next = { tab: d.tab, order, bin: false };
|
|
100
|
+
live.current.drag = next;
|
|
101
|
+
setDrag(next);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const end = () => {
|
|
105
|
+
const h = hold.current;
|
|
106
|
+
hold.current = null;
|
|
107
|
+
if (!h)
|
|
108
|
+
return;
|
|
109
|
+
clearTimeout(h.timer);
|
|
110
|
+
if (!h.active)
|
|
111
|
+
return;
|
|
112
|
+
// The lift is not a tap: its click must not switch tabs or count toward
|
|
113
|
+
// a double tap. Only on the bar: a quick tap on the bin's Undo counts.
|
|
114
|
+
const swallow = (ev) => {
|
|
115
|
+
if (!barRef.current?.contains(ev.target))
|
|
116
|
+
return;
|
|
117
|
+
ev.preventDefault();
|
|
118
|
+
ev.stopPropagation();
|
|
119
|
+
};
|
|
120
|
+
document.addEventListener('click', swallow, { capture: true, once: true });
|
|
121
|
+
setTimeout(() => document.removeEventListener('click', swallow, { capture: true }), 600);
|
|
122
|
+
const d = live.current.drag;
|
|
123
|
+
live.current.drag = null;
|
|
124
|
+
setDrag(null);
|
|
125
|
+
if (!d)
|
|
126
|
+
return;
|
|
127
|
+
if (d.bin && binnable(d.tab)) {
|
|
128
|
+
live.current.onBin?.(d.tab);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (d.order.join('\u0000') !== live.current.tabs.join('\u0000'))
|
|
132
|
+
live.current.onReorder(d.order);
|
|
133
|
+
};
|
|
134
|
+
document.addEventListener('touchmove', move, { passive: false, capture: true });
|
|
135
|
+
document.addEventListener('touchend', end, true);
|
|
136
|
+
document.addEventListener('touchcancel', end, true);
|
|
137
|
+
return () => {
|
|
138
|
+
if (hold.current)
|
|
139
|
+
clearTimeout(hold.current.timer);
|
|
140
|
+
hold.current = null;
|
|
141
|
+
document.removeEventListener('touchmove', move, { capture: true });
|
|
142
|
+
document.removeEventListener('touchend', end, true);
|
|
143
|
+
document.removeEventListener('touchcancel', end, true);
|
|
144
|
+
};
|
|
145
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
|
+
}, []);
|
|
147
|
+
const tabProps = (tab) => ({
|
|
148
|
+
'data-reorder-tab': tab,
|
|
149
|
+
...(drag?.tab === tab ? { 'data-reorder-lifted': '' } : {}),
|
|
150
|
+
onTouchStart: (e) => {
|
|
151
|
+
if (!enabled || e.touches.length !== 1 || live.current.tabs.length < 2)
|
|
152
|
+
return;
|
|
153
|
+
const t0 = e.touches[0];
|
|
154
|
+
if (hold.current)
|
|
155
|
+
clearTimeout(hold.current.timer);
|
|
156
|
+
const h = {
|
|
157
|
+
x0: t0.clientX,
|
|
158
|
+
y0: t0.clientY,
|
|
159
|
+
active: false,
|
|
160
|
+
timer: setTimeout(() => {
|
|
161
|
+
h.active = true;
|
|
162
|
+
navigator.vibrate?.(12);
|
|
163
|
+
const next = { tab, order: [...live.current.tabs], bin: false };
|
|
164
|
+
live.current.drag = next;
|
|
165
|
+
setDrag(next);
|
|
166
|
+
}, holdMs),
|
|
167
|
+
};
|
|
168
|
+
hold.current = h;
|
|
169
|
+
},
|
|
170
|
+
// A held finger brings up no system menu.
|
|
171
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
order: drag?.order ?? [...tabs],
|
|
175
|
+
dragging: drag?.tab ?? null,
|
|
176
|
+
overBin: Boolean(drag?.bin),
|
|
177
|
+
showBin: Boolean(drag && binnable(drag.tab)),
|
|
178
|
+
barRef,
|
|
179
|
+
binRef,
|
|
180
|
+
tabProps,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const BinIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: _jsx("path", { d: "M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3" }) }));
|
|
184
|
+
/**
|
|
185
|
+
* The bin a held tab can be dropped on, to hide it. Show it while
|
|
186
|
+
* `showBin`. Fixed above the foot of the screen; `className` moves it.
|
|
187
|
+
*/
|
|
188
|
+
export function TabBin({ binRef, over, hint, drop, icon, language, className }) {
|
|
189
|
+
useInsertionEffect(() => injectPhoneListStyles(), []);
|
|
190
|
+
const copy = phoneListCopy(useLang(language));
|
|
191
|
+
return (_jsxs("div", { ref: binRef, className: cx('unisim-tab-bin', className), "data-over": over ? '' : undefined, "aria-hidden": true, children: [icon ?? _jsx(BinIcon, {}), _jsx("span", { children: over ? (drop ?? copy.binDrop) : (hint ?? copy.binHint) })] }));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Tune this app ▸ Tab order, without the drawing: a grip per row to drag (the
|
|
195
|
+
* row under the pointer takes the tab's place) and `move` for the Move up /
|
|
196
|
+
* Move down buttons. `order` is the whole order, hidden tabs included, so a
|
|
197
|
+
* tab switched back on returns to its place.
|
|
198
|
+
*/
|
|
199
|
+
export function useTabOrderList(order, onChange) {
|
|
200
|
+
const listRef = useRef(null);
|
|
201
|
+
const [held, setHeld] = useState(null);
|
|
202
|
+
const move = (tab, to) => onChange(moveTab(order, tab, to));
|
|
203
|
+
return {
|
|
204
|
+
held,
|
|
205
|
+
listRef,
|
|
206
|
+
move,
|
|
207
|
+
gripProps: (tab) => ({
|
|
208
|
+
onPointerDown: (e) => {
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
211
|
+
setHeld(tab);
|
|
212
|
+
},
|
|
213
|
+
onPointerMove: (e) => {
|
|
214
|
+
if (held !== tab)
|
|
215
|
+
return;
|
|
216
|
+
const rows = [...(listRef.current?.children ?? [])];
|
|
217
|
+
const at = rows.findIndex((r) => {
|
|
218
|
+
const b = r.getBoundingClientRect();
|
|
219
|
+
return e.clientY >= b.top && e.clientY <= b.bottom;
|
|
220
|
+
});
|
|
221
|
+
if (at >= 0 && order[at] !== tab)
|
|
222
|
+
move(tab, at);
|
|
223
|
+
},
|
|
224
|
+
onPointerUp: () => setHeld(null),
|
|
225
|
+
onPointerCancel: () => setHeld(null),
|
|
226
|
+
}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const Arrow = ({ down }) => (_jsx("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.75", "aria-hidden": true, style: down ? { transform: 'rotate(180deg)' } : undefined, children: _jsx("path", { d: "M8 13V3M4 7l4-4 4 4", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
230
|
+
const Grip = () => (_jsxs("svg", { viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": true, children: [_jsx("circle", { cx: "5.5", cy: "4", r: "1.2" }), _jsx("circle", { cx: "10.5", cy: "4", r: "1.2" }), _jsx("circle", { cx: "5.5", cy: "8", r: "1.2" }), _jsx("circle", { cx: "10.5", cy: "8", r: "1.2" }), _jsx("circle", { cx: "5.5", cy: "12", r: "1.2" }), _jsx("circle", { cx: "10.5", cy: "12", r: "1.2" })] }));
|
|
231
|
+
/**
|
|
232
|
+
* Tune this app ▸ Tab order: the tab bar's order as a list, each row with a
|
|
233
|
+
* grip to drag and Move up / Move down buttons — the accessible way to do
|
|
234
|
+
* what a hold and a drag do on the bar. Reset to defaults is the app's (it
|
|
235
|
+
* puts its stored order back).
|
|
236
|
+
*/
|
|
237
|
+
export function TabOrderList({ order, onChange, label, hidden, title, note, language, className }) {
|
|
238
|
+
useInsertionEffect(() => injectPhoneListStyles(), []);
|
|
239
|
+
const copy = phoneListCopy(useLang(language));
|
|
240
|
+
const list = useTabOrderList(order, onChange);
|
|
241
|
+
const heading = title ?? copy.tabOrder;
|
|
242
|
+
const line = note === undefined ? copy.tabOrderNote : note;
|
|
243
|
+
return (_jsxs("fieldset", { className: cx('unisim-tab-order', className), children: [_jsx("legend", { style: { position: 'absolute', width: 1, height: 1, overflow: 'hidden', clip: 'rect(0 0 0 0)' }, children: heading }), _jsx("p", { "aria-hidden": true, className: "unisim-tab-order-title", children: heading }), line && _jsx("p", { className: "unisim-tab-order-note", children: line }), _jsx("ol", { ref: list.listRef, children: order.map((tab, i) => (_jsxs("li", { "data-tab": tab, "data-held": list.held === tab ? '' : undefined, children: [_jsx("span", { ...list.gripProps(tab), "aria-hidden": true, className: "unisim-tab-order-grip", children: _jsx(Grip, {}) }), _jsxs("span", { className: "unisim-tab-order-name", children: [label(tab), hidden?.(tab) && _jsxs("span", { className: "unisim-tab-order-hidden", children: ["(", copy.hidden, ")"] })] }), _jsx("button", { type: "button", className: "unisim-tab-order-move", "aria-label": copy.moveEarlier.replace('{name}', label(tab)), disabled: i === 0, onClick: () => list.move(tab, i - 1), children: _jsx(Arrow, {}) }), _jsx("button", { type: "button", className: "unisim-tab-order-move", "aria-label": copy.moveLater.replace('{name}', label(tab)), disabled: i === order.length - 1, onClick: () => list.move(tab, i + 1), children: _jsx(Arrow, { down: true }) })] }, tab))) })] }));
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=TabReorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TabReorder.js","sourceRoot":"","sources":["../../src/phone/TabReorder.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,2EAA2E;AAC3E,wEAAwE;AACxE,EAAE;AACF,8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eAAa,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,aACxE,kBAAU,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,uBAAc,SAAS,EAAC,uBAAuB,YAC1E,KAAC,IAAI,KAAG,GACH,EACP,gBAAM,SAAS,EAAC,uBAAuB,aACpC,KAAK,CAAC,GAAG,CAAC,EACV,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,gBAAM,SAAS,EAAC,yBAAyB,kBAAG,IAAI,CAAC,MAAM,SAAS,IAC7E,EACP,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,uBAAuB,gBACrB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAC1D,QAAQ,EAAE,CAAC,KAAK,CAAC,EACjB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,YAEpC,KAAC,KAAK,KAAG,GACF,EACT,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,uBAAuB,gBACrB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EACxD,QAAQ,EAAE,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,EAChC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,YAEpC,KAAC,KAAK,IAAC,IAAI,SAAG,GACP,KAzBF,GAAG,CA0BP,CACN,CAAC,GACC,IACI,CACZ,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type TouchEvent as ReactTouchEvent } from 'react';
|
|
2
|
+
/** How long a finger stays still to count as a hold, ms. */
|
|
3
|
+
export declare const HOLD_MS = 450;
|
|
4
|
+
/** How far it may wander and still be holding, px. */
|
|
5
|
+
export declare const HOLD_SLOP_PX = 8;
|
|
6
|
+
/**
|
|
7
|
+
* Eat the next click, wherever it lands, if it comes before the finger lifts
|
|
8
|
+
* or within 0.4 s of it — the click that ends a hold, so it neither opens the
|
|
9
|
+
* row nor presses what has just slid in under the finger. Call it the moment
|
|
10
|
+
* the hold fires, while the finger is still down. `swallowed` runs if a click
|
|
11
|
+
* was eaten. From Universal Jukebox.
|
|
12
|
+
*/
|
|
13
|
+
export declare function swallowReleaseClick(swallowed?: () => void): void;
|
|
14
|
+
export interface HoldOptions {
|
|
15
|
+
/** How long the finger stays still, ms. Default 450. */
|
|
16
|
+
ms?: number;
|
|
17
|
+
/** A haptic as it fires (`navigator.vibrate`, Android). Default true. */
|
|
18
|
+
vibrate?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The hold itself. Spread `holdStart(id)` as a row's `onTouchStart`: a still
|
|
22
|
+
* finger for 0.45 s calls `onHold(id)`. Movement first (the row's swipe, the
|
|
23
|
+
* list's scroll), the finger lifting, or a second finger cancels it. The click
|
|
24
|
+
* the lifting finger makes is swallowed ({@link swallowReleaseClick}).
|
|
25
|
+
*
|
|
26
|
+
* const holdStart = useHold((id) => startSelecting(id))
|
|
27
|
+
* <li onTouchStart={selecting ? undefined : holdStart(row.id)}>…
|
|
28
|
+
*
|
|
29
|
+
* Touch only: the website ticks with its tick boxes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useHold(onHold: (id: string) => void, options?: HoldOptions): (id: string) => (e: ReactTouchEvent) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Selection mode is left the phone's ways as well as by its Done button:
|
|
34
|
+
* Android's back gesture (a layer on the SDK's stack while `selecting`, so
|
|
35
|
+
* Back takes selection mode away rather than the page) and a swipe in from
|
|
36
|
+
* the left edge. `enabled: false` (the website) turns both off.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useLeaveSelection(selecting: boolean, leave: () => void, options?: {
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
}): void;
|
|
41
|
+
/** What {@link useHoldSelect} returns: selection mode for one list. */
|
|
42
|
+
export interface HoldSelect {
|
|
43
|
+
/** In selection mode (a hold started it, or a Select button). */
|
|
44
|
+
selecting: boolean;
|
|
45
|
+
isSelected: (id: string) => boolean;
|
|
46
|
+
/** The ticked ids still in the list, in the list's order. */
|
|
47
|
+
picked: string[];
|
|
48
|
+
/** Into selection mode, with this one ticked if given. */
|
|
49
|
+
start: (id?: string) => void;
|
|
50
|
+
/** Tick or untick one; `range` (Shift-click) ticks the run from the last one. */
|
|
51
|
+
toggle: (id: string, range?: boolean) => void;
|
|
52
|
+
/** Everything, or nothing if everything was ticked. */
|
|
53
|
+
all: () => void;
|
|
54
|
+
/** Out of selection mode. */
|
|
55
|
+
done: () => void;
|
|
56
|
+
/** Spread `holdStart(id)` as each row's `onTouchStart`. */
|
|
57
|
+
holdStart: (id: string) => (e: ReactTouchEvent) => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Selection mode for one list, started by a hold ({@link useHold}) and left
|
|
61
|
+
* by Done, Android's back or an edge swipe ({@link useLeaveSelection}).
|
|
62
|
+
* `ids` are the rows on screen, in order. Pair it with your own bar (the
|
|
63
|
+
* count, Select all, the list's bulk actions, Done) shown while `selecting`.
|
|
64
|
+
*
|
|
65
|
+
* const sel = useHoldSelect(rows.map((r) => r.id), { gestures: isPhoneApp })
|
|
66
|
+
*
|
|
67
|
+
* `gestures: false` keeps Back and the edge swipe out of it (a website).
|
|
68
|
+
*/
|
|
69
|
+
export declare function useHoldSelect(ids: readonly string[], options?: {
|
|
70
|
+
gestures?: boolean;
|
|
71
|
+
} & HoldOptions): HoldSelect;
|
|
72
|
+
/**
|
|
73
|
+
* Delete now, Undo for a while (six seconds by default): what was deleted and
|
|
74
|
+
* the way to put it back. The rule's "Delete offers Undo". Show your own
|
|
75
|
+
* toast while `item` is set; From Universal BlackBook.
|
|
76
|
+
*/
|
|
77
|
+
export declare function useUndo<T>(restore: (item: T) => void | Promise<void>, ms?: number): {
|
|
78
|
+
/** What can still be put back, or null. */
|
|
79
|
+
item: T | null;
|
|
80
|
+
/** Something was deleted: offer it back for `ms`. */
|
|
81
|
+
deleted: (x: T) => void;
|
|
82
|
+
/** Put it back. */
|
|
83
|
+
undo: () => Promise<void>;
|
|
84
|
+
/** Forget it without restoring (the toast was dismissed). */
|
|
85
|
+
dismiss: () => void;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=hold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hold.d.ts","sourceRoot":"","sources":["../../src/phone/hold.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA+B,KAAK,UAAU,IAAI,eAAe,EAAE,MAAM,OAAO,CAAA;AAIvF,4DAA4D;AAC5D,eAAO,MAAM,OAAO,MAAM,CAAA;AAC1B,sDAAsD;AACtD,eAAO,MAAM,YAAY,IAAI,CAAA;AAI7B;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAoBhE;AAED,MAAM,WAAW,WAAW;IAC1B,wDAAwD;IACxD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,EAC5B,OAAO,GAAE,WAAgB,GACxB,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CA2C9C;AAOD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,IAAI,CA2BlH;AAED,uEAAuE;AACvE,MAA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