@openartifactsai/editor-kit 0.0.0-stage → 0.23.0-rc.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +143 -2
- package/package.json +67 -4
- package/src/Announcer.d.ts +2 -0
- package/src/Announcer.js +8 -0
- package/src/FindBar.d.ts +31 -0
- package/src/FindBar.js +37 -0
- package/src/FoldToolbar.d.ts +58 -0
- package/src/FoldToolbar.js +438 -0
- package/src/PanelEdge.d.ts +20 -0
- package/src/PanelEdge.js +74 -0
- package/src/VideoShrinkNotice.d.ts +10 -0
- package/src/VideoShrinkNotice.js +81 -0
- package/src/WheelZoomItem.d.ts +12 -0
- package/src/WheelZoomItem.js +18 -0
- package/src/agent.d.ts +68 -0
- package/src/agent.js +113 -0
- package/src/announce.d.ts +21 -0
- package/src/announce.js +31 -0
- package/src/chrome.d.ts +208 -0
- package/src/chrome.js +148 -0
- package/src/clipboard.d.ts +19 -0
- package/src/clipboard.js +48 -0
- package/src/collab/CommentList.d.ts +32 -0
- package/src/collab/CommentList.js +165 -0
- package/src/collab/CommentViews.d.ts +131 -0
- package/src/collab/CommentViews.js +619 -0
- package/src/collab/HistoryViews.d.ts +38 -0
- package/src/collab/HistoryViews.js +103 -0
- package/src/collab/PresenceViews.d.ts +53 -0
- package/src/collab/PresenceViews.js +48 -0
- package/src/collab/cds/cds.d.ts +151 -0
- package/src/collab/cds/cds.js +231 -0
- package/src/collab/cds/comment-card.d.ts +113 -0
- package/src/collab/cds/comment-card.js +230 -0
- package/src/collab/cds/comment-composer.d.ts +35 -0
- package/src/collab/cds/comment-composer.js +125 -0
- package/src/collab/cds/comments-css.d.ts +2 -0
- package/src/collab/cds/comments-css.js +3 -0
- package/src/collab/cds/comments.css +504 -0
- package/src/collab/cds/edge-piles.d.ts +69 -0
- package/src/collab/cds/edge-piles.js +178 -0
- package/src/collab/cds/layer.d.ts +41 -0
- package/src/collab/cds/layer.js +144 -0
- package/src/collab/cds/markdown.d.ts +20 -0
- package/src/collab/cds/markdown.js +534 -0
- package/src/collab/cds/shield.d.ts +28 -0
- package/src/collab/cds/shield.js +114 -0
- package/src/collab/cds/time.d.ts +2 -0
- package/src/collab/cds/time.js +41 -0
- package/src/collab/collab.d.ts +102 -0
- package/src/collab/collab.js +121 -0
- package/src/collab/comments.d.ts +272 -0
- package/src/collab/comments.js +596 -0
- package/src/collab/history-wiring.d.ts +32 -0
- package/src/collab/history-wiring.js +53 -0
- package/src/collab/history.d.ts +59 -0
- package/src/collab/history.js +96 -0
- package/src/collab/mentions/mention-list.d.ts +63 -0
- package/src/collab/mentions/mention-list.js +257 -0
- package/src/collab/mentions.d.ts +112 -0
- package/src/collab/mentions.js +164 -0
- package/src/collab/peer-colors.d.ts +123 -0
- package/src/collab/peer-colors.js +273 -0
- package/src/collab/pins.d.ts +70 -0
- package/src/collab/pins.js +44 -0
- package/src/collab/presence.d.ts +92 -0
- package/src/collab/presence.js +158 -0
- package/src/design-systems.d.ts +46 -0
- package/src/design-systems.js +61 -0
- package/src/downloads.d.ts +31 -0
- package/src/downloads.js +46 -0
- package/src/file-drop.d.ts +33 -0
- package/src/file-drop.js +36 -0
- package/src/find.d.ts +64 -0
- package/src/find.js +147 -0
- package/src/follow.d.ts +141 -0
- package/src/follow.js +389 -0
- package/src/index.d.ts +32 -0
- package/src/index.js +32 -0
- package/src/keys.d.ts +18 -0
- package/src/keys.js +42 -0
- package/src/menu-fit.d.ts +12 -0
- package/src/menu-fit.js +9 -0
- package/src/merge.d.ts +23 -0
- package/src/merge.js +116 -0
- package/src/page-link.d.ts +33 -0
- package/src/page-link.js +75 -0
- package/src/project-sync.d.ts +161 -0
- package/src/project-sync.js +319 -0
- package/src/react.d.ts +20 -0
- package/src/react.js +20 -0
- package/src/read-retries.d.ts +55 -0
- package/src/read-retries.js +125 -0
- package/src/right-drag-pan.d.ts +128 -0
- package/src/right-drag-pan.js +253 -0
- package/src/roles.d.ts +39 -0
- package/src/roles.js +27 -0
- package/src/session.d.ts +56 -0
- package/src/session.js +57 -0
- package/src/shell.d.ts +60 -0
- package/src/shell.js +111 -0
- package/src/stash.d.ts +26 -0
- package/src/stash.js +69 -0
- package/src/styles.css +17 -0
- package/src/toolbar-fold.d.ts +106 -0
- package/src/toolbar-fold.js +130 -0
- package/src/video-shrink/index.d.ts +8 -0
- package/src/video-shrink/index.js +7 -0
- package/src/video-shrink/plan.d.ts +92 -0
- package/src/video-shrink/plan.js +133 -0
- package/src/video-shrink/protocol.d.ts +29 -0
- package/src/video-shrink/protocol.js +2 -0
- package/src/video-shrink/queue.d.ts +69 -0
- package/src/video-shrink/queue.js +287 -0
- package/src/video-shrink/worker.d.ts +8 -0
- package/src/video-shrink/worker.js +223 -0
- package/src/wheel-zoom.d.ts +14 -0
- package/src/wheel-zoom.js +48 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A floating toolbar that can fold. With `fold` on, controls that do not fit
|
|
4
|
+
* the strip's width move into a "More tools" card opened from a button at the
|
|
5
|
+
* strip's end (the rules are in `toolbar-fold.ts`). They are the same mounted
|
|
6
|
+
* controls: each lives in a host node that moves, so pressed states, spinners
|
|
7
|
+
* and open popups go with it. On a narrow touch screen the strip does not
|
|
8
|
+
* fold; its row scrolls.
|
|
9
|
+
*
|
|
10
|
+
* Build the strip from {@link FoldGroup}s and {@link FoldDivider}s. Mark the
|
|
11
|
+
* properties / more button `data-fold-more`, a control that must stay on the
|
|
12
|
+
* strip `data-fold-keep`, and the last group `tail`.
|
|
13
|
+
*
|
|
14
|
+
* Arrow keys, Home and End move focus through the strip's and the open
|
|
15
|
+
* card's controls. An editor whose own Escape handling runs first (capturing
|
|
16
|
+
* on the window) leaves alone a press inside {@link FOLD_OWNS_ESCAPE}.
|
|
17
|
+
*/
|
|
18
|
+
import { Ellipsis } from 'lucide-react';
|
|
19
|
+
import { Children, createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, isValidElement, } from 'react';
|
|
20
|
+
import { createPortal } from 'react-dom';
|
|
21
|
+
import { cn, isComposingKey } from '@openartifactsai/ui';
|
|
22
|
+
import { Card, ChromeButton, Tip } from "./chrome.js";
|
|
23
|
+
import { FOLD_OWNS_ESCAPE, arrowStep, firstInCard, focusExit, foldItems, placeCard, scrollToShow, shownRuns, takesEscape } from "./toolbar-fold.js";
|
|
24
|
+
const MORE_TOOLS = 'More tools';
|
|
25
|
+
/** Controls the arrow keys visit, and those they pass over. */
|
|
26
|
+
const FOCUSABLE = 'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
27
|
+
const PASSED_OVER = ':disabled, [role="radio"][tabindex="-1"]';
|
|
28
|
+
const TEXT_FIELD = 'input, select, textarea, [contenteditable="true"], [contenteditable=""], [contenteditable="plaintext-only"], [role="textbox"]';
|
|
29
|
+
/** A popup (menu, popover) opened from a control of the strip; a tooltip is not one. */
|
|
30
|
+
const STRIP_POPUP = '[aria-expanded="true"]:not([data-fold-toggle])';
|
|
31
|
+
/** A modal dialog anywhere on the page. */
|
|
32
|
+
const MODAL = '[role="dialog"][aria-modal="true"], [role="alertdialog"]';
|
|
33
|
+
const NARROW_TOUCH = '(pointer: coarse) and (max-width: 599px)';
|
|
34
|
+
/** Margins kept around a control scrolled into view: along the strip, and inside the card. */
|
|
35
|
+
const ROW_SCROLL_MARGIN = 48;
|
|
36
|
+
const CARD_SCROLL_MARGIN = 8;
|
|
37
|
+
/** How often a postponed re-measure checks whether it may run. */
|
|
38
|
+
/** A strip class that positions it already (the card is placed against any of these). */
|
|
39
|
+
const POSITIONED = /(?:^|\s)(?:fixed|absolute|sticky)(?:\s|$)/;
|
|
40
|
+
const IDLE_POLL_MS = 200;
|
|
41
|
+
const FoldContext = createContext(null);
|
|
42
|
+
/** Whether the strip around the caller is folded (its properties button changes icon in the card). */
|
|
43
|
+
export function useFolded() {
|
|
44
|
+
return useContext(FoldContext)?.folded ?? false;
|
|
45
|
+
}
|
|
46
|
+
/* ------------------------------ the last key ------------------------------ */
|
|
47
|
+
/** Whether the last key down was F6 or Escape: focus that leaves a strip then was moved by the keyboard. */
|
|
48
|
+
let focusKeyDown = false;
|
|
49
|
+
let trackers = 0;
|
|
50
|
+
const noteKey = (event) => {
|
|
51
|
+
// An Escape that ends an input method's composition moves no focus.
|
|
52
|
+
focusKeyDown = !isComposingKey(event) && (event.key === 'F6' || event.key === 'Escape');
|
|
53
|
+
};
|
|
54
|
+
const forgetKey = () => {
|
|
55
|
+
focusKeyDown = false;
|
|
56
|
+
};
|
|
57
|
+
/** The window listeners behind `focusKeyDown`: [event, listener, capture]. */
|
|
58
|
+
const FOCUS_KEY_LISTENERS = [
|
|
59
|
+
['keydown', noteKey, true],
|
|
60
|
+
['keyup', forgetKey, true],
|
|
61
|
+
['pointerdown', forgetKey, true],
|
|
62
|
+
['blur', forgetKey, false],
|
|
63
|
+
];
|
|
64
|
+
function trackFocusKeys(view) {
|
|
65
|
+
if (trackers++ === 0)
|
|
66
|
+
for (const [type, listener, capture] of FOCUS_KEY_LISTENERS)
|
|
67
|
+
view.addEventListener(type, listener, capture);
|
|
68
|
+
return () => {
|
|
69
|
+
if (--trackers === 0)
|
|
70
|
+
for (const [type, listener, capture] of FOCUS_KEY_LISTENERS)
|
|
71
|
+
view.removeEventListener(type, listener, capture);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/* ------------------------------ page helpers ------------------------------ */
|
|
75
|
+
function subscribeNarrowTouch(change) {
|
|
76
|
+
const query = window.matchMedia?.(NARROW_TOUCH);
|
|
77
|
+
query?.addEventListener('change', change);
|
|
78
|
+
return () => query?.removeEventListener('change', change);
|
|
79
|
+
}
|
|
80
|
+
const isNarrowTouch = () => window.matchMedia?.(NARROW_TOUCH).matches ?? false;
|
|
81
|
+
/** Each item's host, by the slot it belongs in. */
|
|
82
|
+
const hostOf = new WeakMap();
|
|
83
|
+
function popupOpenIn(strip) {
|
|
84
|
+
return strip.querySelector(STRIP_POPUP) !== null || strip.ownerDocument.querySelector(MODAL) !== null;
|
|
85
|
+
}
|
|
86
|
+
const isTextField = (element) => element.matches(TEXT_FIELD) && !element.matches('input[type="range"]');
|
|
87
|
+
/** What decides a group's place: whether it holds a control now. */
|
|
88
|
+
function runOf(part, folded) {
|
|
89
|
+
if (part.hasAttribute('data-fold-divider'))
|
|
90
|
+
return 'divider';
|
|
91
|
+
if (part.hasAttribute('data-fold-toggle-group'))
|
|
92
|
+
return folded ? 'group' : 'empty';
|
|
93
|
+
const slots = part.querySelectorAll('[data-fold-slot]');
|
|
94
|
+
if (slots.length === 0)
|
|
95
|
+
return 'group';
|
|
96
|
+
return [...slots].some((slot) => slot.childElementCount > 0) ? 'group' : 'empty';
|
|
97
|
+
}
|
|
98
|
+
/** Hides the row's empty groups and the dividers left without a group on each side. */
|
|
99
|
+
function tidyRuns(row, folded) {
|
|
100
|
+
const parts = [...row.querySelectorAll('[data-fold-group], [data-fold-divider], [data-fold-toggle-group]')];
|
|
101
|
+
const shown = shownRuns(parts.map((part) => runOf(part, folded)));
|
|
102
|
+
parts.forEach((part, index) => part.toggleAttribute('data-fold-gone', !shown[index]));
|
|
103
|
+
}
|
|
104
|
+
function roleOf(slot) {
|
|
105
|
+
const host = hostOf.get(slot);
|
|
106
|
+
if (host?.querySelector('[data-fold-more]'))
|
|
107
|
+
return 'more';
|
|
108
|
+
if (slot.closest('[data-fold-tail]') || host?.querySelector('[data-fold-keep]'))
|
|
109
|
+
return 'pinned';
|
|
110
|
+
return 'loose';
|
|
111
|
+
}
|
|
112
|
+
/** A strip's content, to tell a real change from a re-render. */
|
|
113
|
+
const contentKey = (strip) => `${strip.getElementsByTagName('*').length}:${strip.textContent ?? ''}`;
|
|
114
|
+
/**
|
|
115
|
+
* Puts every item back, measures the strip at its natural width and, when it
|
|
116
|
+
* is wider than its limit, folds. True when it folded.
|
|
117
|
+
*/
|
|
118
|
+
function refoldStrip(strip, row, cardRow) {
|
|
119
|
+
const slots = [...row.querySelectorAll('[data-fold-slot]')];
|
|
120
|
+
for (const slot of slots) {
|
|
121
|
+
const host = hostOf.get(slot);
|
|
122
|
+
if (host && host.parentElement !== slot)
|
|
123
|
+
slot.append(host);
|
|
124
|
+
}
|
|
125
|
+
const limit = parseFloat(getComputedStyle(strip).maxWidth);
|
|
126
|
+
// Measured at its natural width: no maximum, and not shrunk by a flex row it sits in.
|
|
127
|
+
const { maxWidth, width, flexShrink } = strip.style;
|
|
128
|
+
strip.style.maxWidth = 'none';
|
|
129
|
+
strip.style.width = 'max-content';
|
|
130
|
+
strip.style.flexShrink = '0';
|
|
131
|
+
const stripWidth = () => strip.getBoundingClientRect().width;
|
|
132
|
+
let folded = false;
|
|
133
|
+
tidyRuns(row, false);
|
|
134
|
+
if (limit > 0 && stripWidth() > 0 && stripWidth() > limit) {
|
|
135
|
+
tidyRuns(row, true);
|
|
136
|
+
const card = foldItems(slots, roleOf, () => stripWidth() > limit, (slot, to) => {
|
|
137
|
+
const host = hostOf.get(slot);
|
|
138
|
+
if (!host)
|
|
139
|
+
return;
|
|
140
|
+
if (to === 'end')
|
|
141
|
+
cardRow.append(host);
|
|
142
|
+
else
|
|
143
|
+
cardRow.prepend(host);
|
|
144
|
+
tidyRuns(row, true);
|
|
145
|
+
});
|
|
146
|
+
folded = card.length > 0;
|
|
147
|
+
if (!folded)
|
|
148
|
+
tidyRuns(row, false);
|
|
149
|
+
}
|
|
150
|
+
strip.style.maxWidth = maxWidth;
|
|
151
|
+
strip.style.width = width;
|
|
152
|
+
strip.style.flexShrink = flexShrink;
|
|
153
|
+
strip.toggleAttribute('data-folded', folded);
|
|
154
|
+
return folded;
|
|
155
|
+
}
|
|
156
|
+
/* --------------------------------- parts ---------------------------------- */
|
|
157
|
+
/** One control of a group: on a folding strip it lives in a host node that moves between its place and the card. */
|
|
158
|
+
function FoldSlot({ children }) {
|
|
159
|
+
const fold = useContext(FoldContext);
|
|
160
|
+
const slot = useRef(null);
|
|
161
|
+
const [host] = useState(() => {
|
|
162
|
+
const node = document.createElement('span');
|
|
163
|
+
node.style.display = 'contents';
|
|
164
|
+
return node;
|
|
165
|
+
});
|
|
166
|
+
const changed = fold?.changed;
|
|
167
|
+
useLayoutEffect(() => {
|
|
168
|
+
const place = slot.current;
|
|
169
|
+
if (!place)
|
|
170
|
+
return;
|
|
171
|
+
hostOf.set(place, host);
|
|
172
|
+
place.append(host);
|
|
173
|
+
changed?.();
|
|
174
|
+
return () => {
|
|
175
|
+
host.remove();
|
|
176
|
+
changed?.();
|
|
177
|
+
};
|
|
178
|
+
}, [host, changed]);
|
|
179
|
+
return (_jsx("span", { ref: slot, "data-fold-slot": "", className: "contents", children: createPortal(children, host) }));
|
|
180
|
+
}
|
|
181
|
+
/** A group of related controls; each of its children folds as one item. */
|
|
182
|
+
export function FoldGroup({ tail, className, children, ...rest }) {
|
|
183
|
+
const fold = useContext(FoldContext);
|
|
184
|
+
const items = fold ? Children.toArray(children).map((child, index) => _jsx(FoldSlot, { children: child }, isValidElement(child) && child.key !== null ? child.key : index)) : children;
|
|
185
|
+
return (_jsx("span", { "data-fold-group": "", "data-fold-tail": tail ? '' : undefined, className: cn('flex shrink-0 items-center data-[fold-gone]:hidden', !/(?:^|\s)gap-/.test(className ?? '') && 'gap-0.5', className), ...rest, children: items }));
|
|
186
|
+
}
|
|
187
|
+
/** The divider between two groups; it goes when a group next to it empties. */
|
|
188
|
+
export function FoldDivider({ className }) {
|
|
189
|
+
return (_jsx("span", { "data-fold-divider": "", "aria-hidden": "true", className: "contents data-[fold-gone]:hidden", children: _jsx("span", { className: cn('mx-0.5 h-[18px] w-px shrink-0 bg-chrome-line', className) }) }));
|
|
190
|
+
}
|
|
191
|
+
/** A floating toolbar strip that folds what does not fit into a "More tools" card. */
|
|
192
|
+
export const FoldToolbar = forwardRef(function FoldToolbar({ fold = false, foldKey, band, placed = 'above', limit, rowClassName, size = 'md', arrowKeys = true, onTabOut, className, style, children, onKeyDown, onKeyDownCapture, onKeyUpCapture, onBlurCapture, ...rest }, ref) {
|
|
193
|
+
const narrowTouch = useSyncExternalStore(subscribeNarrowTouch, isNarrowTouch, () => false);
|
|
194
|
+
const foldable = fold && !narrowTouch;
|
|
195
|
+
const stripRef = useRef(null);
|
|
196
|
+
const rowRef = useRef(null);
|
|
197
|
+
const cardRef = useRef(null);
|
|
198
|
+
const cardRowRef = useRef(null);
|
|
199
|
+
const toggleRef = useRef(null);
|
|
200
|
+
const cardId = useId();
|
|
201
|
+
const [folded, setFolded] = useState(false);
|
|
202
|
+
const [open, setOpen] = useState(false);
|
|
203
|
+
const [escapeDown, setEscapeDown] = useState(false);
|
|
204
|
+
const opening = useRef(false);
|
|
205
|
+
const tabbing = useRef(false);
|
|
206
|
+
const remeasure = useRef(() => undefined);
|
|
207
|
+
const place = useRef(() => undefined);
|
|
208
|
+
const measuredKey = useRef(null);
|
|
209
|
+
const setStrip = useCallback((node) => {
|
|
210
|
+
stripRef.current = node;
|
|
211
|
+
if (typeof ref === 'function')
|
|
212
|
+
ref(node);
|
|
213
|
+
else if (ref)
|
|
214
|
+
ref.current = node;
|
|
215
|
+
}, [ref]);
|
|
216
|
+
const changed = useCallback(() => remeasure.current(), []);
|
|
217
|
+
const context = useMemo(() => ({ folded, changed }), [folded, changed]);
|
|
218
|
+
useEffect(() => trackFocusKeys(window), []);
|
|
219
|
+
// Measure now and whenever the row's width, the window, the content or the limit changes; never while a popup of
|
|
220
|
+
// the strip is open or the focus is on a control that may move, so neither jumps between the strip and the card.
|
|
221
|
+
useLayoutEffect(() => {
|
|
222
|
+
const strip = stripRef.current;
|
|
223
|
+
const row = rowRef.current;
|
|
224
|
+
const card = cardRef.current;
|
|
225
|
+
const cardRow = cardRowRef.current;
|
|
226
|
+
if (!foldable || !strip || !row || !card || !cardRow) {
|
|
227
|
+
remeasure.current = () => undefined;
|
|
228
|
+
setFolded(false);
|
|
229
|
+
setOpen(false);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
let width = 0;
|
|
233
|
+
let poll;
|
|
234
|
+
const mayMove = (element) => {
|
|
235
|
+
if (!element || !strip.contains(element))
|
|
236
|
+
return false;
|
|
237
|
+
if (element.closest('[data-fold-slot]')?.querySelector('[data-fold-keep]'))
|
|
238
|
+
return false;
|
|
239
|
+
if (card.contains(element))
|
|
240
|
+
return !card.hidden;
|
|
241
|
+
return element.closest('[data-fold-slot], [data-fold-toggle-group]') !== null;
|
|
242
|
+
};
|
|
243
|
+
const busy = () => popupOpenIn(strip) || mayMove(document.activeElement);
|
|
244
|
+
const measure = () => {
|
|
245
|
+
const isFolded = refoldStrip(strip, row, cardRow);
|
|
246
|
+
width = row.getBoundingClientRect().width;
|
|
247
|
+
measuredKey.current = contentKey(strip);
|
|
248
|
+
observer.takeRecords();
|
|
249
|
+
setFolded(isFolded);
|
|
250
|
+
if (!isFolded)
|
|
251
|
+
setOpen(false);
|
|
252
|
+
else if (!card.hidden)
|
|
253
|
+
place.current();
|
|
254
|
+
};
|
|
255
|
+
const run = () => {
|
|
256
|
+
window.clearInterval(poll);
|
|
257
|
+
poll = undefined;
|
|
258
|
+
if (!busy())
|
|
259
|
+
return measure();
|
|
260
|
+
poll = window.setInterval(() => {
|
|
261
|
+
if (busy())
|
|
262
|
+
return;
|
|
263
|
+
window.clearInterval(poll);
|
|
264
|
+
poll = undefined;
|
|
265
|
+
measure();
|
|
266
|
+
}, IDLE_POLL_MS);
|
|
267
|
+
};
|
|
268
|
+
const observer = new MutationObserver(() => {
|
|
269
|
+
if (contentKey(strip) !== measuredKey.current)
|
|
270
|
+
run();
|
|
271
|
+
});
|
|
272
|
+
observer.observe(row, { childList: true, subtree: true, characterData: true });
|
|
273
|
+
observer.observe(cardRow, { childList: true, subtree: true, characterData: true });
|
|
274
|
+
const resize = new ResizeObserver(() => {
|
|
275
|
+
if (Math.abs(row.getBoundingClientRect().width - width) > 0.5)
|
|
276
|
+
run();
|
|
277
|
+
});
|
|
278
|
+
resize.observe(row);
|
|
279
|
+
window.addEventListener('resize', run);
|
|
280
|
+
remeasure.current = run;
|
|
281
|
+
run();
|
|
282
|
+
return () => {
|
|
283
|
+
window.clearInterval(poll);
|
|
284
|
+
observer.disconnect();
|
|
285
|
+
resize.disconnect();
|
|
286
|
+
window.removeEventListener('resize', run);
|
|
287
|
+
remeasure.current = () => undefined;
|
|
288
|
+
};
|
|
289
|
+
}, [foldable]);
|
|
290
|
+
useLayoutEffect(() => remeasure.current(), [limit]);
|
|
291
|
+
// Another selection: the card closes, and focus in it goes back to its button.
|
|
292
|
+
useLayoutEffect(() => {
|
|
293
|
+
if (cardRef.current?.contains(document.activeElement))
|
|
294
|
+
toggleRef.current?.focus({ preventScroll: true });
|
|
295
|
+
setOpen(false);
|
|
296
|
+
}, [foldKey]);
|
|
297
|
+
useLayoutEffect(() => {
|
|
298
|
+
place.current = () => {
|
|
299
|
+
const strip = stripRef.current;
|
|
300
|
+
const card = cardRef.current;
|
|
301
|
+
if (!strip || !card)
|
|
302
|
+
return;
|
|
303
|
+
const box = strip.getBoundingClientRect();
|
|
304
|
+
const size = card.getBoundingClientRect();
|
|
305
|
+
const at = placeCard(box, size, placed, band ?? { top: 0, bottom: window.innerHeight });
|
|
306
|
+
card.dataset.side = at.side;
|
|
307
|
+
card.style.right = at.shift > 0 ? `${-at.shift}px` : '';
|
|
308
|
+
};
|
|
309
|
+
if (open)
|
|
310
|
+
place.current();
|
|
311
|
+
});
|
|
312
|
+
// Opened with More tools (a click or a key): the focus goes to the card's first button (else its first field), in view.
|
|
313
|
+
useLayoutEffect(() => {
|
|
314
|
+
const cardRow = cardRowRef.current;
|
|
315
|
+
if (open && cardRow)
|
|
316
|
+
cardRow.scrollLeft = 0;
|
|
317
|
+
const pressed = opening.current;
|
|
318
|
+
opening.current = false;
|
|
319
|
+
if (!open || !pressed || !cardRow)
|
|
320
|
+
return;
|
|
321
|
+
const enabled = (selector) => [...cardRow.querySelectorAll(selector)].filter((element) => !element.matches(':disabled, [tabindex="-1"]'));
|
|
322
|
+
const first = firstInCard(enabled('button'), enabled('input, select, textarea'));
|
|
323
|
+
if (!first)
|
|
324
|
+
return;
|
|
325
|
+
first.focus({ preventScroll: true });
|
|
326
|
+
showControl(first);
|
|
327
|
+
}, [open]);
|
|
328
|
+
/** Scrolls a control into view along the strip, or inside the card. */
|
|
329
|
+
const showControl = (control) => {
|
|
330
|
+
const inCard = cardRowRef.current?.contains(control) === true;
|
|
331
|
+
const box = inCard ? cardRowRef.current : rowRef.current;
|
|
332
|
+
if (!box)
|
|
333
|
+
return;
|
|
334
|
+
box.scrollLeft += scrollToShow(control.getBoundingClientRect(), box.getBoundingClientRect(), inCard ? CARD_SCROLL_MARGIN : ROW_SCROLL_MARGIN);
|
|
335
|
+
};
|
|
336
|
+
const toggle = (event) => {
|
|
337
|
+
// Only the main button clicks: a press of it, with the mouse or the keyboard, leads into the card.
|
|
338
|
+
opening.current = event.button === 0;
|
|
339
|
+
if (cardRef.current?.contains(document.activeElement))
|
|
340
|
+
toggleRef.current?.focus({ preventScroll: true });
|
|
341
|
+
setOpen((was) => !was);
|
|
342
|
+
};
|
|
343
|
+
/** Enter and Space on More tools press it: a page's own shortcuts for those keys do not also run. */
|
|
344
|
+
const keepActivation = (event) => {
|
|
345
|
+
if (isComposingKey(event.nativeEvent))
|
|
346
|
+
return;
|
|
347
|
+
if (event.key === 'Enter' || event.key === ' ')
|
|
348
|
+
event.stopPropagation();
|
|
349
|
+
};
|
|
350
|
+
const keyDownCapture = (event) => {
|
|
351
|
+
if (isComposingKey(event.nativeEvent)) {
|
|
352
|
+
onKeyDownCapture?.(event);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const strip = event.currentTarget;
|
|
356
|
+
const target = event.target;
|
|
357
|
+
const inStrip = strip.contains(target);
|
|
358
|
+
const popupOpen = popupOpenIn(strip);
|
|
359
|
+
tabbing.current = event.key === 'Tab' && !event.ctrlKey && !event.metaKey && inStrip && !popupOpen;
|
|
360
|
+
const escape = takesEscape({
|
|
361
|
+
key: event.key,
|
|
362
|
+
defaultPrevented: event.defaultPrevented,
|
|
363
|
+
ownedHere: inStrip && target.closest(FOLD_OWNS_ESCAPE) !== null,
|
|
364
|
+
popupOpen,
|
|
365
|
+
inTextField: isTextField(target),
|
|
366
|
+
});
|
|
367
|
+
if (escape) {
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
event.stopPropagation();
|
|
370
|
+
if (event.repeat)
|
|
371
|
+
return;
|
|
372
|
+
if (cardRef.current?.contains(target))
|
|
373
|
+
toggleRef.current?.focus({ preventScroll: true });
|
|
374
|
+
setOpen(false);
|
|
375
|
+
setEscapeDown(true);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
onKeyDownCapture?.(event);
|
|
379
|
+
};
|
|
380
|
+
const keyDown = (event) => {
|
|
381
|
+
onKeyDown?.(event);
|
|
382
|
+
if (event.defaultPrevented || isComposingKey(event.nativeEvent))
|
|
383
|
+
return;
|
|
384
|
+
const strip = event.currentTarget;
|
|
385
|
+
const target = event.target;
|
|
386
|
+
if (!strip.contains(target) || isTextField(target) || target.isContentEditable || popupOpenIn(strip))
|
|
387
|
+
return;
|
|
388
|
+
if (event.key === 'Tab') {
|
|
389
|
+
if (onTabOut?.())
|
|
390
|
+
event.preventDefault();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (!arrowKeys)
|
|
394
|
+
return;
|
|
395
|
+
const controls = [...strip.querySelectorAll(FOCUSABLE)].filter((control) => control.getClientRects().length > 0 && (control === target || !control.matches(PASSED_OVER)));
|
|
396
|
+
const next = arrowStep(event, controls.findIndex((control) => control.contains(target)), controls.length);
|
|
397
|
+
if (next === null)
|
|
398
|
+
return;
|
|
399
|
+
event.preventDefault();
|
|
400
|
+
const control = controls[next];
|
|
401
|
+
control.focus({ preventScroll: true });
|
|
402
|
+
showControl(control);
|
|
403
|
+
};
|
|
404
|
+
const keyUpCapture = (event) => {
|
|
405
|
+
if (event.key === 'Escape' || event.key === 'Meta')
|
|
406
|
+
setEscapeDown(false);
|
|
407
|
+
tabbing.current = false;
|
|
408
|
+
onKeyUpCapture?.(event);
|
|
409
|
+
};
|
|
410
|
+
const blurCapture = (event) => {
|
|
411
|
+
const strip = event.currentTarget;
|
|
412
|
+
const to = event.relatedTarget;
|
|
413
|
+
if (to === null || !strip.contains(to)) {
|
|
414
|
+
const exit = focusExit({
|
|
415
|
+
into: to === null ? 'nowhere' : 'outside',
|
|
416
|
+
tabbing: tabbing.current,
|
|
417
|
+
byFocusKey: focusKeyDown && strip.contains(event.target),
|
|
418
|
+
popupOpen: popupOpenIn(strip),
|
|
419
|
+
toToast: to?.closest('[data-toast]') != null,
|
|
420
|
+
});
|
|
421
|
+
if (exit === 'close')
|
|
422
|
+
setOpen(false);
|
|
423
|
+
else if (exit === 'close-unless-back')
|
|
424
|
+
window.setTimeout(() => {
|
|
425
|
+
if (!strip.contains(document.activeElement))
|
|
426
|
+
setOpen(false);
|
|
427
|
+
});
|
|
428
|
+
tabbing.current = false;
|
|
429
|
+
setEscapeDown(false);
|
|
430
|
+
}
|
|
431
|
+
onBlurCapture?.(event);
|
|
432
|
+
};
|
|
433
|
+
return (_jsxs(Card, { ref: setStrip, role: "toolbar", "data-fold-strip": foldable ? '' : undefined,
|
|
434
|
+
// The card hangs off the strip: a strip placed some other way keeps its own position.
|
|
435
|
+
className: cn(!POSITIONED.test(className ?? '') && 'relative', 'max-w-[calc(100vw-16px)]', className), style: limit === undefined ? style : { ...style, maxWidth: limit }, onKeyDownCapture: keyDownCapture, onKeyDown: keyDown, onKeyUpCapture: keyUpCapture, onBlurCapture: blurCapture, ...rest, children: [_jsx("div", { ref: rowRef, "data-fold-row": "", "data-fold-escape": foldable && (open || escapeDown) ? '' : undefined, className: cn('flex min-w-0 flex-auto items-center gap-1 overflow-x-auto rounded-[inherit] p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden', rowClassName), children: _jsxs(FoldContext.Provider, { value: foldable ? context : null, children: [children, foldable ? (
|
|
436
|
+
// Hidden until a measure folds the strip, so a measure put off by an open popup never shows it on a strip that fits.
|
|
437
|
+
_jsx("span", { "data-fold-toggle-group": "", "data-fold-gone": folded ? undefined : '', className: "flex shrink-0 items-center data-[fold-gone]:hidden", children: _jsx(Tip, { label: MORE_TOOLS, side: placed === 'below' ? 'bottom' : 'top', children: _jsx(ChromeButton, { ref: toggleRef, square: true, size: size, "data-fold-toggle": "", "aria-label": MORE_TOOLS, "aria-expanded": open, "aria-controls": cardId, className: cn(size === 'xl' && '[&_svg]:size-[18px]', open && 'bg-chrome-hover'), onClick: toggle, onKeyDown: keepActivation, children: _jsx(Ellipsis, { className: "size-4", strokeWidth: 1.5, "aria-hidden": "true" }) }) }) })) : null] }) }), foldable ? (_jsx("div", { ref: cardRef, id: cardId, role: "group", "aria-label": MORE_TOOLS, "data-fold-card": "", "data-fold-escape": "", "data-side": placed, hidden: !open, className: "absolute right-0 w-max max-w-[calc(100vw-16px)] rounded-[inherit] bg-chrome text-chrome-fg shadow-chrome data-[side=above]:bottom-[calc(100%+8px)] data-[side=below]:top-[calc(100%+8px)]", children: _jsx("div", { ref: cardRowRef, "data-fold-card-row": "", className: "flex items-center gap-0.5 overflow-x-auto rounded-[inherit] p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden" }) })) : null] }));
|
|
438
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface PanelEdgeProps {
|
|
3
|
+
label: string;
|
|
4
|
+
width: number;
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
/** Which of the panel's sides the edge is on. */
|
|
8
|
+
side: 'left' | 'right';
|
|
9
|
+
onResize(width: number): void;
|
|
10
|
+
onReset?(): void;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function PanelEdge({ label, width, min, max, side, onResize, onReset, className }: PanelEdgeProps): ReactNode;
|
|
14
|
+
export interface PanelWidth {
|
|
15
|
+
width: number;
|
|
16
|
+
resize(width: number): void;
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
19
|
+
/** A panel's width between `min` and `max` (and never wider than `cap`, when given), kept in this browser under `key`. */
|
|
20
|
+
export declare function usePanelWidth(key: string, initial: number, min: number, max: number, cap?: number): PanelWidth;
|
package/src/PanelEdge.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A panel's edge that resizes it: drag it, or with it focused press the arrow keys (Shift for bigger steps); a double
|
|
4
|
+
* click puts the panel back to its first width. `usePanelWidth` keeps the width per panel in this browser.
|
|
5
|
+
*/
|
|
6
|
+
import { cn } from '@openartifactsai/ui';
|
|
7
|
+
import { useCallback, useRef, useState } from 'react';
|
|
8
|
+
const STEP = 8;
|
|
9
|
+
const BIG_STEP = 32;
|
|
10
|
+
export function PanelEdge({ label, width, min, max, side, onResize, onReset, className }) {
|
|
11
|
+
const start = useRef(null);
|
|
12
|
+
const grow = side === 'left' ? -1 : 1;
|
|
13
|
+
const down = (event) => {
|
|
14
|
+
if (event.button !== 0)
|
|
15
|
+
return;
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
18
|
+
start.current = { x: event.clientX, width };
|
|
19
|
+
};
|
|
20
|
+
const move = (event) => {
|
|
21
|
+
if (!start.current)
|
|
22
|
+
return;
|
|
23
|
+
onResize(start.current.width + (event.clientX - start.current.x) * grow);
|
|
24
|
+
};
|
|
25
|
+
const up = () => {
|
|
26
|
+
start.current = null;
|
|
27
|
+
};
|
|
28
|
+
const key = (event) => {
|
|
29
|
+
if (start.current || event.metaKey || event.ctrlKey || event.altKey)
|
|
30
|
+
return;
|
|
31
|
+
const toward = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0;
|
|
32
|
+
if (!toward)
|
|
33
|
+
return;
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
event.stopPropagation();
|
|
36
|
+
onResize(width + toward * grow * (event.shiftKey ? BIG_STEP : STEP));
|
|
37
|
+
};
|
|
38
|
+
return (_jsx("div", { role: "separator", "aria-orientation": "vertical", "aria-label": label, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": Math.round(width), tabIndex: 0, className: cn('absolute inset-y-0 z-10 w-2 cursor-col-resize outline-none pointer-coarse:hidden', 'hover:bg-[linear-gradient(to_right,transparent_3px,var(--color-chrome-accent)_3px,var(--color-chrome-accent)_5px,transparent_5px)]', 'focus-visible:bg-[linear-gradient(to_right,transparent_3px,var(--color-chrome-accent)_3px,var(--color-chrome-accent)_5px,transparent_5px)]', side === 'left' ? '-left-1' : '-right-1', className), onPointerDown: down, onPointerMove: move, onPointerUp: up, onPointerCancel: up, onKeyDown: key, onDoubleClick: onReset }));
|
|
39
|
+
}
|
|
40
|
+
function readWidth(key) {
|
|
41
|
+
try {
|
|
42
|
+
const value = Number(localStorage.getItem(key));
|
|
43
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function writeWidth(key, width) {
|
|
50
|
+
try {
|
|
51
|
+
if (width === null)
|
|
52
|
+
localStorage.removeItem(key);
|
|
53
|
+
else
|
|
54
|
+
localStorage.setItem(key, String(Math.round(width)));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// A browser that keeps nothing still resizes for the visit.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** A panel's width between `min` and `max` (and never wider than `cap`, when given), kept in this browser under `key`. */
|
|
61
|
+
export function usePanelWidth(key, initial, min, max, cap = Infinity) {
|
|
62
|
+
const clamp = useCallback((value) => Math.round(Math.max(min, Math.min(max, cap, value))), [min, max, cap]);
|
|
63
|
+
const [stored, setStored] = useState(() => readWidth(key) ?? initial);
|
|
64
|
+
const resize = useCallback((value) => {
|
|
65
|
+
const next = clamp(value);
|
|
66
|
+
setStored(next);
|
|
67
|
+
writeWidth(key, next);
|
|
68
|
+
}, [clamp, key]);
|
|
69
|
+
const reset = useCallback(() => {
|
|
70
|
+
setStored(initial);
|
|
71
|
+
writeWidth(key, null);
|
|
72
|
+
}, [initial, key]);
|
|
73
|
+
return { width: clamp(stored), resize, reset };
|
|
74
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The notice that stays up while videos are being made small enough to
|
|
3
|
+
* store: what is happening to the first one, how far along it is, the
|
|
4
|
+
* limit, a reminder to keep the tab open, how many more are waiting, and
|
|
5
|
+
* Cancel for the first one.
|
|
6
|
+
*/
|
|
7
|
+
import { type ShrinkEntry } from './video-shrink/queue.js';
|
|
8
|
+
/** The notice's first line for `job`. */
|
|
9
|
+
export declare function shrinkStatus(job: ShrinkEntry): string;
|
|
10
|
+
export declare function VideoShrinkNotice(): null;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The notice that stays up while videos are being made small enough to
|
|
4
|
+
* store: what is happening to the first one, how far along it is, the
|
|
5
|
+
* limit, a reminder to keep the tab open, how many more are waiting, and
|
|
6
|
+
* Cancel for the first one.
|
|
7
|
+
*/
|
|
8
|
+
import { useEffect, useRef } from 'react';
|
|
9
|
+
import { toast } from '@openartifactsai/ui';
|
|
10
|
+
import { SHRINK_WORDS } from "./video-shrink/plan.js";
|
|
11
|
+
import { cancelShrink, leadingShrink, useVideoShrink } from "./video-shrink/queue.js";
|
|
12
|
+
/** The notice's first line for `job`. */
|
|
13
|
+
export function shrinkStatus(job) {
|
|
14
|
+
if (job.waiting)
|
|
15
|
+
return SHRINK_WORDS.waiting;
|
|
16
|
+
if (job.phase === 'placing')
|
|
17
|
+
return SHRINK_WORDS.placing;
|
|
18
|
+
if (job.phase === 'shrinking' && job.attempt > 1)
|
|
19
|
+
return SHRINK_WORDS.retrying;
|
|
20
|
+
return SHRINK_WORDS.shrinking;
|
|
21
|
+
}
|
|
22
|
+
function Details({ job, waitingCount }) {
|
|
23
|
+
const percent = Math.round(job.progress * 100);
|
|
24
|
+
const showBar = job.phase !== 'placing' && !job.waiting;
|
|
25
|
+
return (_jsxs("span", { className: "flex flex-col gap-1", children: [showBar ? (_jsxs("span", { className: "flex items-center gap-2", children: [_jsx("span", { role: "progressbar", "aria-label": SHRINK_WORDS.progressLabel, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent, className: "h-1 flex-1 overflow-hidden rounded-full bg-hover", children: _jsx("span", { className: "block h-full rounded-full bg-accent transition-[width]", style: { width: `${percent}%` } }) }), _jsxs("span", { className: "tabular-nums", children: [percent, "%"] })] })) : null, _jsxs("span", { children: [SHRINK_WORDS.limit(), " ", SHRINK_WORDS.keepOpen, waitingCount > 0 ? ` ${SHRINK_WORDS.queued(waitingCount)}` : ''] })] }));
|
|
26
|
+
}
|
|
27
|
+
export function VideoShrinkNotice() {
|
|
28
|
+
const jobs = useVideoShrink((state) => state.jobs);
|
|
29
|
+
const toastId = useRef(null);
|
|
30
|
+
const dismissed = useRef(false);
|
|
31
|
+
// While the shrunk video waits for the text box to be left, pressing Cancel would leave it (and place the video) before the click lands.
|
|
32
|
+
const cancelledOnPress = useRef(false);
|
|
33
|
+
const job = leadingShrink(jobs);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!job) {
|
|
36
|
+
if (toastId.current)
|
|
37
|
+
toast.close(toastId.current);
|
|
38
|
+
toastId.current = null;
|
|
39
|
+
dismissed.current = false;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (dismissed.current)
|
|
43
|
+
return;
|
|
44
|
+
const id = job.id;
|
|
45
|
+
const options = {
|
|
46
|
+
title: shrinkStatus(job),
|
|
47
|
+
description: _jsx(Details, { job: job, waitingCount: jobs.length - 1 }),
|
|
48
|
+
timeout: 0,
|
|
49
|
+
actionProps: {
|
|
50
|
+
children: SHRINK_WORDS.cancel,
|
|
51
|
+
onPointerDown: () => {
|
|
52
|
+
cancelledOnPress.current = job.waiting;
|
|
53
|
+
if (cancelledOnPress.current)
|
|
54
|
+
cancelShrink(id);
|
|
55
|
+
},
|
|
56
|
+
onPointerCancel: () => {
|
|
57
|
+
cancelledOnPress.current = false;
|
|
58
|
+
},
|
|
59
|
+
onClick: () => {
|
|
60
|
+
if (!cancelledOnPress.current)
|
|
61
|
+
cancelShrink(id);
|
|
62
|
+
cancelledOnPress.current = false;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
onClose: () => {
|
|
66
|
+
if (toastId.current)
|
|
67
|
+
dismissed.current = true;
|
|
68
|
+
toastId.current = null;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
if (toastId.current)
|
|
72
|
+
toast.update(toastId.current, options);
|
|
73
|
+
else
|
|
74
|
+
toastId.current = toast.add(options);
|
|
75
|
+
}, [job, jobs.length]);
|
|
76
|
+
useEffect(() => () => {
|
|
77
|
+
if (toastId.current)
|
|
78
|
+
toast.close(toastId.current);
|
|
79
|
+
}, []);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "Scroll to zoom" menu row the canvases share (see wheel-zoom.ts), and
|
|
3
|
+
* a hook for views that word their hints by it.
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
/** Whether a plain wheel zooms, kept current. */
|
|
7
|
+
export declare function useWheelZooms(): boolean;
|
|
8
|
+
/** A checked row that turns "Scroll to zoom" on and off. */
|
|
9
|
+
export declare function WheelZoomMenuItem({ disabled, closeOnClick }: {
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
closeOnClick?: boolean;
|
|
12
|
+
}): ReactNode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The "Scroll to zoom" menu row the canvases share (see wheel-zoom.ts), and
|
|
4
|
+
* a hook for views that word their hints by it.
|
|
5
|
+
*/
|
|
6
|
+
import { useSyncExternalStore } from 'react';
|
|
7
|
+
import { ChromeMenuItem } from "./chrome.js";
|
|
8
|
+
import { MOD } from "./keys.js";
|
|
9
|
+
import { onWheelZoomsChange, setWheelZooms, wheelZooms } from "./wheel-zoom.js";
|
|
10
|
+
/** Whether a plain wheel zooms, kept current. */
|
|
11
|
+
export function useWheelZooms() {
|
|
12
|
+
return useSyncExternalStore(onWheelZoomsChange, wheelZooms, () => false);
|
|
13
|
+
}
|
|
14
|
+
/** A checked row that turns "Scroll to zoom" on and off. */
|
|
15
|
+
export function WheelZoomMenuItem({ disabled, closeOnClick }) {
|
|
16
|
+
const on = useWheelZooms();
|
|
17
|
+
return (_jsx(ChromeMenuItem, { checked: on, disabled: disabled, closeOnClick: closeOnClick, title: `The wheel zooms at the pointer without ${MOD.replace(/\+$/, '')}. Made for a mouse: two-finger scrolling on a trackpad zooms too.`, description: "Drag with the right button to pan", onSelect: () => setWheelZooms(!on), children: "Scroll to zoom" }));
|
|
18
|
+
}
|