reifyui 0.12.0 → 0.13.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/README.md +29 -0
- package/dist/chart.js +2 -0
- package/dist/chart.js.map +1 -1
- package/dist/chunk-EL2DHWOH.js +1710 -0
- package/dist/chunk-EL2DHWOH.js.map +1 -0
- package/dist/chunk-J633KV57.js +41 -0
- package/dist/chunk-J633KV57.js.map +1 -0
- package/dist/chunk-J7SECRIG.js +295 -0
- package/dist/chunk-J7SECRIG.js.map +1 -0
- package/dist/chunk-PIRPLH2Z.js +231 -0
- package/dist/chunk-PIRPLH2Z.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-UKG4Z6QK.js +130 -0
- package/dist/chunk-UKG4Z6QK.js.map +1 -0
- package/dist/chunk-ZYWE47EO.js +19 -0
- package/dist/chunk-ZYWE47EO.js.map +1 -0
- package/dist/collab.cjs +169 -0
- package/dist/collab.cjs.map +1 -0
- package/dist/collab.d.ts +30 -0
- package/dist/collab.js +18 -0
- package/dist/collab.js.map +1 -0
- package/dist/graph.cjs +2244 -0
- package/dist/graph.cjs.map +1 -0
- package/dist/graph.d.ts +41 -0
- package/dist/graph.js +1870 -0
- package/dist/graph.js.map +1 -0
- package/dist/harness.js +1 -0
- package/dist/harness.js.map +1 -1
- package/dist/index.cjs +1699 -817
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +680 -1769
- package/dist/index.js.map +1 -1
- package/dist/sheet-doc.cjs +235 -0
- package/dist/sheet-doc.cjs.map +1 -0
- package/dist/sheet-doc.d.ts +16 -0
- package/dist/sheet-doc.js +20 -0
- package/dist/sheet-doc.js.map +1 -0
- package/dist/sheet.cjs +2322 -0
- package/dist/sheet.cjs.map +1 -0
- package/dist/sheet.d.ts +23 -0
- package/dist/sheet.js +237 -0
- package/dist/sheet.js.map +1 -0
- package/dist/slides.js +2 -0
- package/dist/slides.js.map +1 -1
- package/package.json +34 -2
- package/src/auth/client.js +4 -2
- package/src/collab/colors.js +18 -0
- package/src/collab/index.d.ts +30 -0
- package/src/collab/index.js +8 -0
- package/src/collab/keepAlive.js +34 -0
- package/src/collab/useLiveDoc.js +76 -0
- package/src/components/CascadeMenu.jsx +9 -3
- package/src/components/Composer.jsx +37 -3
- package/src/components/resizable.jsx +82 -12
- package/src/graph/ConnectPane.jsx +634 -0
- package/src/graph/ConnectToolDetail.jsx +565 -0
- package/src/graph/LogsPane.jsx +328 -0
- package/src/graph/Skeleton.jsx +13 -0
- package/src/graph/draft.js +108 -0
- package/src/graph/format.js +37 -0
- package/src/graph/index.d.ts +41 -0
- package/src/graph/index.js +14 -0
- package/src/graph/useGraphCollab.js +299 -0
- package/src/graph/vgraph.js +215 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +4 -1
- package/src/mention/MentionInput.jsx +420 -0
- package/src/mention/mentionModel.js +177 -0
- package/src/sheet/RunStrip.jsx +57 -0
- package/src/sheet/SheetGrid.jsx +448 -423
- package/src/sheet/doc.d.ts +16 -0
- package/src/sheet/index.d.ts +23 -0
- package/src/sheet/index.js +10 -0
- package/src/sheet/sheetDoc.js +203 -0
- package/src/sheet/useSheetCollab.js +102 -0
- package/src/sheet/useSheetRun.js +80 -0
- package/styles/chat.css +2 -0
- package/styles/graph.css +395 -0
- package/styles/mention.css +79 -0
- package/styles/sheet.css +156 -112
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// reifyui/collab — public type surface (hand-authored; the source is plain-ESM React).
|
|
2
|
+
import type * as Y from 'yjs';
|
|
3
|
+
|
|
4
|
+
export interface LiveDocOptions {
|
|
5
|
+
/** The collaboration server (Hocuspocus) URL. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** The document name; one document per resource. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** A bearer ticket for the document, as the host's collaboration service issues it. */
|
|
10
|
+
token?: string;
|
|
11
|
+
/** Called once the document is synced; `doc` is the shared Y.Doc. */
|
|
12
|
+
onSynced?(doc: Y.Doc): void;
|
|
13
|
+
[k: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface LiveDoc {
|
|
16
|
+
doc: Y.Doc | null;
|
|
17
|
+
provider: unknown;
|
|
18
|
+
synced: boolean;
|
|
19
|
+
status: string;
|
|
20
|
+
awareness: unknown;
|
|
21
|
+
[k: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** One live-document core: provider lifecycle, sync state, awareness, for any live surface. */
|
|
24
|
+
export function useLiveDoc(options: LiveDocOptions | null): LiveDoc;
|
|
25
|
+
/** Keep awareness renewed from a worker clock so a hidden tab's presence never lapses. */
|
|
26
|
+
export function keepPresenceAlive(provider: unknown, periodMs?: number): () => void;
|
|
27
|
+
export const PEER_PALETTE: readonly string[];
|
|
28
|
+
/** The palette color for a peer id, stable across every host. */
|
|
29
|
+
export function peerColor(id: string | number): string;
|
|
30
|
+
export function withAlpha(color: string, alpha: number): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// reifyui/collab — one live-document core for any collaborative surface.
|
|
2
|
+
//
|
|
3
|
+
// A separate entry because it pulls in yjs and the Hocuspocus provider: importing a Button
|
|
4
|
+
// from the root never costs a CRDT. Presence colors and the worker-clock keep-alive ride along
|
|
5
|
+
// (they have no dependencies) so a host wires collaboration from one import.
|
|
6
|
+
export { useLiveDoc } from './useLiveDoc.js';
|
|
7
|
+
export { keepPresenceAlive } from './keepAlive.js';
|
|
8
|
+
export { PEER_PALETTE, peerColor, withAlpha } from './colors.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// keepPresenceAlive — renew this client's awareness on a clock the browser
|
|
2
|
+
// does not throttle.
|
|
3
|
+
//
|
|
4
|
+
// Yjs awareness renews a client's own state every 15s on a main-thread timer
|
|
5
|
+
// and every other client drops a state it has not heard from for 30s. A tab
|
|
6
|
+
// in the background gets its timers throttled to once a minute, so its
|
|
7
|
+
// presence expires for everyone else and reappears when the timer finally
|
|
8
|
+
// fires: a flag that flickers every minute on every other screen. Worker
|
|
9
|
+
// clocks are not throttled, so the renewal runs there and the main thread
|
|
10
|
+
// only relays it. One helper for every live document (sheets, canvases,
|
|
11
|
+
// docs).
|
|
12
|
+
const TICK_MS = 10_000;
|
|
13
|
+
|
|
14
|
+
export function keepPresenceAlive(awareness, intervalMs = TICK_MS) {
|
|
15
|
+
if (!awareness || typeof Worker === 'undefined' || typeof Blob === 'undefined') return () => {};
|
|
16
|
+
let url = '';
|
|
17
|
+
let worker = null;
|
|
18
|
+
try {
|
|
19
|
+
url = URL.createObjectURL(new Blob([`setInterval(() => postMessage(0), ${Math.max(1000, intervalMs)});`],
|
|
20
|
+
{ type: 'text/javascript' }));
|
|
21
|
+
worker = new Worker(url);
|
|
22
|
+
} catch {
|
|
23
|
+
if (url) URL.revokeObjectURL(url);
|
|
24
|
+
return () => {};
|
|
25
|
+
}
|
|
26
|
+
worker.onmessage = () => {
|
|
27
|
+
const state = awareness.getLocalState();
|
|
28
|
+
if (state !== null && state !== undefined) awareness.setLocalState(state); // same state, new clock
|
|
29
|
+
};
|
|
30
|
+
return () => {
|
|
31
|
+
worker.terminate();
|
|
32
|
+
URL.revokeObjectURL(url);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// useLiveDoc — the one provider lifecycle for every live document on the
|
|
2
|
+
// platform's realtime sidecar: a sheet, a graph canvas, a doc. It takes a
|
|
3
|
+
// host-authenticated ticket ({url, doc, token}), connects, re-tickets when the
|
|
4
|
+
// token ages out, retries quietly when realtime is unreachable, and exposes
|
|
5
|
+
// the document once synced, the awareness states of everyone in it, and one
|
|
6
|
+
// field for what THIS person publishes (re-applied on every reconnect).
|
|
7
|
+
// Surfaces build their own shape on top: what to read from the document and
|
|
8
|
+
// what presence means for them.
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
import { HocuspocusProvider } from '@hocuspocus/provider';
|
|
11
|
+
import { keepPresenceAlive } from './keepAlive.js';
|
|
12
|
+
|
|
13
|
+
export function useLiveDoc(resourceId, { fetchTicket, field = 'presence' } = {}) {
|
|
14
|
+
const [doc, setDoc] = useState(null); // the Y.Doc, once synced
|
|
15
|
+
const [provider, setProvider] = useState(null);
|
|
16
|
+
const [ready, setReady] = useState(false);
|
|
17
|
+
const [states, setStates] = useState([]); // [{clientId, ...awareness}]
|
|
18
|
+
const [selfClientId, setSelfClientId] = useState(null);
|
|
19
|
+
const providerRef = useRef(null);
|
|
20
|
+
const lastRef = useRef(null); // this person's last published value
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!resourceId || typeof fetchTicket !== 'function') return undefined;
|
|
24
|
+
let dead = false;
|
|
25
|
+
let current = null;
|
|
26
|
+
let retry = null;
|
|
27
|
+
let stopKeepAlive = () => {};
|
|
28
|
+
|
|
29
|
+
async function connect() {
|
|
30
|
+
let ticket = null;
|
|
31
|
+
try { ticket = await fetchTicket(resourceId); } catch { ticket = null; }
|
|
32
|
+
if (dead) return;
|
|
33
|
+
if (!ticket) { retry = window.setTimeout(connect, 60_000); return; } // realtime unreachable: try later
|
|
34
|
+
current = new HocuspocusProvider({
|
|
35
|
+
url: ticket.url, name: ticket.doc, parameters: { cg_token: ticket.token },
|
|
36
|
+
onAuthenticationFailed: () => {
|
|
37
|
+
// The token aged out (or access was revoked): tear down and re-ticket.
|
|
38
|
+
stopKeepAlive();
|
|
39
|
+
try { current.destroy(); } catch { /* down */ }
|
|
40
|
+
if (!dead) retry = window.setTimeout(connect, 5_000);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
stopKeepAlive = keepPresenceAlive(current.awareness);
|
|
44
|
+
providerRef.current = current;
|
|
45
|
+
setProvider(current);
|
|
46
|
+
if (lastRef.current) { try { current.setAwarenessField(field, lastRef.current); } catch { /* not yet */ } }
|
|
47
|
+
current.on('awarenessUpdate', ({ states: next }) => { if (!dead) setStates(next || []); });
|
|
48
|
+
current.on('synced', () => {
|
|
49
|
+
if (dead) return;
|
|
50
|
+
setSelfClientId(current.awareness ? current.awareness.clientID : null);
|
|
51
|
+
setDoc(current.document);
|
|
52
|
+
setReady(true);
|
|
53
|
+
});
|
|
54
|
+
current.on('status', ({ status }) => { if (!dead && status === 'disconnected') setReady(false); });
|
|
55
|
+
}
|
|
56
|
+
connect();
|
|
57
|
+
return () => {
|
|
58
|
+
dead = true; window.clearTimeout(retry);
|
|
59
|
+
stopKeepAlive();
|
|
60
|
+
if (current) { try { current.destroy(); } catch { /* closing */ } }
|
|
61
|
+
providerRef.current = null;
|
|
62
|
+
setProvider(null); setDoc(null); setReady(false); setStates([]); setSelfClientId(null);
|
|
63
|
+
};
|
|
64
|
+
// fetchTicket is a host constant; re-subscribing on its identity would reconnect every render.
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [resourceId]);
|
|
67
|
+
|
|
68
|
+
/** Publish what this person is doing; kept and re-applied across reconnects. */
|
|
69
|
+
const setAwareness = useCallback((value) => {
|
|
70
|
+
lastRef.current = value;
|
|
71
|
+
const p = providerRef.current;
|
|
72
|
+
if (p) { try { p.setAwarenessField(field, value); } catch { /* closing */ } }
|
|
73
|
+
}, [field]);
|
|
74
|
+
|
|
75
|
+
return { doc, provider, ready, states, selfClientId, setAwareness };
|
|
76
|
+
}
|
|
@@ -34,7 +34,10 @@ const itemsOf = (groups) => groups.flatMap((g) => g.items);
|
|
|
34
34
|
* groups [{ label, items: [{ id, label, icon, note }] }] — the first column, grouped;
|
|
35
35
|
* a note is a small trailing word, e.g. 'fixed' on the one item a locked
|
|
36
36
|
* chooser offers
|
|
37
|
-
* optionsOf(item) -> [{ id, label, disabled, note }] — the second column for one item
|
|
37
|
+
* optionsOf(item) -> [{ id, label, disabled, note, badge }] — the second column for one item;
|
|
38
|
+
* a badge is a node at the row's end, e.g. which key serves a model, and
|
|
39
|
+
* is what gives way (its own ellipsis) when the row is narrow
|
|
40
|
+
* optionsFooter a node under the options, e.g. what the options without a badge mean
|
|
38
41
|
* onPick(item, option)
|
|
39
42
|
* value { item, option } — the current pair: its item opens first and its option
|
|
40
43
|
* carries a check, so an editor of an existing choice shows where it stands
|
|
@@ -51,7 +54,7 @@ export function CascadeMenu(props) {
|
|
|
51
54
|
groups = [], optionsOf, onPick,
|
|
52
55
|
filter = 'auto', filterPlaceholder = 'Filter',
|
|
53
56
|
emptyText = 'Nothing matches.', noOptionsText = 'Nothing to choose here.',
|
|
54
|
-
optionsLabel = 'Options', backLabel = 'Back',
|
|
57
|
+
optionsLabel = 'Options', backLabel = 'Back', optionsFooter,
|
|
55
58
|
width = 520, stackBelow = 560, className, value,
|
|
56
59
|
} = props;
|
|
57
60
|
|
|
@@ -191,17 +194,20 @@ export function CascadeMenu(props) {
|
|
|
191
194
|
{options.map((o) => {
|
|
192
195
|
const on = !!value && active?.id === value.item && o.id === value.option;
|
|
193
196
|
return (
|
|
194
|
-
<button key={o.id} type="button"
|
|
197
|
+
<button key={o.id} type="button"
|
|
198
|
+
className={'uic-pop-item uic-cascade-opt' + (on ? ' is-on' : '') + (o.badge ? ' has-badge' : '')}
|
|
195
199
|
aria-current={on ? 'true' : undefined}
|
|
196
200
|
disabled={!!o.disabled} onClick={() => onPick?.(active, o)}>
|
|
197
201
|
{value ? <span className="uic-pop-check" aria-hidden="true">{on ? <Tick /> : null}</span> : null}
|
|
198
202
|
<span className="uic-chip-t">{o.label}</span>
|
|
199
203
|
{o.note ? <span className="uic-cascade-note">{o.note}</span> : null}
|
|
204
|
+
{o.badge || null}
|
|
200
205
|
</button>
|
|
201
206
|
);
|
|
202
207
|
})}
|
|
203
208
|
{active && options.length === 0 ? <div className="uic-pop-note">{noOptionsText}</div> : null}
|
|
204
209
|
</div>
|
|
210
|
+
{optionsFooter || null}
|
|
205
211
|
</div>
|
|
206
212
|
)}
|
|
207
213
|
</div>
|
|
@@ -14,13 +14,17 @@
|
|
|
14
14
|
// surface, no divider band. This is where a product puts the row that
|
|
15
15
|
// belongs to the message being composed (Arena's harness+model chips,
|
|
16
16
|
// a template picker, a recipient list) rather than to the app chrome.
|
|
17
|
+
// onFiles(FileList) files dropped on the composer (or on dropTargetRef's element, when a
|
|
18
|
+
// product wants the whole conversation to take a drop). The composer is
|
|
19
|
+
// the one that lights up (.is-dropping) either way. Absent: no drop.
|
|
20
|
+
// dropTargetRef a ref to a wider drop target than the composer itself
|
|
17
21
|
// classNames { root, input, row } — each REPLACES the default class when provided,
|
|
18
22
|
// so a product can restyle wholesale without fighting the package CSS
|
|
19
23
|
//
|
|
20
24
|
// NOTE: autoGrow and a CSS-driven min-height on the textarea are mutually exclusive — autoGrow
|
|
21
25
|
// writes an explicit height on every keystroke, which the min-height then cannot raise. A fixed
|
|
22
26
|
// multi-line box wants autoGrow={false} + rows.
|
|
23
|
-
import React, { useEffect, useRef } from 'react';
|
|
27
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
24
28
|
import { IcSend } from './icons.jsx';
|
|
25
29
|
|
|
26
30
|
// Takes a single `props` object (destructured inside) so TSX consumers don't infer every slot
|
|
@@ -44,6 +48,8 @@ export function Composer(props) {
|
|
|
44
48
|
inputAriaLabel,
|
|
45
49
|
attachments,
|
|
46
50
|
tray,
|
|
51
|
+
onFiles,
|
|
52
|
+
dropTargetRef,
|
|
47
53
|
accessoriesLeft,
|
|
48
54
|
accessoriesRight,
|
|
49
55
|
renderSend,
|
|
@@ -52,6 +58,34 @@ export function Composer(props) {
|
|
|
52
58
|
} = props;
|
|
53
59
|
const ownRef = useRef(null);
|
|
54
60
|
const taRef = inputRef || ownRef;
|
|
61
|
+
const rootRef = useRef(null);
|
|
62
|
+
|
|
63
|
+
// Drag-and-drop attach. Native listeners on the target (the composer, or the wider element a
|
|
64
|
+
// product names), so any element can take the drop; a depth counter, because children fire
|
|
65
|
+
// their own enter/leave pairs and the highlight would flicker off while crossing them.
|
|
66
|
+
const [dropping, setDropping] = useState(false);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!onFiles || disabled) return undefined;
|
|
69
|
+
const el = (dropTargetRef && dropTargetRef.current) || rootRef.current;
|
|
70
|
+
if (!el) return undefined;
|
|
71
|
+
let depth = 0;
|
|
72
|
+
const hasFiles = (e) => Array.from((e.dataTransfer && e.dataTransfer.types) || []).includes('Files');
|
|
73
|
+
const enter = (e) => { if (!hasFiles(e)) return; e.preventDefault(); depth += 1; setDropping(true); };
|
|
74
|
+
const over = (e) => { if (!hasFiles(e)) return; e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; };
|
|
75
|
+
const leave = (e) => { if (!hasFiles(e)) return; e.preventDefault(); depth = Math.max(0, depth - 1); if (depth === 0) setDropping(false); };
|
|
76
|
+
const drop = (e) => {
|
|
77
|
+
if (!hasFiles(e)) return;
|
|
78
|
+
e.preventDefault(); depth = 0; setDropping(false);
|
|
79
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length) onFiles(e.dataTransfer.files);
|
|
80
|
+
};
|
|
81
|
+
el.addEventListener('dragenter', enter); el.addEventListener('dragover', over);
|
|
82
|
+
el.addEventListener('dragleave', leave); el.addEventListener('drop', drop);
|
|
83
|
+
return () => {
|
|
84
|
+
el.removeEventListener('dragenter', enter); el.removeEventListener('dragover', over);
|
|
85
|
+
el.removeEventListener('dragleave', leave); el.removeEventListener('drop', drop);
|
|
86
|
+
};
|
|
87
|
+
}, [onFiles, disabled, dropTargetRef]);
|
|
88
|
+
const rootClass = (classNames.root ?? 'wbx-composer') + (dropping ? ' is-dropping' : '');
|
|
55
89
|
|
|
56
90
|
// Auto-grow the composer to fit its content, capped at ~maxRows rows (then it scrolls).
|
|
57
91
|
useEffect(() => {
|
|
@@ -73,7 +107,7 @@ export function Composer(props) {
|
|
|
73
107
|
|
|
74
108
|
if (inline) {
|
|
75
109
|
return (
|
|
76
|
-
<div className={
|
|
110
|
+
<div ref={rootRef} className={rootClass}>
|
|
77
111
|
{attachments}
|
|
78
112
|
<div className="uic-composer-line">
|
|
79
113
|
{accessoriesLeft}
|
|
@@ -100,7 +134,7 @@ export function Composer(props) {
|
|
|
100
134
|
}
|
|
101
135
|
|
|
102
136
|
return (
|
|
103
|
-
<div className={
|
|
137
|
+
<div ref={rootRef} className={rootClass}>
|
|
104
138
|
{attachments}
|
|
105
139
|
<textarea
|
|
106
140
|
ref={taRef}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// - min/max clamps (absolute px and/or a viewport fraction, e.g. 60vw)
|
|
4
4
|
// - per-user width persistence (localStorage, storageKey)
|
|
5
5
|
// - double-click the divider to reset to the default width
|
|
6
|
+
// - axis: 'x' (default, side-by-side panes) or 'y' (stacked panes, e.g. an artifact preview
|
|
7
|
+
// under a narrow chat column, where splitting sideways would leave neither half readable)
|
|
6
8
|
//
|
|
7
9
|
// Usage:
|
|
8
10
|
// const pane = useResizablePane({ initial: 340, min: 320, maxFraction: 0.6,
|
|
@@ -17,15 +19,22 @@ export function useResizablePane(opts = {}) {
|
|
|
17
19
|
min = 240,
|
|
18
20
|
max = null, // absolute px cap (null = none)
|
|
19
21
|
maxFraction = null, // viewport-width fraction cap, e.g. 0.6 for 60vw (null = none)
|
|
20
|
-
fromRight = false, // divider sits on the pane's LEFT edge (dragging
|
|
21
|
-
storageKey = null, // persist the chosen
|
|
22
|
+
fromRight = false, // divider sits on the pane's LEFT/TOP edge (dragging toward it shrinks)
|
|
23
|
+
storageKey = null, // persist the chosen size per user (localStorage)
|
|
24
|
+
axis = 'x', // 'x' = width (col-resize), 'y' = height (row-resize)
|
|
22
25
|
} = opts;
|
|
26
|
+
const vertical = axis === 'y';
|
|
27
|
+
// One clamp, one drag, one persistence path for both orientations: the axis only decides which
|
|
28
|
+
// pointer coordinate and which viewport dimension are read.
|
|
29
|
+
const coord = (e) => (vertical ? e.clientY : e.clientX);
|
|
30
|
+
const viewportExtent = () => (typeof window === 'undefined' ? 0 : (vertical ? window.innerHeight : window.innerWidth));
|
|
31
|
+
const cursor = vertical ? 'row-resize' : 'col-resize';
|
|
23
32
|
|
|
24
33
|
const clamp = useCallback((x) => {
|
|
25
34
|
let hi = max ?? Infinity;
|
|
26
|
-
if (maxFraction && typeof window !== 'undefined') hi = Math.min(hi, Math.round(
|
|
35
|
+
if (maxFraction && typeof window !== 'undefined') hi = Math.min(hi, Math.round(viewportExtent() * maxFraction));
|
|
27
36
|
return Math.min(hi, Math.max(min, x));
|
|
28
|
-
}, [min, max, maxFraction]);
|
|
37
|
+
}, [min, max, maxFraction, vertical]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
29
38
|
|
|
30
39
|
const [width, setWidth] = useState(() => {
|
|
31
40
|
if (storageKey && typeof window !== 'undefined') {
|
|
@@ -46,38 +55,99 @@ export function useResizablePane(opts = {}) {
|
|
|
46
55
|
|
|
47
56
|
const onMouseDown = useCallback((e) => {
|
|
48
57
|
e.preventDefault();
|
|
49
|
-
const sx = e
|
|
58
|
+
const sx = coord(e), base = widthRef.current, dir = fromRight ? -1 : 1;
|
|
50
59
|
// While dragging, neutralize iframes/text-selection so an embedded preview can't swallow
|
|
51
60
|
// mousemove/mouseup (which would strand the drag).
|
|
52
61
|
document.body.classList.add('uic-resizing');
|
|
53
|
-
const move = (ev) => setWidth(clamp(base + dir * (ev
|
|
62
|
+
const move = (ev) => setWidth(clamp(base + dir * (coord(ev) - sx)));
|
|
54
63
|
const up = () => {
|
|
55
64
|
window.removeEventListener('mousemove', move); window.removeEventListener('mouseup', up);
|
|
56
65
|
document.body.style.cursor = ''; document.body.classList.remove('uic-resizing');
|
|
57
66
|
persist(widthRef.current);
|
|
58
67
|
};
|
|
59
68
|
window.addEventListener('mousemove', move); window.addEventListener('mouseup', up);
|
|
60
|
-
document.body.style.cursor =
|
|
61
|
-
}, [clamp, fromRight, persist]);
|
|
69
|
+
document.body.style.cursor = cursor;
|
|
70
|
+
}, [clamp, fromRight, persist, vertical]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
71
|
+
|
|
72
|
+
// Touch / pen drags (pointer events). Mouse keeps the mousedown path above
|
|
73
|
+
// untouched — this handler ignores mouse pointers so the two never double up.
|
|
74
|
+
const onPointerDown = useCallback((e) => {
|
|
75
|
+
if (e.pointerType === 'mouse') return;
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
const sx = coord(e), base = widthRef.current, dir = fromRight ? -1 : 1;
|
|
78
|
+
const el = e.currentTarget;
|
|
79
|
+
document.body.classList.add('uic-resizing');
|
|
80
|
+
try { el.setPointerCapture(e.pointerId); } catch { /* unsupported */ }
|
|
81
|
+
const move = (ev) => setWidth(clamp(base + dir * (coord(ev) - sx)));
|
|
82
|
+
const up = () => {
|
|
83
|
+
el.removeEventListener('pointermove', move);
|
|
84
|
+
el.removeEventListener('pointerup', up);
|
|
85
|
+
el.removeEventListener('pointercancel', up);
|
|
86
|
+
document.body.classList.remove('uic-resizing');
|
|
87
|
+
persist(widthRef.current);
|
|
88
|
+
};
|
|
89
|
+
el.addEventListener('pointermove', move);
|
|
90
|
+
el.addEventListener('pointerup', up);
|
|
91
|
+
el.addEventListener('pointercancel', up);
|
|
92
|
+
}, [clamp, fromRight, persist, vertical]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
93
|
+
|
|
94
|
+
// Keyboard resizing: move the pane edge by a signed px delta (clamped,
|
|
95
|
+
// persisted). Positive delta = wider pane.
|
|
96
|
+
const nudge = useCallback((delta) => {
|
|
97
|
+
const w = clamp(widthRef.current + delta);
|
|
98
|
+
setWidth(w);
|
|
99
|
+
persist(w);
|
|
100
|
+
}, [clamp, persist]);
|
|
62
101
|
|
|
63
102
|
const reset = useCallback(() => {
|
|
64
103
|
setWidth(initial);
|
|
65
104
|
if (storageKey) { try { window.localStorage.removeItem(storageKey); } catch { /* private mode */ } }
|
|
66
105
|
}, [initial, storageKey]);
|
|
67
106
|
|
|
68
|
-
|
|
107
|
+
// Resolved clamp bounds for aria-valuemin/max on the divider.
|
|
108
|
+
let maxResolved = max ?? null;
|
|
109
|
+
if (maxFraction && typeof window !== 'undefined') {
|
|
110
|
+
const frac = Math.round(viewportExtent() * maxFraction);
|
|
111
|
+
maxResolved = maxResolved == null ? frac : Math.min(maxResolved, frac);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { width, onMouseDown, onPointerDown, nudge, reset, min, max: maxResolved, fromRight, axis };
|
|
69
115
|
}
|
|
70
116
|
|
|
71
|
-
/** The grabbable divider (comfortable 7px hit area, col-resize cursor, dblclick = reset).
|
|
117
|
+
/** The grabbable divider (comfortable 7px hit area, col-resize cursor, dblclick = reset).
|
|
118
|
+
* Keyboard: focus it (Tab) and use ArrowLeft/ArrowRight to move the divider
|
|
119
|
+
* in 24px steps (Shift for 96px); touch drags work through pointer events.
|
|
120
|
+
* Mouse drag and double-click reset behave exactly as before. */
|
|
72
121
|
export function PaneResizer(props) {
|
|
73
122
|
const { pane, className, title = 'Drag to resize (double-click to reset)' } = props;
|
|
123
|
+
const vertical = pane.axis === 'y';
|
|
124
|
+
const onKeyDown = (e) => {
|
|
125
|
+
const keys = vertical ? ['ArrowUp', 'ArrowDown'] : ['ArrowLeft', 'ArrowRight'];
|
|
126
|
+
if (!keys.includes(e.key)) return;
|
|
127
|
+
if (!pane.nudge) return;
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
const step = e.shiftKey ? 96 : 24;
|
|
130
|
+
// Arrows move the SEPARATOR: for a trailing pane (divider on its leading
|
|
131
|
+
// edge) the forward key shrinks the pane; for a leading pane it grows it.
|
|
132
|
+
const forward = e.key === 'ArrowRight' || e.key === 'ArrowDown';
|
|
133
|
+
const dir = (forward ? 1 : -1) * (pane.fromRight ? -1 : 1);
|
|
134
|
+
pane.nudge(dir * step);
|
|
135
|
+
};
|
|
74
136
|
return (
|
|
75
137
|
<div
|
|
76
|
-
className={className ?? 'uic-vresize'}
|
|
138
|
+
className={className ?? (vertical ? 'uic-hresize' : 'uic-vresize')}
|
|
77
139
|
role="separator"
|
|
78
|
-
|
|
140
|
+
// The separator's own orientation: a stacked (axis 'y') split is divided by a HORIZONTAL bar.
|
|
141
|
+
aria-orientation={vertical ? 'horizontal' : 'vertical'}
|
|
142
|
+
aria-label={title}
|
|
143
|
+
aria-valuenow={Math.round(pane.width)}
|
|
144
|
+
aria-valuemin={pane.min != null ? Math.round(pane.min) : undefined}
|
|
145
|
+
aria-valuemax={pane.max != null ? Math.round(pane.max) : undefined}
|
|
146
|
+
tabIndex={0}
|
|
79
147
|
title={title}
|
|
80
148
|
onMouseDown={pane.onMouseDown}
|
|
149
|
+
onPointerDown={pane.onPointerDown}
|
|
150
|
+
onKeyDown={onKeyDown}
|
|
81
151
|
onDoubleClick={pane.reset}
|
|
82
152
|
/>
|
|
83
153
|
);
|