@tristan2828/ui-foundation 4.130.0 → 4.130.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.
|
@@ -91,16 +91,42 @@ function Control({ render, ...props }) {
|
|
|
91
91
|
// field's left edge, so it's never off screen (F5). Not CSS sticky: a
|
|
92
92
|
// section's card clips its content (`overflow-hidden`), which stops sticky
|
|
93
93
|
// at the card. Returns where to pin it, or null while it shows in place.
|
|
94
|
+
//
|
|
95
|
+
// Judged by where the field ends with its line in place, pinned or not.
|
|
96
|
+
// Pinning takes the line out of the field, so the field's own box is
|
|
97
|
+
// shorter by the line while it's pinned: judged by that box, a field whose
|
|
98
|
+
// end is within a line of the screen's bottom pinned, shrank, unpinned,
|
|
99
|
+
// grew and pinned again, every frame (a conflict's two buttons hopping
|
|
100
|
+
// 128px on a phone, never still enough to press).
|
|
94
101
|
function usePinnedStatus(field, enabled) {
|
|
95
102
|
const [pin, setPin] = useState(null);
|
|
96
103
|
useLayoutEffect(() => {
|
|
97
104
|
if (!enabled)
|
|
98
105
|
return;
|
|
99
106
|
let frame = 0;
|
|
107
|
+
// How far the line in place reaches below the rest of the field (the
|
|
108
|
+
// gap and the line), measured whenever it's in place.
|
|
109
|
+
let reserve = 0;
|
|
100
110
|
const measure = () => {
|
|
101
111
|
frame = 0;
|
|
102
|
-
const
|
|
103
|
-
const
|
|
112
|
+
const element = field.current;
|
|
113
|
+
const box = element?.getBoundingClientRect();
|
|
114
|
+
let bottom = box?.bottom;
|
|
115
|
+
const line = element?.querySelector(':scope > [data-slot="editable-value-status"]');
|
|
116
|
+
if (element && box && line) {
|
|
117
|
+
if (line.hasAttribute('data-pinned')) {
|
|
118
|
+
bottom = box.bottom + reserve;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
let rest = box.top;
|
|
122
|
+
for (const child of element.children) {
|
|
123
|
+
if (child !== line)
|
|
124
|
+
rest = Math.max(rest, child.getBoundingClientRect().bottom);
|
|
125
|
+
}
|
|
126
|
+
reserve = Math.max(0, box.bottom - rest);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const runsPast = box !== undefined && bottom !== undefined && box.top < window.innerHeight - 48 && bottom > window.innerHeight;
|
|
104
130
|
setPin((current) => {
|
|
105
131
|
if (!runsPast)
|
|
106
132
|
return null;
|
|
@@ -116,7 +116,7 @@ import { DEFAULT_HEADING_LEVEL } from './prose-look.js';
|
|
|
116
116
|
import { foldPlugin, setFolds } from './rich-text-fold.js';
|
|
117
117
|
import { headingView } from './rich-text-heading-view.js';
|
|
118
118
|
import { taskItemView, toggleTaskItem } from './rich-text-task-item-view.js';
|
|
119
|
-
import { applyLink, followLink, linkTarget } from './rich-text-links.js';
|
|
119
|
+
import { applyLink, followLink, linkTarget, notePress } from './rich-text-links.js';
|
|
120
120
|
import { anchorAt } from './rich-text-box-anchor.js';
|
|
121
121
|
import { LinkForm } from './rich-text-link-box.js';
|
|
122
122
|
import { PageForm } from './rich-text-page-box.js';
|
|
@@ -672,7 +672,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
672
672
|
}),
|
|
673
673
|
// The floating toolbar waits for the mouse to be up: a drag
|
|
674
674
|
// is still choosing the words.
|
|
675
|
-
mousedown: (
|
|
675
|
+
mousedown: (view, event) => {
|
|
676
|
+
notePress(view, event);
|
|
676
677
|
if (event.button !== 0)
|
|
677
678
|
return false;
|
|
678
679
|
setDismissed(null);
|
|
@@ -7,6 +7,8 @@ export type LinkTarget = {
|
|
|
7
7
|
href: string;
|
|
8
8
|
};
|
|
9
9
|
export declare function linkTarget(state: EditorState): LinkTarget;
|
|
10
|
+
/** Where the mouse went down in the editor: `followLink` doesn't follow a drag. */
|
|
11
|
+
export declare function notePress(view: EditorView, event: MouseEvent): void;
|
|
10
12
|
export declare function followLink(view: EditorView, event: MouseEvent, pages: {
|
|
11
13
|
resolve: PageLinkResolver | undefined;
|
|
12
14
|
open: (href: string) => void;
|
|
@@ -45,6 +45,17 @@ export function linkTarget(state) {
|
|
|
45
45
|
// A page link (`pageLink`) opens its page in this tab instead (`open`:
|
|
46
46
|
// the router's, when there is one), and a removed page's link opens
|
|
47
47
|
// nothing.
|
|
48
|
+
//
|
|
49
|
+
// A drag is told by the pointer moving between the press and the click,
|
|
50
|
+
// not only by the words it chose: whether a drag selects is the editor's
|
|
51
|
+
// and the browser's call (prosemirror-view 1.43, handling the mouse
|
|
52
|
+
// itself, leaves the caret where a drag with a mouse on a phone ended).
|
|
53
|
+
const presses = new WeakMap();
|
|
54
|
+
const DRAG_SLOP = 4;
|
|
55
|
+
/** Where the mouse went down in the editor: `followLink` doesn't follow a drag. */
|
|
56
|
+
export function notePress(view, event) {
|
|
57
|
+
presses.set(view, { x: event.clientX, y: event.clientY });
|
|
58
|
+
}
|
|
48
59
|
export function followLink(view, event, pages) {
|
|
49
60
|
if (event.button !== 0 || event.shiftKey || event.altKey)
|
|
50
61
|
return false;
|
|
@@ -53,6 +64,9 @@ export function followLink(view, event, pages) {
|
|
|
53
64
|
return false;
|
|
54
65
|
if (!view.state.selection.empty)
|
|
55
66
|
return false;
|
|
67
|
+
const press = presses.get(view);
|
|
68
|
+
if (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > DRAG_SLOP)
|
|
69
|
+
return false;
|
|
56
70
|
const written = anchor.getAttribute('href') ?? '';
|
|
57
71
|
const page = pageLinkInfo(pages.resolve, written);
|
|
58
72
|
if (page) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.130.
|
|
3
|
+
"version": "4.130.1",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|