docblocks-react-ui 0.14.0 → 0.15.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/CHANGELOG.md +56 -0
- package/dist/{Editor-DZk9LV9W.mjs → Editor-xRjCnKad.mjs} +55 -10
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/mermaid/index.mjs +61 -33
- package/dist/styles.css +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# docblocks-react-ui
|
|
2
2
|
|
|
3
|
+
## 0.15.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f91f895: A press over a non-editable island (the mention chip, an image figure, the
|
|
8
|
+
table's chrome) no longer parks the editor root's focus over the press:
|
|
9
|
+
the mousedown's default (the browser's focus's move over the shared page
|
|
10
|
+
editable + the scroll's pull to the press's point) is suppressed, and the
|
|
11
|
+
focus stands where it stood — the parked root's focus scrolled the port to
|
|
12
|
+
the editor's top over the press (the press's point moved under the pointer
|
|
13
|
+
and the island's own click's handlers — the consumer's
|
|
14
|
+
`mentionInteractions.onClick` — could lose the click). A self-contained
|
|
15
|
+
editable inside the island (a table cell's inner, the empty cell's
|
|
16
|
+
activation layer) keeps its native default.
|
|
17
|
+
|
|
18
|
+
## 0.15.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- a8559ae: The inline meta editors (the header's title, the attributes panel's rows,
|
|
23
|
+
the key's rename) follow the incoming value while the field stands: a
|
|
24
|
+
pristine field reseeds over a value change from the reader (the document's
|
|
25
|
+
write, a peer's edit, the consumer's own state) with the caret kept in
|
|
26
|
+
place, and a typed draft stands over it — the user's text is never
|
|
27
|
+
clobbered mid-edit. The commit and the Escape's cancel are unchanged.
|
|
28
|
+
- fb2eef9: The diagram preview's load-time view is the FIT: over the settled geometry
|
|
29
|
+
(the svg's async render, the page's post-mount layout) a diagram without a
|
|
30
|
+
persisted view stands whole in the frame, centered, scaled down only —
|
|
31
|
+
never up. The persisted zoom / pan is the explicit gesture's state only:
|
|
32
|
+
it is restored on reload and written back to the document on the wheel,
|
|
33
|
+
the drag-pan, the toolbar's zoom / fit / reset presses, and it is never
|
|
34
|
+
written by the load default, the peer's adopt, or the geometry's
|
|
35
|
+
re-computation. A wrapper resize re-fits the diagram while no explicit
|
|
36
|
+
view stands (and re-clamps the pan once it does).
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- 5020597: Grouping the selected canvas figures leaves their earlier containers: the
|
|
41
|
+
engine used to add the members to the new group while the old group kept
|
|
42
|
+
them, so a figure stood in two containers and both markers moved it. The
|
|
43
|
+
new group's creation and the leave are one transaction (one undo step, one
|
|
44
|
+
wire update); an earlier group left without members stands in place (the
|
|
45
|
+
empty container is a legal marker).
|
|
46
|
+
- fb02998: The cover tint's border stands the plain border until the cover's average
|
|
47
|
+
color resolves: the tint variable lands only once the blob's read and the
|
|
48
|
+
image's decode settle, and an undefined variable inside the color mix
|
|
49
|
+
invalidated the whole border-color — the dark theme flashed its near-white
|
|
50
|
+
text color as the frame's border over that window.
|
|
51
|
+
- 6d5ab1c: A press over a non-editable island inside the text (the mention chip, an
|
|
52
|
+
image figure, the table's chrome) starts no cross-drag caret session: the
|
|
53
|
+
session used to seat the selection on the island's line and focus the
|
|
54
|
+
editable with it, which pulled the scroll port to the chip and left the
|
|
55
|
+
caret away from the pressed point. A self-contained editable inside the
|
|
56
|
+
island (a table cell's inner, the empty cell's activation layer) keeps its
|
|
57
|
+
session.
|
|
58
|
+
|
|
3
59
|
## 0.14.0
|
|
4
60
|
|
|
5
61
|
### Minor Changes
|
|
@@ -7430,10 +7430,23 @@ function Input({ className, size, variant, type, ...props }) {
|
|
|
7430
7430
|
* seated at the end (no select-all) on mount, the commit on the blur /
|
|
7431
7431
|
* the Enter (one write), the Escape cancels without a write (the guard
|
|
7432
7432
|
* stops the blur's commit over the unmount).
|
|
7433
|
+
*
|
|
7434
|
+
* The seed's reseed over an open edit: the incoming value may change
|
|
7435
|
+
* while the field stands (the built-in document path — a peer's write, a
|
|
7436
|
+
* command — or the consumer's own read, e.g. the description's). A
|
|
7437
|
+
* PRISTINE field (the user has not typed away from the seed) follows the
|
|
7438
|
+
* incoming value, the caret kept in place; a typed draft stands (the
|
|
7439
|
+
* user's text is never clobbered mid-edit — the input wins until the
|
|
7440
|
+
* commit or the cancel).
|
|
7433
7441
|
*/
|
|
7434
7442
|
function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, invalid, variant, selectOnMount, onCommit, onCancel }) {
|
|
7435
7443
|
const inputRef = useRef(null);
|
|
7436
7444
|
const committedRef = useRef(false);
|
|
7445
|
+
const [value, setValue] = useState(initial);
|
|
7446
|
+
const valueRef = useRef(value);
|
|
7447
|
+
valueRef.current = value;
|
|
7448
|
+
const seedRef = useRef(initial);
|
|
7449
|
+
const caretRef = useRef(null);
|
|
7437
7450
|
const selectRef = useRef(selectOnMount);
|
|
7438
7451
|
useEffect(() => {
|
|
7439
7452
|
const input = inputRef.current;
|
|
@@ -7445,6 +7458,23 @@ function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, inv
|
|
|
7445
7458
|
}
|
|
7446
7459
|
input.setSelectionRange(input.value.length, input.value.length);
|
|
7447
7460
|
}, []);
|
|
7461
|
+
useEffect(() => {
|
|
7462
|
+
if (initial === seedRef.current) return;
|
|
7463
|
+
const previous = seedRef.current;
|
|
7464
|
+
seedRef.current = initial;
|
|
7465
|
+
if (valueRef.current !== previous) return;
|
|
7466
|
+
const input = inputRef.current;
|
|
7467
|
+
caretRef.current = input !== null && document.activeElement === input ? input.selectionStart : null;
|
|
7468
|
+
setValue(initial);
|
|
7469
|
+
}, [initial]);
|
|
7470
|
+
useLayoutEffect(() => {
|
|
7471
|
+
const caret = caretRef.current;
|
|
7472
|
+
caretRef.current = null;
|
|
7473
|
+
const input = inputRef.current;
|
|
7474
|
+
if (caret === null || input === null) return;
|
|
7475
|
+
const offset = Math.min(caret, input.value.length);
|
|
7476
|
+
input.setSelectionRange(offset, offset);
|
|
7477
|
+
}, [value]);
|
|
7448
7478
|
const commit = (value) => {
|
|
7449
7479
|
if (committedRef.current) return;
|
|
7450
7480
|
committedRef.current = true;
|
|
@@ -7470,9 +7500,12 @@ function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, inv
|
|
|
7470
7500
|
"aria-invalid": invalid ? true : void 0,
|
|
7471
7501
|
variant,
|
|
7472
7502
|
placeholder,
|
|
7473
|
-
|
|
7503
|
+
value,
|
|
7474
7504
|
className,
|
|
7475
|
-
onChange:
|
|
7505
|
+
onChange: (event) => {
|
|
7506
|
+
setValue(event.target.value);
|
|
7507
|
+
rearm();
|
|
7508
|
+
},
|
|
7476
7509
|
onBlur: onInputBlur,
|
|
7477
7510
|
onKeyDown: onInputKeyDown
|
|
7478
7511
|
});
|
|
@@ -15429,12 +15462,16 @@ function findParentSurface(doc, id) {
|
|
|
15429
15462
|
return null;
|
|
15430
15463
|
}
|
|
15431
15464
|
/**
|
|
15432
|
-
* The group creation: the selected canvas
|
|
15433
|
-
*
|
|
15434
|
-
*
|
|
15435
|
-
*
|
|
15436
|
-
*
|
|
15437
|
-
*
|
|
15465
|
+
* The group creation: the selected canvas items stand the new group's
|
|
15466
|
+
* members in ONE transact (one undo step, one wire update), and the
|
|
15467
|
+
* members leave every earlier owner — a figure stands in one container
|
|
15468
|
+
* at a time (the automatic membership's parity for the explicit
|
|
15469
|
+
* grouping; without the leave the figure would stay a member of its old
|
|
15470
|
+
* group too, and the two markers would both move it). Returns the new
|
|
15471
|
+
* group id, or null for the ineligible selection (one member, a
|
|
15472
|
+
* connector / a group in the set, a page block, or the members across
|
|
15473
|
+
* surfaces — the group is a flat marker over its siblings, never a
|
|
15474
|
+
* container). No throw: the hotkey's no-op posture.
|
|
15438
15475
|
*/
|
|
15439
15476
|
function makeGroup(doc, ids) {
|
|
15440
15477
|
if (ids.length < 2) return null;
|
|
@@ -15447,8 +15484,15 @@ function makeGroup(doc, ids) {
|
|
|
15447
15484
|
if (surface === null) surface = owner;
|
|
15448
15485
|
else if (owner !== surface) return null;
|
|
15449
15486
|
}
|
|
15487
|
+
const members = new Set(ids);
|
|
15450
15488
|
let created = null;
|
|
15451
15489
|
doc.transact(() => {
|
|
15490
|
+
for (const siblingId of doc.getChildren(surface)) {
|
|
15491
|
+
const sibling = doc.getBlock(siblingId);
|
|
15492
|
+
if (sibling === null || sibling.type !== "group") continue;
|
|
15493
|
+
const kept = sibling.attrs.members.filter((memberId) => !members.has(memberId));
|
|
15494
|
+
if (kept.length !== sibling.attrs.members.length) doc.updateBlock(siblingId, { members: kept });
|
|
15495
|
+
}
|
|
15452
15496
|
created = doc.insertBlock("group", { members: [...ids] }, { parent: surface });
|
|
15453
15497
|
});
|
|
15454
15498
|
return created;
|
|
@@ -35066,8 +35110,6 @@ function usePageMousedownGuard(rootRef, readOnly) {
|
|
|
35066
35110
|
if (active instanceof HTMLElement && (active.matches("input, textarea") || activeIsland !== null && activeEditable !== null && activeIsland.contains(activeEditable))) return;
|
|
35067
35111
|
if (island === null && editable instanceof HTMLElement && isPageSurfaceInner(editable)) return;
|
|
35068
35112
|
event.preventDefault();
|
|
35069
|
-
const a = document.activeElement;
|
|
35070
|
-
if (a === null || !root.contains(a)) root.focus();
|
|
35071
35113
|
};
|
|
35072
35114
|
window.addEventListener("mousedown", guard, true);
|
|
35073
35115
|
return () => window.removeEventListener("mousedown", guard, true);
|
|
@@ -35296,6 +35338,9 @@ function useCrossDrag(rootRef, doc, readOnly = false) {
|
|
|
35296
35338
|
const target = event.target instanceof Element ? event.target : null;
|
|
35297
35339
|
if (target?.closest("[data-slot=\"docblocks/editor\"]") !== root) return;
|
|
35298
35340
|
if (target.closest("[data-slot=\"docblocks/page-card\"]") !== null) return;
|
|
35341
|
+
const island = target.closest("[contenteditable=\"false\"]");
|
|
35342
|
+
const editable = target.closest("[contenteditable=\"true\"]");
|
|
35343
|
+
if (island !== null && (editable === null || !island.contains(editable))) return;
|
|
35299
35344
|
if (target.closest("[data-slot=\"docblocks/block-content\"]") === null) return;
|
|
35300
35345
|
const anchor = positionAtPoint(doc, root, event.clientX, event.clientY);
|
|
35301
35346
|
if (anchor === null) return;
|
package/dist/index.d.mts
CHANGED
|
@@ -356,7 +356,7 @@ declare function AlertDescription({ className, ...props }: React$1.ComponentProp
|
|
|
356
356
|
//#endregion
|
|
357
357
|
//#region src/shared/ui/Badge.d.ts
|
|
358
358
|
declare const badgeVariants: (props?: ({
|
|
359
|
-
variant?: "default" | "
|
|
359
|
+
variant?: "default" | "destructive" | "outline" | "secondary" | "custom" | null | undefined;
|
|
360
360
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
361
361
|
declare function Badge({ className, variant, asChild, ...props }: React$1.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
|
|
362
362
|
asChild?: boolean;
|
|
@@ -367,7 +367,7 @@ declare function BareSelect({ className, children, ...props }: React$1.Component
|
|
|
367
367
|
//#endregion
|
|
368
368
|
//#region src/shared/ui/Button.d.ts
|
|
369
369
|
declare const buttonVariants: (props?: ({
|
|
370
|
-
variant?: "link" | "default" | "
|
|
370
|
+
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
|
|
371
371
|
size?: "default" | "icon" | "sm" | "lg" | "xl" | null | undefined;
|
|
372
372
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
373
373
|
declare function Button({ className, variant, size, asChild, type, ...props }: React$1.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as DropdownMenuSubContent, $t as Eye, A as SelectGroup, At as Skeleton, B as Input, Bt as useBlock, C as FilterBuilder, Ct as isBridgeError, D as ScrollArea, Dt as parseCellValue, E as SegmentSelector, Et as conditionMatches, F as SelectSeparator, Ft as CardFooter, G as DropdownMenuItem, Gt as useSelection, H as DropdownMenuCheckboxItem, Ht as useMeta, I as SelectTrigger, It as CardHeader, J as DropdownMenuRadioGroup, Jt as DocblocksI18nProvider, K as DropdownMenuLabel, Kt as useSelectionView, L as SelectValue, Lt as CardTitle, M as SelectLabel, Mt as CardAction, N as SelectScrollDownButton, Nt as CardContent, O as Select, Ot as TEXT_TYPES, P as SelectScrollUpButton, Pt as CardDescription, Q as DropdownMenuSub, Qt as Pen, R as Label, Rt as Badge, S as newMutationContext, St as BridgeError, T as filterIsComplete, Tt as toBridgeError, U as DropdownMenuContent, Ut as usePresence, V as DropdownMenu, Vt as useDoc, W as DropdownMenuGroup, Wt as usePresenceSharing, X as DropdownMenuSeparator, Xt as renderRuns, Y as DropdownMenuRadioItem, Z as DropdownMenuShortcut, _ as mapFrontmatter, _t as BASELINE_CAPABILITIES, a as DEFAULT_EMBED_SANDBOX, at as PopoverContent, b as useDatabaseTable, bt as validateProtocolDescriptor, c as SHAPE_FONT_OPTIONS, ct as PopoverTitle, d as FORMAT_PALETTE, dt as Button, et as DropdownMenuSubTrigger, ft as buttonVariants, g as mdToBlocks, gt as AlertTitle, h as insertNative, ht as AlertDescription, i as useEditorContext, it as PopoverAnchor, j as SelectItem, jt as Card, k as SelectContent, kt as columnAnnotation, l as SHAPE_FONT_STACKS, lt as PopoverTrigger, m as htmlToBlocks, mt as Alert, n as useCoverAverageColor, nn as createMemoryBlobStore, nt as Separator, ot as PopoverDescription, p as markToggleAction, pt as BareSelect, q as DropdownMenuPortal, qt as useText, r as EditorProvider, rt as Popover, st as PopoverHeader, t as Editor, tn as BookOpen, tt as DropdownMenuTrigger, ut as Checkbox, v as parseFrontmatter, vt as PROTOCOL_VERSION, w as emptyFilter, wt as isBridgeErrorCode, x as cellValueEqual, xt as BRIDGE_ERROR_CODES, y as GridBody, yt as isDatabaseBridge, z as InlineEditInput, zt as badgeVariants } from "./Editor-
|
|
1
|
+
import { $ as DropdownMenuSubContent, $t as Eye, A as SelectGroup, At as Skeleton, B as Input, Bt as useBlock, C as FilterBuilder, Ct as isBridgeError, D as ScrollArea, Dt as parseCellValue, E as SegmentSelector, Et as conditionMatches, F as SelectSeparator, Ft as CardFooter, G as DropdownMenuItem, Gt as useSelection, H as DropdownMenuCheckboxItem, Ht as useMeta, I as SelectTrigger, It as CardHeader, J as DropdownMenuRadioGroup, Jt as DocblocksI18nProvider, K as DropdownMenuLabel, Kt as useSelectionView, L as SelectValue, Lt as CardTitle, M as SelectLabel, Mt as CardAction, N as SelectScrollDownButton, Nt as CardContent, O as Select, Ot as TEXT_TYPES, P as SelectScrollUpButton, Pt as CardDescription, Q as DropdownMenuSub, Qt as Pen, R as Label, Rt as Badge, S as newMutationContext, St as BridgeError, T as filterIsComplete, Tt as toBridgeError, U as DropdownMenuContent, Ut as usePresence, V as DropdownMenu, Vt as useDoc, W as DropdownMenuGroup, Wt as usePresenceSharing, X as DropdownMenuSeparator, Xt as renderRuns, Y as DropdownMenuRadioItem, Z as DropdownMenuShortcut, _ as mapFrontmatter, _t as BASELINE_CAPABILITIES, a as DEFAULT_EMBED_SANDBOX, at as PopoverContent, b as useDatabaseTable, bt as validateProtocolDescriptor, c as SHAPE_FONT_OPTIONS, ct as PopoverTitle, d as FORMAT_PALETTE, dt as Button, et as DropdownMenuSubTrigger, ft as buttonVariants, g as mdToBlocks, gt as AlertTitle, h as insertNative, ht as AlertDescription, i as useEditorContext, it as PopoverAnchor, j as SelectItem, jt as Card, k as SelectContent, kt as columnAnnotation, l as SHAPE_FONT_STACKS, lt as PopoverTrigger, m as htmlToBlocks, mt as Alert, n as useCoverAverageColor, nn as createMemoryBlobStore, nt as Separator, ot as PopoverDescription, p as markToggleAction, pt as BareSelect, q as DropdownMenuPortal, qt as useText, r as EditorProvider, rt as Popover, st as PopoverHeader, t as Editor, tn as BookOpen, tt as DropdownMenuTrigger, ut as Checkbox, v as parseFrontmatter, vt as PROTOCOL_VERSION, w as emptyFilter, wt as isBridgeErrorCode, x as cellValueEqual, xt as BRIDGE_ERROR_CODES, y as GridBody, yt as isDatabaseBridge, z as InlineEditInput, zt as badgeVariants } from "./Editor-xRjCnKad.mjs";
|
|
2
2
|
import { a as preventDefault, s as cn } from "./constants-D8PSgkwi.mjs";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useTranslation } from "react-i18next";
|
package/dist/mermaid/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as Eye, At as Skeleton, E as SegmentSelector, Yt as INLINE_CODE_CLASS, Zt as RotateCcw, dt as Button, en as CodeXml, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, o as childrenSlot, s as CodeHeader, u as TextBlock } from "../Editor-
|
|
1
|
+
import { $t as Eye, At as Skeleton, E as SegmentSelector, Yt as INLINE_CODE_CLASS, Zt as RotateCcw, dt as Button, en as CodeXml, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, o as childrenSlot, s as CodeHeader, u as TextBlock } from "../Editor-xRjCnKad.mjs";
|
|
2
2
|
import { a as preventDefault, d as Minus, f as LoaderCircle, l as TriangleAlert, r as clamp, u as Plus } from "../constants-D8PSgkwi.mjs";
|
|
3
3
|
import { t as Maximize } from "../Maximize-BBHnCDWL.mjs";
|
|
4
4
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -266,11 +266,30 @@ function MermaidViewport({ id, block, children }) {
|
|
|
266
266
|
const [view, setView] = useState(() => viewOfAttrs(block.attrs?.zoom, block.attrs?.panX, block.attrs?.panY));
|
|
267
267
|
const viewRef = useRef(view);
|
|
268
268
|
viewRef.current = view;
|
|
269
|
+
const explicitViewRef = useRef(block.attrs?.zoom != null || block.attrs?.panX != null || block.attrs?.panY != null);
|
|
270
|
+
const persistGateRef = useRef(false);
|
|
271
|
+
/** The explicit gesture's stand: the view is the user's (the load-time fit stops re-applying) and the write-back opens. */
|
|
272
|
+
const markExplicit = () => {
|
|
273
|
+
explicitViewRef.current = true;
|
|
274
|
+
persistGateRef.current = true;
|
|
275
|
+
};
|
|
269
276
|
const [height, setHeight] = useState(block.attrs?.height ?? null);
|
|
270
277
|
const heightRef = useRef(height);
|
|
271
278
|
heightRef.current = height;
|
|
272
279
|
const panSession = useRef(null);
|
|
273
280
|
const resizeSession = useRef(null);
|
|
281
|
+
/** The fit's view over the measured's boxes (the scale's min, the no-upscale's cap, the centering). */
|
|
282
|
+
const fitViewOf = () => {
|
|
283
|
+
const rect = wrapperRef.current?.getBoundingClientRect();
|
|
284
|
+
const content = measureContent(layerRef.current);
|
|
285
|
+
if (rect === void 0 || rect.width <= 0 || rect.height <= 0 || content.w <= 0 || content.h <= 0) return null;
|
|
286
|
+
const scale = clamp(Math.min(rect.width / content.w, rect.height / content.h, 1), VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
|
|
287
|
+
return {
|
|
288
|
+
scale,
|
|
289
|
+
x: (rect.width - content.w * scale) / 2,
|
|
290
|
+
y: (rect.height - content.h * scale) / 2
|
|
291
|
+
};
|
|
292
|
+
};
|
|
274
293
|
/** The clamped view over the measured's boxes (the gesture's helper). */
|
|
275
294
|
const clampView = (next) => {
|
|
276
295
|
const rect = wrapperRef.current?.getBoundingClientRect();
|
|
@@ -281,29 +300,33 @@ function MermaidViewport({ id, block, children }) {
|
|
|
281
300
|
};
|
|
282
301
|
};
|
|
283
302
|
/**
|
|
284
|
-
* The geometry's
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
303
|
+
* The geometry's stand: the mount's wrapper / layer boxes are not final
|
|
304
|
+
* (the page's layout settles post-mount) and the diagram's svg lands
|
|
305
|
+
* AFTER the mount (mermaid renders async), so the mount-time measure
|
|
306
|
+
* reads the loading skeleton's box. Over the settled boxes:
|
|
307
|
+
* - no explicit view yet (nothing persisted, no gesture): the load-time
|
|
308
|
+
* default stands — the FIT (the whole diagram in the frame, centered,
|
|
309
|
+
* capped at 100%);
|
|
310
|
+
* - an explicit view stands (the reload's restore, a gesture, a peer's
|
|
311
|
+
* write): the pan re-clamps into the box (the view never lands
|
|
312
|
+
* unclamped).
|
|
313
|
+
* The observer stands both when the boxes change (the svg's appearance,
|
|
314
|
+
* the consumer's re-layout) and on its initial observe; none of it
|
|
315
|
+
* touches the wire (see the persist gate).
|
|
294
316
|
*/
|
|
295
317
|
useEffect(() => {
|
|
296
318
|
const wrapper = wrapperRef.current;
|
|
297
319
|
const layer = layerRef.current;
|
|
298
320
|
if (wrapper === null || layer === null) return;
|
|
299
321
|
if (typeof ResizeObserver === "undefined") return;
|
|
300
|
-
const
|
|
322
|
+
const settle = () => {
|
|
301
323
|
const current = viewRef.current;
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
|
|
324
|
+
const next = explicitViewRef.current ? clampView(current) : fitViewOf();
|
|
325
|
+
if (next === null) return;
|
|
326
|
+
if (next.scale === current.scale && next.x === current.x && next.y === current.y) return;
|
|
327
|
+
setView(next);
|
|
305
328
|
};
|
|
306
|
-
const observer = new ResizeObserver(
|
|
329
|
+
const observer = new ResizeObserver(settle);
|
|
307
330
|
observer.observe(wrapper);
|
|
308
331
|
observer.observe(layer);
|
|
309
332
|
return () => observer.disconnect();
|
|
@@ -333,6 +356,7 @@ function MermaidViewport({ id, block, children }) {
|
|
|
333
356
|
}
|
|
334
357
|
if (next === null) return;
|
|
335
358
|
event.preventDefault();
|
|
359
|
+
markExplicit();
|
|
336
360
|
setView(next);
|
|
337
361
|
};
|
|
338
362
|
wrapper.addEventListener("wheel", onWheel, { passive: false });
|
|
@@ -344,6 +368,7 @@ function MermaidViewport({ id, block, children }) {
|
|
|
344
368
|
if (wrapper === null) return;
|
|
345
369
|
const rect = wrapper.getBoundingClientRect();
|
|
346
370
|
const content = measureContent(layerRef.current);
|
|
371
|
+
markExplicit();
|
|
347
372
|
setView((v) => {
|
|
348
373
|
const nextScale = clamp(v.scale * step, VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
|
|
349
374
|
if (nextScale === v.scale) return v;
|
|
@@ -356,7 +381,10 @@ function MermaidViewport({ id, block, children }) {
|
|
|
356
381
|
};
|
|
357
382
|
const zoomIn = () => zoomBy(VIEWPORT_ZOOM_STEP);
|
|
358
383
|
const zoomOut = () => zoomBy(1 / VIEWPORT_ZOOM_STEP);
|
|
359
|
-
const resetView = () =>
|
|
384
|
+
const resetView = () => {
|
|
385
|
+
markExplicit();
|
|
386
|
+
setView(clampView(VIEWPORT_IDENTITY));
|
|
387
|
+
};
|
|
360
388
|
const atIdentity = (() => {
|
|
361
389
|
const rect = wrapperRef.current?.getBoundingClientRect();
|
|
362
390
|
const content = measureContent(layerRef.current);
|
|
@@ -364,24 +392,19 @@ function MermaidViewport({ id, block, children }) {
|
|
|
364
392
|
return view.scale === VIEWPORT_IDENTITY.scale && view.x === clamped.x && view.y === clamped.y;
|
|
365
393
|
})();
|
|
366
394
|
/**
|
|
367
|
-
* The fit's stand (the default's restore for
|
|
368
|
-
* scale's min over the width / height's ratio,
|
|
369
|
-
* diagram's stand the natural's size — no
|
|
370
|
-
* visible viewport's box (the clipped
|
|
371
|
-
* stand (the error / loading's
|
|
395
|
+
* The fit's stand (the load-time default and the toolbar's restore for
|
|
396
|
+
* the large diagram): the scale's min over the width / height's ratio,
|
|
397
|
+
* capped at 1 (the small diagram's stand the natural's size — no
|
|
398
|
+
* upscaling), centered over the visible viewport's box (the clipped
|
|
399
|
+
* stand included). The no-content's stand (the error / loading's
|
|
400
|
+
* states): the no-op. The button's press stands the explicit view (the
|
|
401
|
+
* persisted write follows).
|
|
372
402
|
*/
|
|
373
403
|
const fitView = () => {
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if (rect.width <= 0 || rect.height <= 0 || content.w <= 0 || content.h <= 0) return;
|
|
379
|
-
const scale = clamp(Math.min(rect.width / content.w, rect.height / content.h, 1), VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
|
|
380
|
-
setView({
|
|
381
|
-
scale,
|
|
382
|
-
x: (rect.width - content.w * scale) / 2,
|
|
383
|
-
y: (rect.height - content.h * scale) / 2
|
|
384
|
-
});
|
|
404
|
+
const next = fitViewOf();
|
|
405
|
+
if (next === null) return;
|
|
406
|
+
markExplicit();
|
|
407
|
+
setView(next);
|
|
385
408
|
};
|
|
386
409
|
/**
|
|
387
410
|
* The persisted view's write (the debounce over the gesture's bursts):
|
|
@@ -397,6 +420,8 @@ function MermaidViewport({ id, block, children }) {
|
|
|
397
420
|
* no wire update).
|
|
398
421
|
*/
|
|
399
422
|
useEffect(() => {
|
|
423
|
+
if (!persistGateRef.current) return;
|
|
424
|
+
persistGateRef.current = false;
|
|
400
425
|
const clamped = clampView(view);
|
|
401
426
|
const zoom = roundViewValue(clamped.scale, 2);
|
|
402
427
|
const x = roundViewValue(clamped.x, 1);
|
|
@@ -439,9 +464,11 @@ function MermaidViewport({ id, block, children }) {
|
|
|
439
464
|
x: block.attrs?.panX ?? 0,
|
|
440
465
|
y: block.attrs?.panY ?? 0
|
|
441
466
|
};
|
|
467
|
+
const persisted = block.attrs?.zoom != null || block.attrs?.panX != null || block.attrs?.panY != null;
|
|
442
468
|
const clamped = clampView(target);
|
|
443
469
|
const v = viewRef.current;
|
|
444
470
|
if (clamped.scale === v.scale && clamped.x === v.x && clamped.y === v.y) return;
|
|
471
|
+
if (persisted) explicitViewRef.current = true;
|
|
445
472
|
setView(clamped);
|
|
446
473
|
}, [block.attrs]);
|
|
447
474
|
/** The remote's stand over the height (the panes' shared stand over the
|
|
@@ -470,6 +497,7 @@ function MermaidViewport({ id, block, children }) {
|
|
|
470
497
|
const dy = event.clientY - session.lastY;
|
|
471
498
|
session.lastX = event.clientX;
|
|
472
499
|
session.lastY = event.clientY;
|
|
500
|
+
markExplicit();
|
|
473
501
|
setView((v) => clampView({
|
|
474
502
|
scale: v.scale,
|
|
475
503
|
x: v.x + dx,
|
package/dist/styles.css
CHANGED
|
@@ -4233,7 +4233,12 @@
|
|
|
4233
4233
|
* so the theme's flip re-mixes over the same value without a re-read.
|
|
4234
4234
|
*/
|
|
4235
4235
|
[data-slot="card"][data-cover-tint] {
|
|
4236
|
-
|
|
4236
|
+
/* The tint variable lands only once the cover's average color resolves
|
|
4237
|
+
(the blob's read + the image's decode): until then the fallback
|
|
4238
|
+
resolves to the plain border — an undefined variable inside the mix
|
|
4239
|
+
would make the whole border-color invalid and fall back to the text
|
|
4240
|
+
color (a near-white flash over the dark theme). */
|
|
4241
|
+
border-color: color-mix(in srgb, var(--docblocks-cover-tint-color, var(--border)) 25%, var(--border));
|
|
4237
4242
|
}
|
|
4238
4243
|
|
|
4239
4244
|
/* 5. The shape-text's self-hosted fonts (the woff2 in dist/fonts/; the
|
package/package.json
CHANGED