docblocks-react-ui 0.17.0 → 0.18.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.
@@ -1,5 +1,5 @@
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-CbHCJZ6R.mjs";
2
- import { a as preventDefault, d as Minus, f as LoaderCircle, l as TriangleAlert, r as clamp, u as Plus } from "../constants-D8PSgkwi.mjs";
1
+ import { a as clamp, d as Plus, f as Minus, p as LoaderCircle, s as preventDefault, u as TriangleAlert } from "../constants-DWJbJpt5.mjs";
2
+ import { At as RotateCcw, Ft as Skeleton, Mt as Eye, Nt as CodeXml, O as SegmentSelector, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, nn as Button, o as childrenSlot, s as CodeHeader, u as TextBlock, y as INLINE_CODE_CLASS } from "../Editor-DQg2tfne.mjs";
3
3
  import { t as Maximize } from "../Maximize-BBHnCDWL.mjs";
4
4
  import { useEffect, useRef, useState } from "react";
5
5
  import { useTranslation } from "react-i18next";
@@ -171,20 +171,16 @@ function MermaidDiagram({ id, text }) {
171
171
  });
172
172
  }
173
173
  //#endregion
174
- //#region src/mermaid/MermaidViewport.tsx
174
+ //#region src/mermaid/mermaid-viewport-view.ts
175
+ /** The mermaid viewport's pure view math: the scale / pan bounds, the
176
+ * view's canonical forms (the restore, the rounding, the pan's clamp
177
+ * over the scaled overflow, the point-fixed zoom). */
175
178
  /** The zoom range (the min / max scale). */
176
179
  const VIEWPORT_MIN_SCALE = .25;
177
- const VIEWPORT_MAX_SCALE = 4;
178
180
  /** The toolbar's multiplicative zoom step (per in / out press). */
179
181
  const VIEWPORT_ZOOM_STEP = 1.2;
180
182
  /** The wheel's continuous zoom factor (the exponential of the delta, the canvas pinch idiom). */
181
183
  const VIEWPORT_WHEEL_ZOOM = .002;
182
- /** The view's persist debounce (the gesture's bursts stand one doc write per rest). */
183
- const VIEWPORT_PERSIST_DEBOUNCE_MS = 250;
184
- /** The height's minimum (px): the toolbar's usable area's stand (the non-CSS environment's parity). */
185
- const VIEWPORT_MIN_HEIGHT = 160;
186
- /** The resize handle's key step (px per arrow press). */
187
- const VIEWPORT_RESIZE_KEY_STEP = 16;
188
184
  /** The identity view: the diagram at its natural size, no pan. */
189
185
  const VIEWPORT_IDENTITY = {
190
186
  scale: 1,
@@ -252,17 +248,156 @@ function zoomAtPoint(view, cx, cy, nextScale) {
252
248
  y: cy - (cy - view.y) * factor
253
249
  };
254
250
  }
255
- /**
256
- * The diagram's viewport over one mermaid code block (the `nested`'s
257
- * stand — the diagram + the legacy's nested children render inside the
258
- * transform's layer). The wrapper's height stands the `height` attr
259
- * (the stretched stand; absent = the natural's auto's stand).
260
- */
261
- function MermaidViewport({ id, block, children }) {
262
- const { t } = useTranslation("blocks");
263
- const { doc, viewMode } = useEditorContext();
264
- const wrapperRef = useRef(null);
265
- const layerRef = useRef(null);
251
+ /** The resize handle's key step (px per arrow press). */
252
+ const VIEWPORT_RESIZE_KEY_STEP = 16;
253
+ function useMermaidHeight({ id, block, doc, wrapperRef }) {
254
+ const [height, setHeight] = useState(block.attrs?.height ?? null);
255
+ const heightRef = useRef(height);
256
+ heightRef.current = height;
257
+ const resizeSession = useRef(null);
258
+ /** The remote's stand over the height (the panes' shared stand over the
259
+ * wire — the adopt's parity over the embed's idiom). */
260
+ useEffect(() => {
261
+ const attrHeight = block.attrs?.height ?? null;
262
+ if (attrHeight === heightRef.current) return;
263
+ setHeight(attrHeight);
264
+ }, [block.attrs]);
265
+ const onResizePointerDown = (event) => {
266
+ if (event.button !== 0) return;
267
+ event.stopPropagation();
268
+ const wrapper = wrapperRef.current;
269
+ if (wrapper === null) return;
270
+ event.target.setPointerCapture?.(event.pointerId);
271
+ const startHeight = wrapper.getBoundingClientRect().height;
272
+ resizeSession.current = {
273
+ pointerId: event.pointerId,
274
+ startY: event.clientY,
275
+ startHeight,
276
+ lastHeight: startHeight
277
+ };
278
+ };
279
+ const onResizePointerMove = (event) => {
280
+ const session = resizeSession.current;
281
+ if (session === null || event.pointerId !== session.pointerId) return;
282
+ const next = Math.max(session.startHeight + (event.clientY - session.startY), 160);
283
+ session.lastHeight = next;
284
+ setHeight(next);
285
+ };
286
+ const endResize = (event) => {
287
+ const session = resizeSession.current;
288
+ if (session === null || event.pointerId !== session.pointerId) return;
289
+ event.target.releasePointerCapture?.(event.pointerId);
290
+ resizeSession.current = null;
291
+ const committed = Math.round(session.lastHeight);
292
+ const current = block.attrs?.height ?? null;
293
+ if (committed <= 160) {
294
+ if (current !== null) doc.updateBlock(id, { height: null });
295
+ } else if (committed !== current) doc.updateBlock(id, { height: committed });
296
+ };
297
+ const onResizeKeyDown = (event) => {
298
+ const wrapper = wrapperRef.current;
299
+ if (wrapper === null) return;
300
+ const delta = event.key === "ArrowDown" ? VIEWPORT_RESIZE_KEY_STEP : event.key === "ArrowUp" ? -16 : null;
301
+ if (delta === null) return;
302
+ event.preventDefault();
303
+ const current = Math.max(heightRef.current ?? wrapper.clientHeight, 0);
304
+ const next = Math.max(current + delta, 160);
305
+ setHeight(next <= 160 ? null : next);
306
+ const value = next <= 160 ? null : next;
307
+ if (value === (block.attrs?.height ?? null)) return;
308
+ doc.updateBlock(id, { height: value });
309
+ };
310
+ return {
311
+ height,
312
+ onResizePointerDown,
313
+ onResizePointerMove,
314
+ endResize,
315
+ onResizeKeyDown
316
+ };
317
+ }
318
+ //#endregion
319
+ //#region src/mermaid/use-mermaid-pan.ts
320
+ /** The mermaid viewport's pan: the wheel's zoom / pan (the non-passive
321
+ * listener) and the left-button's drag-pan over the diagram's area. */
322
+ function useMermaidPan({ wrapperRef, layerRef, viewRef, clampView, markExplicit, setView }) {
323
+ const panSession = useRef(null);
324
+ useEffect(() => {
325
+ const wrapper = wrapperRef.current;
326
+ if (wrapper === null) return;
327
+ const onWheel = (event) => {
328
+ const current = viewRef.current;
329
+ const rect = wrapper.getBoundingClientRect();
330
+ const cx = event.clientX - rect.left;
331
+ const cy = event.clientY - rect.top;
332
+ let next = null;
333
+ if (event.ctrlKey || event.metaKey) {
334
+ const nextScale = clamp(current.scale * Math.exp(-event.deltaY * VIEWPORT_WHEEL_ZOOM), VIEWPORT_MIN_SCALE, 4);
335
+ if (nextScale !== current.scale) next = clampView({
336
+ ...zoomAtPoint(current, cx, cy, nextScale),
337
+ scale: nextScale
338
+ });
339
+ } else {
340
+ const content = measureContent(layerRef.current);
341
+ const clamped = clampPan(current.scale, current.x, current.y - event.deltaY, rect.width, rect.height, content.w, content.h);
342
+ if (clamped.y !== current.y) next = {
343
+ ...current,
344
+ ...clamped
345
+ };
346
+ }
347
+ if (next === null) return;
348
+ event.preventDefault();
349
+ markExplicit();
350
+ setView(next);
351
+ };
352
+ wrapper.addEventListener("wheel", onWheel, { passive: false });
353
+ return () => wrapper.removeEventListener("wheel", onWheel);
354
+ }, []);
355
+ const onPointerDown = (event) => {
356
+ if (event.button !== 0) return;
357
+ const target = event.target;
358
+ if (target.closest("button") !== null || target.closest("[data-slot=\"docblocks/mermaid-resize\"]") !== null) return;
359
+ event.preventDefault();
360
+ wrapperRef.current?.setPointerCapture(event.pointerId);
361
+ panSession.current = {
362
+ pointerId: event.pointerId,
363
+ lastX: event.clientX,
364
+ lastY: event.clientY
365
+ };
366
+ };
367
+ const onPointerMove = (event) => {
368
+ const session = panSession.current;
369
+ if (session === null || event.pointerId !== session.pointerId) return;
370
+ const dx = event.clientX - session.lastX;
371
+ const dy = event.clientY - session.lastY;
372
+ session.lastX = event.clientX;
373
+ session.lastY = event.clientY;
374
+ markExplicit();
375
+ setView((v) => clampView({
376
+ scale: v.scale,
377
+ x: v.x + dx,
378
+ y: v.y + dy
379
+ }));
380
+ };
381
+ const endPan = (event) => {
382
+ const session = panSession.current;
383
+ if (session === null || event.pointerId !== session.pointerId) return;
384
+ wrapperRef.current?.releasePointerCapture(event.pointerId);
385
+ panSession.current = null;
386
+ };
387
+ return {
388
+ panSession,
389
+ onPointerDown,
390
+ onPointerMove,
391
+ endPan
392
+ };
393
+ }
394
+ //#endregion
395
+ //#region src/mermaid/use-mermaid-viewport-view.ts
396
+ /** The mermaid viewport's view state: the persisted view's restore, the
397
+ * geometry's settle (the load-time fit / the pan's re-clamp), the zoom's
398
+ * controls, and the view's persist / remote adopt (the panes' shared
399
+ * stand over the wire). */
400
+ function useMermaidViewportView({ id, block, doc, wrapperRef, layerRef }) {
266
401
  const [view, setView] = useState(() => viewOfAttrs(block.attrs?.zoom, block.attrs?.panX, block.attrs?.panY));
267
402
  const viewRef = useRef(view);
268
403
  viewRef.current = view;
@@ -273,17 +408,12 @@ function MermaidViewport({ id, block, children }) {
273
408
  explicitViewRef.current = true;
274
409
  persistGateRef.current = true;
275
410
  };
276
- const [height, setHeight] = useState(block.attrs?.height ?? null);
277
- const heightRef = useRef(height);
278
- heightRef.current = height;
279
- const panSession = useRef(null);
280
- const resizeSession = useRef(null);
281
411
  /** The fit's view over the measured's boxes (the scale's min, the no-upscale's cap, the centering). */
282
412
  const fitViewOf = () => {
283
413
  const rect = wrapperRef.current?.getBoundingClientRect();
284
414
  const content = measureContent(layerRef.current);
285
415
  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);
416
+ const scale = clamp(Math.min(rect.width / content.w, rect.height / content.h, 1), VIEWPORT_MIN_SCALE, 4);
287
417
  return {
288
418
  scale,
289
419
  x: (rect.width - content.w * scale) / 2,
@@ -331,37 +461,6 @@ function MermaidViewport({ id, block, children }) {
331
461
  observer.observe(layer);
332
462
  return () => observer.disconnect();
333
463
  }, []);
334
- useEffect(() => {
335
- const wrapper = wrapperRef.current;
336
- if (wrapper === null) return;
337
- const onWheel = (event) => {
338
- const current = viewRef.current;
339
- const rect = wrapper.getBoundingClientRect();
340
- const cx = event.clientX - rect.left;
341
- const cy = event.clientY - rect.top;
342
- let next = null;
343
- if (event.ctrlKey || event.metaKey) {
344
- const nextScale = clamp(current.scale * Math.exp(-event.deltaY * VIEWPORT_WHEEL_ZOOM), VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
345
- if (nextScale !== current.scale) next = clampView({
346
- ...zoomAtPoint(current, cx, cy, nextScale),
347
- scale: nextScale
348
- });
349
- } else {
350
- const content = measureContent(layerRef.current);
351
- const clamped = clampPan(current.scale, current.x, current.y - event.deltaY, rect.width, rect.height, content.w, content.h);
352
- if (clamped.y !== current.y) next = {
353
- ...current,
354
- ...clamped
355
- };
356
- }
357
- if (next === null) return;
358
- event.preventDefault();
359
- markExplicit();
360
- setView(next);
361
- };
362
- wrapper.addEventListener("wheel", onWheel, { passive: false });
363
- return () => wrapper.removeEventListener("wheel", onWheel);
364
- }, []);
365
464
  /** The toolbar's center-anchored zoom (the wrapper's center stands fixed). */
366
465
  const zoomBy = (step) => {
367
466
  const wrapper = wrapperRef.current;
@@ -370,7 +469,7 @@ function MermaidViewport({ id, block, children }) {
370
469
  const content = measureContent(layerRef.current);
371
470
  markExplicit();
372
471
  setView((v) => {
373
- const nextScale = clamp(v.scale * step, VIEWPORT_MIN_SCALE, VIEWPORT_MAX_SCALE);
472
+ const nextScale = clamp(v.scale * step, VIEWPORT_MIN_SCALE, 4);
374
473
  if (nextScale === v.scale) return v;
375
474
  const zoomed = zoomAtPoint(v, rect.width / 2, rect.height / 2, nextScale);
376
475
  return {
@@ -439,7 +538,7 @@ function MermaidViewport({ id, block, children }) {
439
538
  panX: x === 0 ? null : x,
440
539
  panY: y === 0 ? null : y
441
540
  });
442
- }, VIEWPORT_PERSIST_DEBOUNCE_MS);
541
+ }, 250);
443
542
  return () => window.clearTimeout(timer);
444
543
  }, [
445
544
  view,
@@ -471,97 +570,61 @@ function MermaidViewport({ id, block, children }) {
471
570
  if (persisted) explicitViewRef.current = true;
472
571
  setView(clamped);
473
572
  }, [block.attrs]);
474
- /** The remote's stand over the height (the panes' shared stand over the
475
- * wire — the adopt's parity over the embed's idiom). */
476
- useEffect(() => {
477
- const attrHeight = block.attrs?.height ?? null;
478
- if (attrHeight === heightRef.current) return;
479
- setHeight(attrHeight);
480
- }, [block.attrs]);
481
- const onPointerDown = (event) => {
482
- if (event.button !== 0) return;
483
- const target = event.target;
484
- if (target.closest("button") !== null || target.closest("[data-slot=\"docblocks/mermaid-resize\"]") !== null) return;
485
- event.preventDefault();
486
- wrapperRef.current?.setPointerCapture(event.pointerId);
487
- panSession.current = {
488
- pointerId: event.pointerId,
489
- lastX: event.clientX,
490
- lastY: event.clientY
491
- };
492
- };
493
- const onPointerMove = (event) => {
494
- const session = panSession.current;
495
- if (session === null || event.pointerId !== session.pointerId) return;
496
- const dx = event.clientX - session.lastX;
497
- const dy = event.clientY - session.lastY;
498
- session.lastX = event.clientX;
499
- session.lastY = event.clientY;
500
- markExplicit();
501
- setView((v) => clampView({
502
- scale: v.scale,
503
- x: v.x + dx,
504
- y: v.y + dy
505
- }));
506
- };
507
- const endPan = (event) => {
508
- const session = panSession.current;
509
- if (session === null || event.pointerId !== session.pointerId) return;
510
- wrapperRef.current?.releasePointerCapture(event.pointerId);
511
- panSession.current = null;
512
- };
513
- const onResizePointerDown = (event) => {
514
- if (event.button !== 0) return;
515
- event.stopPropagation();
516
- const wrapper = wrapperRef.current;
517
- if (wrapper === null) return;
518
- event.target.setPointerCapture?.(event.pointerId);
519
- const startHeight = wrapper.getBoundingClientRect().height;
520
- resizeSession.current = {
521
- pointerId: event.pointerId,
522
- startY: event.clientY,
523
- startHeight,
524
- lastHeight: startHeight
525
- };
526
- };
527
- const onResizePointerMove = (event) => {
528
- const session = resizeSession.current;
529
- if (session === null || event.pointerId !== session.pointerId) return;
530
- const next = Math.max(session.startHeight + (event.clientY - session.startY), VIEWPORT_MIN_HEIGHT);
531
- session.lastHeight = next;
532
- setHeight(next);
533
- };
534
- const endResize = (event) => {
535
- const session = resizeSession.current;
536
- if (session === null || event.pointerId !== session.pointerId) return;
537
- event.target.releasePointerCapture?.(event.pointerId);
538
- resizeSession.current = null;
539
- const committed = Math.round(session.lastHeight);
540
- const current = block.attrs?.height ?? null;
541
- if (committed <= VIEWPORT_MIN_HEIGHT) {
542
- if (current !== null) doc.updateBlock(id, { height: null });
543
- } else if (committed !== current) doc.updateBlock(id, { height: committed });
544
- };
545
- const onResizeKeyDown = (event) => {
546
- const wrapper = wrapperRef.current;
547
- if (wrapper === null) return;
548
- const delta = event.key === "ArrowDown" ? VIEWPORT_RESIZE_KEY_STEP : event.key === "ArrowUp" ? -16 : null;
549
- if (delta === null) return;
550
- event.preventDefault();
551
- const current = Math.max(heightRef.current ?? wrapper.clientHeight, 0);
552
- const next = Math.max(current + delta, VIEWPORT_MIN_HEIGHT);
553
- setHeight(next <= VIEWPORT_MIN_HEIGHT ? null : next);
554
- const value = next <= VIEWPORT_MIN_HEIGHT ? null : next;
555
- if (value === (block.attrs?.height ?? null)) return;
556
- doc.updateBlock(id, { height: value });
573
+ return {
574
+ view,
575
+ setView,
576
+ viewRef,
577
+ explicitViewRef,
578
+ markExplicit,
579
+ clampView,
580
+ fitView,
581
+ zoomIn,
582
+ zoomOut,
583
+ resetView,
584
+ atIdentity
557
585
  };
586
+ }
587
+ //#endregion
588
+ //#region src/mermaid/MermaidViewport.tsx
589
+ /**
590
+ * The diagram's viewport over one mermaid code block (the `nested`'s
591
+ * stand — the diagram + the legacy's nested children render inside the
592
+ * transform's layer). The wrapper's height stands the `height` attr
593
+ * (the stretched stand; absent = the natural's auto's stand).
594
+ */
595
+ function MermaidViewport({ id, block, children }) {
596
+ const { t } = useTranslation("blocks");
597
+ const { doc, viewMode } = useEditorContext();
598
+ const wrapperRef = useRef(null);
599
+ const layerRef = useRef(null);
600
+ const { view, setView, viewRef, markExplicit, clampView, zoomIn, zoomOut, resetView, fitView, atIdentity } = useMermaidViewportView({
601
+ id,
602
+ block,
603
+ doc,
604
+ wrapperRef,
605
+ layerRef
606
+ });
607
+ const { panSession, onPointerDown, onPointerMove, endPan } = useMermaidPan({
608
+ wrapperRef,
609
+ layerRef,
610
+ viewRef,
611
+ clampView,
612
+ markExplicit,
613
+ setView
614
+ });
615
+ const { height, onResizePointerDown, onResizePointerMove, endResize, onResizeKeyDown } = useMermaidHeight({
616
+ id,
617
+ block,
618
+ doc,
619
+ wrapperRef
620
+ });
558
621
  return /* @__PURE__ */ jsxs("div", {
559
622
  ref: wrapperRef,
560
623
  "data-slot": "docblocks/mermaid-viewport",
561
624
  contentEditable: false,
562
625
  className: "group relative mt-(--docblocks-block-spacing) w-full overflow-hidden outline-none",
563
626
  style: {
564
- ...height !== null ? { height: Math.max(height, VIEWPORT_MIN_HEIGHT) } : {},
627
+ ...height !== null ? { height: Math.max(height, 160) } : {},
565
628
  cursor: panSession.current !== null ? "grabbing" : "grab"
566
629
  },
567
630
  onPointerDown,
@@ -604,7 +667,7 @@ function MermaidViewport({ id, block, children }) {
604
667
  size: "icon",
605
668
  "aria-label": t("code.diagramZoomIn"),
606
669
  className: "size-6 cursor-default rounded-sm text-(--docblocks-text-color) disabled:opacity-50",
607
- disabled: view.scale >= VIEWPORT_MAX_SCALE,
670
+ disabled: view.scale >= 4,
608
671
  onMouseDown: preventDefault,
609
672
  onClick: zoomIn,
610
673
  children: /* @__PURE__ */ jsx(Plus, { className: "size-4" })
@@ -636,8 +699,8 @@ function MermaidViewport({ id, block, children }) {
636
699
  "data-slot": "docblocks/mermaid-resize",
637
700
  role: "slider",
638
701
  "aria-orientation": "vertical",
639
- "aria-valuemin": VIEWPORT_MIN_HEIGHT,
640
- "aria-valuenow": Math.max(height ?? wrapperRef.current?.clientHeight ?? VIEWPORT_MIN_HEIGHT, VIEWPORT_MIN_HEIGHT),
702
+ "aria-valuemin": 160,
703
+ "aria-valuenow": Math.max(height ?? wrapperRef.current?.clientHeight ?? 160, 160),
641
704
  "aria-label": t("code.diagramResizeHeight"),
642
705
  tabIndex: 0,
643
706
  className: "\n absolute inset-x-0 bottom-0 z-10 flex h-2 cursor-row-resize items-end justify-center opacity-0\n transition-opacity outline-none\n group-focus-within:opacity-100\n group-hover:opacity-100\n ",
@@ -1,4 +1,4 @@
1
- import { d as PdfPreviewProps } from "../index-C3vzW1Mv.mjs";
1
+ import { d as PdfPreviewProps } from "../index-DLLPjOP5.mjs";
2
2
  //#region src/pdf/PdfFirstPage.d.ts
3
3
  declare function PdfFirstPage({ id, blockType, url, name }: PdfPreviewProps): import("react").JSX.Element;
4
4
  //#endregion