docblocks-react-ui 0.29.2 → 0.31.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/CHANGELOG.md +80 -0
- package/README.md +14 -0
- package/dist/{Editor-y3dFOZE4.mjs → Editor-CAU0NkdR.mjs} +976 -197
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/mermaid/index.mjs +1 -1
- package/dist/styles.css +20 -9
- package/package.json +2 -2
|
@@ -347,6 +347,8 @@ const INIT_OPTIONS = {
|
|
|
347
347
|
"straight": "Straight line",
|
|
348
348
|
"orthogonal": "Orthogonal line",
|
|
349
349
|
"curved": "Curved line",
|
|
350
|
+
"bend": "Add bend point",
|
|
351
|
+
"bendTitle": "Add a bend point (drag it to bend the line; double-click it to remove)",
|
|
350
352
|
"lineColor": "Line color",
|
|
351
353
|
"lineWidth": "Line width",
|
|
352
354
|
"lineWidthTitle": "Line width (1–4 px)",
|
|
@@ -942,6 +944,8 @@ const INIT_OPTIONS = {
|
|
|
942
944
|
"straight": "Прямая линия",
|
|
943
945
|
"orthogonal": "Ортогональная линия",
|
|
944
946
|
"curved": "Кривая линия",
|
|
947
|
+
"bend": "Добавить точку изгиба",
|
|
948
|
+
"bendTitle": "Добавить точку изгиба (перетащите её, чтобы согнуть линию; двойной клик удаляет)",
|
|
945
949
|
"lineColor": "Цвет линии",
|
|
946
950
|
"lineWidth": "Толщина линии",
|
|
947
951
|
"lineWidthTitle": "Толщина линии (1–4 px)",
|
|
@@ -3647,6 +3651,34 @@ function User(props) {
|
|
|
3647
3651
|
})]
|
|
3648
3652
|
});
|
|
3649
3653
|
}
|
|
3654
|
+
// src/shared/ui/icons/Waypoints.tsx
|
|
3655
|
+
function Waypoints(props) {
|
|
3656
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
3657
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3658
|
+
width: 24,
|
|
3659
|
+
height: 24,
|
|
3660
|
+
viewBox: "0 0 24 24",
|
|
3661
|
+
fill: "none",
|
|
3662
|
+
stroke: "currentColor",
|
|
3663
|
+
strokeWidth: 2,
|
|
3664
|
+
strokeLinecap: "round",
|
|
3665
|
+
strokeLinejoin: "round",
|
|
3666
|
+
...props,
|
|
3667
|
+
children: [
|
|
3668
|
+
/* @__PURE__ */ jsx("path", { d: "M4 20h4l4-8 4-8h4" }),
|
|
3669
|
+
/* @__PURE__ */ jsx("circle", {
|
|
3670
|
+
cx: "4",
|
|
3671
|
+
cy: "20",
|
|
3672
|
+
r: "2"
|
|
3673
|
+
}),
|
|
3674
|
+
/* @__PURE__ */ jsx("circle", {
|
|
3675
|
+
cx: "20",
|
|
3676
|
+
cy: "4",
|
|
3677
|
+
r: "2"
|
|
3678
|
+
})
|
|
3679
|
+
]
|
|
3680
|
+
});
|
|
3681
|
+
}
|
|
3650
3682
|
// src/shared/ui/icons/Zap.tsx
|
|
3651
3683
|
function Zap(props) {
|
|
3652
3684
|
return /* @__PURE__ */ jsx("svg", {
|
|
@@ -15424,6 +15456,30 @@ function connectorMidpoint(connectorId, childIds, blocks, previews) {
|
|
|
15424
15456
|
}
|
|
15425
15457
|
return connectorPathPoints(startDraw, endDraw, attrs.variant ?? "straight", obstacleBoxes).mid;
|
|
15426
15458
|
}
|
|
15459
|
+
/**
|
|
15460
|
+
* The connector's STORED waypoints (the bend dots' stand): the attrs'
|
|
15461
|
+
* `points` in the route's own order, the in-flight waypoint drag's point
|
|
15462
|
+
* substituted at its index (the dot follows the handle — the release
|
|
15463
|
+
* commits the same position). The surface-local px (the line's own space).
|
|
15464
|
+
*/
|
|
15465
|
+
function connectorWaypointPoints(block, previews) {
|
|
15466
|
+
if (block === void 0 || block.type !== "connector" || block.attrs === void 0) return [];
|
|
15467
|
+
const drag = previews?.endpointDrag ?? null;
|
|
15468
|
+
const preview = previews?.endpointPreview ?? null;
|
|
15469
|
+
if (drag === null || drag.which !== "waypoint" || preview === null || drag.index === void 0) return (block.attrs.points ?? []).map(([x, y]) => ({
|
|
15470
|
+
x,
|
|
15471
|
+
y
|
|
15472
|
+
}));
|
|
15473
|
+
const index = drag.index;
|
|
15474
|
+
const live = preview.point;
|
|
15475
|
+
return (block.attrs.points ?? []).map(([x, y], i) => i === index ? {
|
|
15476
|
+
x: live.x,
|
|
15477
|
+
y: live.y
|
|
15478
|
+
} : {
|
|
15479
|
+
x,
|
|
15480
|
+
y
|
|
15481
|
+
});
|
|
15482
|
+
}
|
|
15427
15483
|
// src/canvas/geometry/utils/frame-window.ts
|
|
15428
15484
|
/**
|
|
15429
15485
|
* The window's offset: the box-local position of the surface's world
|
|
@@ -16632,6 +16688,159 @@ function createShapeSessions(store, doc) {
|
|
|
16632
16688
|
cancelResize
|
|
16633
16689
|
};
|
|
16634
16690
|
}
|
|
16691
|
+
// src/canvas/viewport/session-waypoint.ts
|
|
16692
|
+
/** The round point (the 2-decimal stand — the endpoints' own). */
|
|
16693
|
+
function rounded(point) {
|
|
16694
|
+
return [Number(point.x.toFixed(2)), Number(point.y.toFixed(2))];
|
|
16695
|
+
}
|
|
16696
|
+
/** The connector's session commands (the route's write / the drag / the
|
|
16697
|
+
* midpoint's add / the point's removal). */
|
|
16698
|
+
function createWaypointSessions(store, doc) {
|
|
16699
|
+
const waypointRef = { current: null };
|
|
16700
|
+
/** The connector's stored waypoints (the surface-local px). */
|
|
16701
|
+
const pointsOf = (connectorId) => {
|
|
16702
|
+
const block = doc.getBlock(connectorId);
|
|
16703
|
+
if (block === null || block.type !== "connector") return [];
|
|
16704
|
+
return (block.attrs?.points ?? []).map(([x, y]) => [x, y]);
|
|
16705
|
+
};
|
|
16706
|
+
const writePoints = (connectorId, points) => {
|
|
16707
|
+
const block = doc.getBlock(connectorId);
|
|
16708
|
+
if (block === null || block.type !== "connector") return;
|
|
16709
|
+
try {
|
|
16710
|
+
doc.transact(() => {
|
|
16711
|
+
if (points.length === 0) doc.removeBlockAttr(connectorId, "points");
|
|
16712
|
+
else doc.updateBlock(connectorId, { points });
|
|
16713
|
+
});
|
|
16714
|
+
} catch {}
|
|
16715
|
+
};
|
|
16716
|
+
const beginConnectorWaypoint = (connectorId, index, pointer, startClientX, startClientY) => {
|
|
16717
|
+
const state = store.getState();
|
|
16718
|
+
const block = doc.getBlock(connectorId);
|
|
16719
|
+
if (block === null || block.type !== "connector") return;
|
|
16720
|
+
const stored = pointsOf(connectorId)[index];
|
|
16721
|
+
if (stored === void 0) return;
|
|
16722
|
+
const canvas = screenToCanvas(pointer, state.zoom, state.pan);
|
|
16723
|
+
waypointRef.current = {
|
|
16724
|
+
connectorId,
|
|
16725
|
+
index,
|
|
16726
|
+
startClientX,
|
|
16727
|
+
startClientY,
|
|
16728
|
+
dragging: false,
|
|
16729
|
+
point: canvas
|
|
16730
|
+
};
|
|
16731
|
+
state.setConnectorEndpoint({
|
|
16732
|
+
connectorId,
|
|
16733
|
+
which: "waypoint",
|
|
16734
|
+
index
|
|
16735
|
+
});
|
|
16736
|
+
state.setConnectorEndpointPreview({
|
|
16737
|
+
point: {
|
|
16738
|
+
x: stored[0],
|
|
16739
|
+
y: stored[1]
|
|
16740
|
+
},
|
|
16741
|
+
snap: null
|
|
16742
|
+
});
|
|
16743
|
+
};
|
|
16744
|
+
const moveConnectorWaypoint = (pointer) => {
|
|
16745
|
+
const session = waypointRef.current;
|
|
16746
|
+
if (session === null) return;
|
|
16747
|
+
const state = store.getState();
|
|
16748
|
+
session.dragging = true;
|
|
16749
|
+
const point = screenToCanvas(pointer, state.zoom, state.pan);
|
|
16750
|
+
session.point = point;
|
|
16751
|
+
state.setConnectorEndpointPreview({
|
|
16752
|
+
point,
|
|
16753
|
+
snap: null
|
|
16754
|
+
});
|
|
16755
|
+
};
|
|
16756
|
+
const endConnectorWaypoint = (releaseClientX, releaseClientY) => {
|
|
16757
|
+
const session = waypointRef.current;
|
|
16758
|
+
waypointRef.current = null;
|
|
16759
|
+
const state = store.getState();
|
|
16760
|
+
state.setConnectorEndpoint(null);
|
|
16761
|
+
state.setConnectorEndpointPreview(null);
|
|
16762
|
+
if (session === null || !session.dragging) return;
|
|
16763
|
+
if (releaseClientX !== void 0 && releaseClientY !== void 0 && Math.hypot(releaseClientX - session.startClientX, releaseClientY - session.startClientY) < 3) return;
|
|
16764
|
+
const points = pointsOf(session.connectorId);
|
|
16765
|
+
if (points[session.index] === void 0) return;
|
|
16766
|
+
points[session.index] = rounded(session.point);
|
|
16767
|
+
writePoints(session.connectorId, points);
|
|
16768
|
+
};
|
|
16769
|
+
const cancelConnectorWaypoint = () => {
|
|
16770
|
+
waypointRef.current = null;
|
|
16771
|
+
const state = store.getState();
|
|
16772
|
+
state.setConnectorEndpoint(null);
|
|
16773
|
+
state.setConnectorEndpointPreview(null);
|
|
16774
|
+
};
|
|
16775
|
+
/**
|
|
16776
|
+
* Adds a waypoint at the ROUTE's middle segment's midpoint: the polyline
|
|
16777
|
+
* through the resolved endpoints and the stored waypoints (the geometry's
|
|
16778
|
+
* own route), the longest-middle segment's middle point (the odd count
|
|
16779
|
+
* stands the exact middle, the even count the later's one). The new point
|
|
16780
|
+
* lands between that segment's ends (the route's order).
|
|
16781
|
+
*/
|
|
16782
|
+
const addConnectorWaypoint = (connectorId) => {
|
|
16783
|
+
const block = doc.getBlock(connectorId);
|
|
16784
|
+
if (block === null || block.type !== "connector" || block.attrs === void 0) return;
|
|
16785
|
+
const surfaceId = findParentSurface(doc, connectorId);
|
|
16786
|
+
if (surfaceId === null) return;
|
|
16787
|
+
const children = doc.getChildren(surfaceId);
|
|
16788
|
+
const blocks = {};
|
|
16789
|
+
for (const childId of children) {
|
|
16790
|
+
const child = doc.getBlock(childId);
|
|
16791
|
+
if (child !== null) blocks[childId] = child;
|
|
16792
|
+
}
|
|
16793
|
+
const attrs = block.attrs;
|
|
16794
|
+
const start = endpointPointOf(attrs.start, children, blocks, {
|
|
16795
|
+
x: 0,
|
|
16796
|
+
y: 0
|
|
16797
|
+
});
|
|
16798
|
+
const end = start !== null ? endpointPointOf(attrs.end, children, blocks, {
|
|
16799
|
+
x: start.x,
|
|
16800
|
+
y: start.y
|
|
16801
|
+
}) : null;
|
|
16802
|
+
if (start === null || end === null) return;
|
|
16803
|
+
const points = pointsOf(connectorId);
|
|
16804
|
+
const route = [
|
|
16805
|
+
{
|
|
16806
|
+
x: start.x,
|
|
16807
|
+
y: start.y
|
|
16808
|
+
},
|
|
16809
|
+
...points.map(([x, y]) => ({
|
|
16810
|
+
x,
|
|
16811
|
+
y
|
|
16812
|
+
})),
|
|
16813
|
+
{
|
|
16814
|
+
x: end.x,
|
|
16815
|
+
y: end.y
|
|
16816
|
+
}
|
|
16817
|
+
];
|
|
16818
|
+
const segment = Math.floor((route.length - 1) / 2);
|
|
16819
|
+
const from = route[segment];
|
|
16820
|
+
const to = route[segment + 1];
|
|
16821
|
+
if (from === void 0 || to === void 0) return;
|
|
16822
|
+
const middle = {
|
|
16823
|
+
x: (from.x + to.x) / 2,
|
|
16824
|
+
y: (from.y + to.y) / 2
|
|
16825
|
+
};
|
|
16826
|
+
points.splice(segment, 0, rounded(middle));
|
|
16827
|
+
writePoints(connectorId, points);
|
|
16828
|
+
};
|
|
16829
|
+
const removeConnectorWaypoint = (connectorId, index) => {
|
|
16830
|
+
const points = pointsOf(connectorId);
|
|
16831
|
+
if (points[index] === void 0) return;
|
|
16832
|
+
points.splice(index, 1);
|
|
16833
|
+
writePoints(connectorId, points);
|
|
16834
|
+
};
|
|
16835
|
+
return {
|
|
16836
|
+
beginConnectorWaypoint,
|
|
16837
|
+
moveConnectorWaypoint,
|
|
16838
|
+
endConnectorWaypoint,
|
|
16839
|
+
cancelConnectorWaypoint,
|
|
16840
|
+
addConnectorWaypoint,
|
|
16841
|
+
removeConnectorWaypoint
|
|
16842
|
+
};
|
|
16843
|
+
}
|
|
16635
16844
|
// src/canvas/viewport/zoom.ts
|
|
16636
16845
|
/**
|
|
16637
16846
|
* The canvas viewport's zoom math: the stop grid's nearest-stop index, the
|
|
@@ -16710,6 +16919,7 @@ function createCanvasViewportCommands(store, doc) {
|
|
|
16710
16919
|
return {
|
|
16711
16920
|
...createShapeSessions(store, doc),
|
|
16712
16921
|
...createConnectorSessions(store, doc, standPoint),
|
|
16922
|
+
...createWaypointSessions(store, doc),
|
|
16713
16923
|
...createPlaceCommands(store, doc),
|
|
16714
16924
|
stepZoom: step,
|
|
16715
16925
|
zoomAt,
|
|
@@ -19993,6 +20203,36 @@ function useMentionMenu(rootRef) {
|
|
|
19993
20203
|
}
|
|
19994
20204
|
// src/editing/page-surface-dom.ts
|
|
19995
20205
|
/**
|
|
20206
|
+
* Materializes the empty page's first paragraph (the empty page's input
|
|
20207
|
+
* stand — the full document's edit mode): while the root holds no blocks,
|
|
20208
|
+
* stands a fresh first paragraph with `content` (one undo step, one wire
|
|
20209
|
+
* update) and seats the caret at its end on the next frame. A concurrently
|
|
20210
|
+
* stood block (a peer's first gesture) stands nothing. Returns the
|
|
20211
|
+
* materialized block's id, or null when the page is not empty.
|
|
20212
|
+
*
|
|
20213
|
+
* The fresh id (not the reserved `${docId}-tail`): the reserved id is the
|
|
20214
|
+
* trailing-paragraph guarantee's own stand — consuming it here would leave a
|
|
20215
|
+
* later non-text tail without its editable paragraph (the guarantee is a
|
|
20216
|
+
* no-op once the reserved block stands).
|
|
20217
|
+
*/
|
|
20218
|
+
function materializeEmptyPageParagraph(doc, scope, content) {
|
|
20219
|
+
const rootId = doc.meta.id;
|
|
20220
|
+
if (doc.getChildren(rootId).length !== 0) return null;
|
|
20221
|
+
const seat = { blockId: null };
|
|
20222
|
+
try {
|
|
20223
|
+
doc.transact(() => {
|
|
20224
|
+
if (doc.getChildren(rootId).length !== 0) return;
|
|
20225
|
+
seat.blockId = doc.insertBlock("paragraph", void 0, { parent: rootId });
|
|
20226
|
+
if (content !== "") doc.insertText(seat.blockId, 0, content);
|
|
20227
|
+
});
|
|
20228
|
+
} catch {
|
|
20229
|
+
return null;
|
|
20230
|
+
}
|
|
20231
|
+
if (seat.blockId === null) return null;
|
|
20232
|
+
focusCaretIn(seat.blockId, content.length, scope);
|
|
20233
|
+
return seat.blockId;
|
|
20234
|
+
}
|
|
20235
|
+
/**
|
|
19996
20236
|
* Whether the inner is a PAGE-SURFACE text block of its own editor scope:
|
|
19997
20237
|
* not inside a contenteditable="false" island of the same scope (the
|
|
19998
20238
|
* island's cells stand their own focused inner). An island OUTSIDE the
|
|
@@ -20151,7 +20391,7 @@ function usePageSurface() {
|
|
|
20151
20391
|
* bare-div's materialization) is suppressed and the caret re-seats into
|
|
20152
20392
|
* the nearest block's edge.
|
|
20153
20393
|
*/
|
|
20154
|
-
function usePageSurfaceDispatch(containerRef, doc, handlers) {
|
|
20394
|
+
function usePageSurfaceDispatch(containerRef, doc, handlers, emptyStand) {
|
|
20155
20395
|
const dispatch = useCallback((event, kind) => {
|
|
20156
20396
|
const container = containerRef.current;
|
|
20157
20397
|
if (container === null || event.target !== container) return;
|
|
@@ -20172,11 +20412,16 @@ function usePageSurfaceDispatch(containerRef, doc, handlers) {
|
|
|
20172
20412
|
if (containerCaretNeedsReseat(container, selection?.anchorNode ?? null) === false) return;
|
|
20173
20413
|
event.preventDefault();
|
|
20174
20414
|
const scope = container.closest("[data-slot=\"docblocks/editor\"]") ?? document;
|
|
20415
|
+
if (emptyStand && materializeEmptyPageParagraph(doc, scope, event.data ?? "") !== null) return;
|
|
20175
20416
|
reseatContainerCaret(container, scope, doc);
|
|
20176
20417
|
};
|
|
20177
20418
|
container.addEventListener("beforeinput", onBeforeInput);
|
|
20178
20419
|
return () => container.removeEventListener("beforeinput", onBeforeInput);
|
|
20179
|
-
}, [
|
|
20420
|
+
}, [
|
|
20421
|
+
containerRef,
|
|
20422
|
+
doc,
|
|
20423
|
+
emptyStand
|
|
20424
|
+
]);
|
|
20180
20425
|
return useMemo(() => ({
|
|
20181
20426
|
onKeyDown: (event) => {
|
|
20182
20427
|
dispatch(event, "keydown");
|
|
@@ -20339,7 +20584,6 @@ function insertCommand(doc, command, at, indent = 0) {
|
|
|
20339
20584
|
case "table": {
|
|
20340
20585
|
const tableId = doc.insertBlock("table", {
|
|
20341
20586
|
cols: 2,
|
|
20342
|
-
columnWidths: [DEFAULT_TABLE_COLUMN_WIDTH, DEFAULT_TABLE_COLUMN_WIDTH],
|
|
20343
20587
|
...ind
|
|
20344
20588
|
}, at);
|
|
20345
20589
|
for (let row = 0; row < 2; row++) {
|
|
@@ -22871,6 +23115,23 @@ function insertRuns(doc, blockId, from, runs) {
|
|
|
22871
23115
|
}
|
|
22872
23116
|
return pos;
|
|
22873
23117
|
}
|
|
23118
|
+
/** The runs' slice from `offset` to the content's end (the marks stand). */
|
|
23119
|
+
function sliceRuns(runs, offset) {
|
|
23120
|
+
const sliced = [];
|
|
23121
|
+
let pos = 0;
|
|
23122
|
+
for (const run of runs) {
|
|
23123
|
+
const end = pos + run.text.length;
|
|
23124
|
+
if (end > offset) {
|
|
23125
|
+
const text = run.text.slice(Math.max(0, offset - pos));
|
|
23126
|
+
if (text !== "") sliced.push({
|
|
23127
|
+
text,
|
|
23128
|
+
marks: run.marks
|
|
23129
|
+
});
|
|
23130
|
+
}
|
|
23131
|
+
pos = end;
|
|
23132
|
+
}
|
|
23133
|
+
return sliced;
|
|
23134
|
+
}
|
|
22874
23135
|
/** The typed insertion (the core's attrs are required per type; the content
|
|
22875
23136
|
* runs are inserted at the fresh block). */
|
|
22876
23137
|
function insertNative(doc, m, parent, after, indent) {
|
|
@@ -23038,7 +23299,8 @@ function insertTable(doc, m, parent, after, indent) {
|
|
|
23038
23299
|
* first pasted block merges into it (the same text type — the block's own
|
|
23039
23300
|
* type and attrs stand) or follows it, the text after the original caret
|
|
23040
23301
|
* (the suffix) lands in the last pasted text block (a trailing paragraph
|
|
23041
|
-
* when the last block is not text)
|
|
23302
|
+
* when the last block is not text) with its own run structure — the marks
|
|
23303
|
+
* over the tail stand. An empty caret block converts in place
|
|
23042
23304
|
* to the first pasted block. Every block the target parent does not accept
|
|
23043
23305
|
* is demoted (the list/quote → paragraph; the table → one paragraph per
|
|
23044
23306
|
* row, the cells joined by ` | `) — the paste never throws on legitimate
|
|
@@ -23057,6 +23319,7 @@ function materializePaste(doc, seatId, from, to, parsed, opts) {
|
|
|
23057
23319
|
const seatText = doc.getText(seatId);
|
|
23058
23320
|
const prefix = seatText.slice(0, from);
|
|
23059
23321
|
const suffix = seatText.slice(to);
|
|
23322
|
+
const suffixRuns = sliceRuns(doc.getRuns(seatId), to);
|
|
23060
23323
|
const seatIndent = indentOf$2(doc, seatId);
|
|
23061
23324
|
const eligible = (type) => {
|
|
23062
23325
|
if (parent === null) return true;
|
|
@@ -23144,14 +23407,12 @@ function materializePaste(doc, seatId, from, to, parsed, opts) {
|
|
|
23144
23407
|
}
|
|
23145
23408
|
landingOffset = lastTextLen;
|
|
23146
23409
|
if (suffix !== "") {
|
|
23147
|
-
if (lastTextId !== null && lastTextType === "paragraph")
|
|
23148
|
-
|
|
23149
|
-
lastTextLen += suffix.length;
|
|
23150
|
-
} else {
|
|
23410
|
+
if (lastTextId !== null && lastTextType === "paragraph") lastTextLen = insertRuns(doc, lastTextId, lastTextLen, suffixRuns);
|
|
23411
|
+
else {
|
|
23151
23412
|
const indent = clamp(material[material.length - 1].indent, prevIndent);
|
|
23152
23413
|
prevId = insertBlockWithIndent(doc, "paragraph", parentId, prevId, indent);
|
|
23153
23414
|
prevIndent = indent;
|
|
23154
|
-
doc
|
|
23415
|
+
insertRuns(doc, prevId, 0, suffixRuns);
|
|
23155
23416
|
}
|
|
23156
23417
|
}
|
|
23157
23418
|
const sequenceNow = doc.getChildren(parentId);
|
|
@@ -25466,7 +25727,7 @@ function LinkPopover({ rootRef, state, onClose }) {
|
|
|
25466
25727
|
useLayoutEffect(() => {
|
|
25467
25728
|
const input = inputRef.current;
|
|
25468
25729
|
if (input === null) return;
|
|
25469
|
-
input.focus();
|
|
25730
|
+
input.focus({ preventScroll: true });
|
|
25470
25731
|
input.select();
|
|
25471
25732
|
}, []);
|
|
25472
25733
|
useLayoutEffect(() => {
|
|
@@ -25523,7 +25784,11 @@ function LinkPopover({ rootRef, state, onClose }) {
|
|
|
25523
25784
|
"data-slot": "docblocks/link-popover",
|
|
25524
25785
|
"aria-label": t("link.aria"),
|
|
25525
25786
|
className: cn("absolute z-modal rounded-md border border-border bg-popover p-2 text-popover-foreground shadow-md", position === null && "opacity-0"),
|
|
25526
|
-
style: position === null ? {
|
|
25787
|
+
style: position === null ? {
|
|
25788
|
+
width: POPOVER_WIDTH_PX,
|
|
25789
|
+
left: state.anchor.x,
|
|
25790
|
+
top: state.anchor.y + ANCHOR_OFFSET_PX
|
|
25791
|
+
} : {
|
|
25527
25792
|
width: POPOVER_WIDTH_PX,
|
|
25528
25793
|
left: position.left,
|
|
25529
25794
|
top: position.top
|
|
@@ -25689,7 +25954,11 @@ function useLinkPopover(rootRef) {
|
|
|
25689
25954
|
if (!parkFocusRef.current) return;
|
|
25690
25955
|
parkFocusRef.current = false;
|
|
25691
25956
|
const active = document.activeElement;
|
|
25692
|
-
if (active === null || active === document.body)
|
|
25957
|
+
if (active === null || active === document.body) {
|
|
25958
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
25959
|
+
const view = selectionRef.view;
|
|
25960
|
+
if (view !== null) reseatHistorySelection(doc, view, rootRef.current ?? document);
|
|
25961
|
+
}
|
|
25693
25962
|
});
|
|
25694
25963
|
const open = useCallback((anchor, opts) => {
|
|
25695
25964
|
setMenu(null);
|
|
@@ -27185,8 +27454,13 @@ function connectorLineGeometryOf(connectorId, block, childIds, blocks, session)
|
|
|
27185
27454
|
};
|
|
27186
27455
|
const startPoly = polyPoint(attrs.start, startDraw, startBox, "start");
|
|
27187
27456
|
const endPoly = polyPoint(attrs.end, endDraw, endBox, "end");
|
|
27457
|
+
const points = (attrs.points ?? []).map(([x, y], index) => {
|
|
27458
|
+
if (!dragging || endpointDrag === null || endpointDrag.which !== "waypoint") return [x, y];
|
|
27459
|
+
if (endpointDrag.index !== index || endpointPreview === null) return [x, y];
|
|
27460
|
+
return [endpointPreview.point.x, endpointPreview.point.y];
|
|
27461
|
+
});
|
|
27188
27462
|
return {
|
|
27189
|
-
path:
|
|
27463
|
+
path: points.length > 0 ? `M ${startPoly.x} ${startPoly.y} L ${points.map(([x, y]) => `${x} ${y}`).join(" L ")} L ${endPoly.x} ${endPoly.y}` : legacy ? connectorPath(startBox, endBox, attrs.variant ?? "straight").d : connectorPathPoints(startDraw, endDraw, attrs.variant ?? "straight", obstacleBoxes).d,
|
|
27190
27464
|
startDraw,
|
|
27191
27465
|
endDraw,
|
|
27192
27466
|
dragging
|
|
@@ -27577,7 +27851,7 @@ function FrameBlock({ id, selected = false, chipMode }) {
|
|
|
27577
27851
|
"data-slot": "docblocks/frame-boundary",
|
|
27578
27852
|
className: "absolute inset-0 rounded-(--docblocks-radius)",
|
|
27579
27853
|
style: {
|
|
27580
|
-
boxShadow: `inset 0 0 0
|
|
27854
|
+
boxShadow: `inset 0 0 0 var(--docblocks-canvas-group-border-width) ${selected ? selectedColor : "var(--docblocks-canvas-group-border-color)"}`,
|
|
27581
27855
|
outline: selected ? `var(--docblocks-canvas-selection-border-width) solid ${selectedColor}` : void 0,
|
|
27582
27856
|
outlineOffset: 1
|
|
27583
27857
|
}
|
|
@@ -27665,7 +27939,7 @@ function GroupBlock({ id, block, selected, chipMode }) {
|
|
|
27665
27939
|
className: "absolute rounded-(--docblocks-radius)",
|
|
27666
27940
|
style: {
|
|
27667
27941
|
inset: 0,
|
|
27668
|
-
boxShadow: `inset 0 0 0
|
|
27942
|
+
boxShadow: `inset 0 0 0 var(--docblocks-canvas-group-border-width) ${selected ? selectedColor : "var(--docblocks-canvas-group-border-color)"}`,
|
|
27669
27943
|
outline: selected ? `1px solid ${selectedColor}` : void 0,
|
|
27670
27944
|
outlineOffset: 1
|
|
27671
27945
|
}
|
|
@@ -27724,7 +27998,7 @@ function GroupBlock({ id, block, selected, chipMode }) {
|
|
|
27724
27998
|
selected,
|
|
27725
27999
|
slot: "group",
|
|
27726
28000
|
ariaLabel: t("titleChip.containerTitle"),
|
|
27727
|
-
restBorderColor: "var(--docblocks-
|
|
28001
|
+
restBorderColor: "var(--docblocks-canvas-group-border-color)",
|
|
27728
28002
|
interactive: chipMode !== "inert"
|
|
27729
28003
|
})
|
|
27730
28004
|
]
|
|
@@ -28369,6 +28643,25 @@ function remapEndpoint(ref, copySet, idMap, dx, dy, toward, resolve) {
|
|
|
28369
28643
|
}
|
|
28370
28644
|
return { ...ref };
|
|
28371
28645
|
}
|
|
28646
|
+
// src/canvas/ConnectorBendButton.tsx
|
|
28647
|
+
/**
|
|
28648
|
+
* The line's bend-point action (the connector toolbar's button): one press
|
|
28649
|
+
* adds a waypoint at the route's middle segment's middle — the waypoint's
|
|
28650
|
+
* dot then drags the route's corner (the dot's double-click removes the
|
|
28651
|
+
* point).
|
|
28652
|
+
*/
|
|
28653
|
+
function ConnectorBendButton({ onPress }) {
|
|
28654
|
+
const { t } = useTranslation("canvas");
|
|
28655
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
28656
|
+
variant: "ghost",
|
|
28657
|
+
size: "icon",
|
|
28658
|
+
"data-slot": "docblocks/connector-toolbar-bend",
|
|
28659
|
+
"aria-label": t("connector.bend"),
|
|
28660
|
+
title: t("connector.bendTitle"),
|
|
28661
|
+
onClick: onPress,
|
|
28662
|
+
children: /* @__PURE__ */ jsx(Waypoints, { className: "size-4" })
|
|
28663
|
+
});
|
|
28664
|
+
}
|
|
28372
28665
|
// src/canvas/ZOrderMenu.tsx
|
|
28373
28666
|
/**
|
|
28374
28667
|
* The canvas figure's z-order menu (the explicit zIndex): the
|
|
@@ -28684,7 +28977,7 @@ const ARROW_HEADS = [
|
|
|
28684
28977
|
icon: /* @__PURE__ */ jsx(Minus, { className: "size-4" })
|
|
28685
28978
|
}
|
|
28686
28979
|
];
|
|
28687
|
-
function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle, arrowHead, arrowStart, zStand, style }) {
|
|
28980
|
+
function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle, arrowHead, arrowStart, zStand, style, onAddWaypoint }) {
|
|
28688
28981
|
const { t } = useTranslation("canvas");
|
|
28689
28982
|
const { doc } = useEditorContext();
|
|
28690
28983
|
const [openSection, setOpenSection] = useState(null);
|
|
@@ -28782,6 +29075,7 @@ function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle,
|
|
|
28782
29075
|
option("straight", "connector.straight", /* @__PURE__ */ jsx(Diagonal, { className: "size-4" })),
|
|
28783
29076
|
option("orthogonal", "connector.orthogonal", /* @__PURE__ */ jsx(Elbow, { className: "size-4" })),
|
|
28784
29077
|
option("curved", "connector.curved", /* @__PURE__ */ jsx(Curve, { className: "size-4" })),
|
|
29078
|
+
onAddWaypoint !== void 0 && /* @__PURE__ */ jsx(ConnectorBendButton, { onPress: onAddWaypoint }),
|
|
28785
29079
|
/* @__PURE__ */ jsx(Separator, {
|
|
28786
29080
|
orientation: "vertical",
|
|
28787
29081
|
className: "h-5"
|
|
@@ -29272,9 +29566,10 @@ function ShapeTextControls({ slotPrefix, sizeListId, fontFamily, textColor, text
|
|
|
29272
29566
|
* position / count over the surface's canvas elements). Each apply is one
|
|
29273
29567
|
* `updateBlock` in one transact (one undo step, one wire update). The
|
|
29274
29568
|
* toolbar is canvas chrome (its own pointers; a press on it starts no
|
|
29275
|
-
* canvas session).
|
|
29569
|
+
* canvas session). The canvas view places it over the box's top edge
|
|
29570
|
+
* (flipped below the box near the canvas's top edge).
|
|
29276
29571
|
*/
|
|
29277
|
-
function CanvasTextToolbar({ id, fontFamily, textColor, textStyle, fontSize, textAlign, zStand, style }) {
|
|
29572
|
+
function CanvasTextToolbar({ id, fontFamily, textColor, textStyle, fontSize, textAlign, zStand, style = {} }) {
|
|
29278
29573
|
const { t } = useTranslation("canvas");
|
|
29279
29574
|
const { doc } = useEditorContext();
|
|
29280
29575
|
const [textColorOpen, setTextColorOpen] = useState(false);
|
|
@@ -29294,11 +29589,7 @@ function CanvasTextToolbar({ id, fontFamily, textColor, textStyle, fontSize, tex
|
|
|
29294
29589
|
};
|
|
29295
29590
|
return /* @__PURE__ */ jsx("div", {
|
|
29296
29591
|
"data-slot": "docblocks/canvas-chrome",
|
|
29297
|
-
|
|
29298
|
-
style: {
|
|
29299
|
-
...style,
|
|
29300
|
-
transform: "translate(-50%, -100%)"
|
|
29301
|
-
},
|
|
29592
|
+
style,
|
|
29302
29593
|
onMouseDown: onToolbarBodyMouseDown,
|
|
29303
29594
|
children: /* @__PURE__ */ jsxs("div", {
|
|
29304
29595
|
"data-slot": "docblocks/canvas-text-toolbar",
|
|
@@ -29344,9 +29635,11 @@ function CanvasTextToolbar({ id, fontFamily, textColor, textStyle, fontSize, tex
|
|
|
29344
29635
|
* reorder picks — one `setZOrder` each). Each apply is one `updateBlock`
|
|
29345
29636
|
* in one transact (one undo step, one wire update). The
|
|
29346
29637
|
* toolbar is canvas chrome (its own pointers; a press on it starts no
|
|
29347
|
-
* canvas session).
|
|
29638
|
+
* canvas session). The canvas view places it over the box's top edge
|
|
29639
|
+
* (flipped below the box near the canvas's top edge — the placement is
|
|
29640
|
+
* the anchor's).
|
|
29348
29641
|
*/
|
|
29349
|
-
function ShapeToolbar({ id, fill, stroke, strokeWidth, strokeStyle, variant, text, fontSize, fontFamily, textColor, textStyle, textAlign, zStand, style }) {
|
|
29642
|
+
function ShapeToolbar({ id, fill, stroke, strokeWidth, strokeStyle, variant, text, fontSize, fontFamily, textColor, textStyle, textAlign, zStand, style = {} }) {
|
|
29350
29643
|
const { t } = useTranslation("canvas");
|
|
29351
29644
|
const { doc } = useEditorContext();
|
|
29352
29645
|
const textEdit = useCanvasTextEdit();
|
|
@@ -29389,11 +29682,7 @@ function ShapeToolbar({ id, fill, stroke, strokeWidth, strokeStyle, variant, tex
|
|
|
29389
29682
|
const beginTextEdit = () => textEdit?.setEditingId(id);
|
|
29390
29683
|
return /* @__PURE__ */ jsx("div", {
|
|
29391
29684
|
"data-slot": "docblocks/canvas-chrome",
|
|
29392
|
-
|
|
29393
|
-
style: {
|
|
29394
|
-
...style,
|
|
29395
|
-
transform: "translate(-50%, -100%)"
|
|
29396
|
-
},
|
|
29685
|
+
style,
|
|
29397
29686
|
onMouseDown: onToolbarBodyMouseDown,
|
|
29398
29687
|
children: /* @__PURE__ */ jsxs("div", {
|
|
29399
29688
|
"data-slot": "docblocks/shape-toolbar",
|
|
@@ -29534,18 +29823,15 @@ function ShapeToolbar({ id, fill, stroke, strokeWidth, strokeStyle, variant, tex
|
|
|
29534
29823
|
* their own (the group's border / the frame's boundary stand the fixed's
|
|
29535
29824
|
* stand), so the z-order's menu is the toolbar's whole content. The toolbar
|
|
29536
29825
|
* is canvas chrome (its own pointers; a press on it starts no canvas
|
|
29537
|
-
* session).
|
|
29826
|
+
* session). The canvas view places it over the box's top edge (the
|
|
29827
|
+
* shape toolbar's placement's stand).
|
|
29538
29828
|
*/
|
|
29539
|
-
function ZOrderToolbar({ id, kind, zStand, style }) {
|
|
29829
|
+
function ZOrderToolbar({ id, kind, zStand, style = {} }) {
|
|
29540
29830
|
const { t } = useTranslation("canvas");
|
|
29541
29831
|
const label = kind === "frame" ? t("arrange.frame") : t("arrange.container");
|
|
29542
29832
|
return /* @__PURE__ */ jsx("div", {
|
|
29543
29833
|
"data-slot": "docblocks/canvas-chrome",
|
|
29544
|
-
|
|
29545
|
-
style: {
|
|
29546
|
-
...style,
|
|
29547
|
-
transform: "translate(-50%, -100%)"
|
|
29548
|
-
},
|
|
29834
|
+
style,
|
|
29549
29835
|
onMouseDown: onToolbarBodyMouseDown,
|
|
29550
29836
|
children: /* @__PURE__ */ jsx("div", {
|
|
29551
29837
|
"data-slot": "docblocks/z-order-toolbar",
|
|
@@ -30174,7 +30460,7 @@ function FramePageWindow({ id, frameId, surfaceId, referenced }) {
|
|
|
30174
30460
|
style: {
|
|
30175
30461
|
width: winW,
|
|
30176
30462
|
height: winH,
|
|
30177
|
-
boxShadow: "inset 0 0 0
|
|
30463
|
+
boxShadow: "inset 0 0 0 var(--docblocks-canvas-group-border-width) var(--docblocks-canvas-group-border-color)"
|
|
30178
30464
|
},
|
|
30179
30465
|
children: /* @__PURE__ */ jsx("div", {
|
|
30180
30466
|
className: "absolute top-0 left-0 origin-top-left",
|
|
@@ -32367,6 +32653,188 @@ function useTableAddChips({ rowHeights, columnWidths, addSessionRef, sessionRef,
|
|
|
32367
32653
|
onAddChipPointerCancel
|
|
32368
32654
|
};
|
|
32369
32655
|
}
|
|
32656
|
+
// src/blocks/table/table-auto-widths.ts
|
|
32657
|
+
/** The table's auto-sizing pure computation: the first row's plain text per
|
|
32658
|
+
* column (over the store's block snapshots) and the width's math (the
|
|
32659
|
+
* header-text base over the minimum floor, the proportional stretch to the
|
|
32660
|
+
* container's width). */
|
|
32661
|
+
/**
|
|
32662
|
+
* The plain text of the cell's content over the store's snapshots (the
|
|
32663
|
+
* read-only stand of the doc's `cellPlainText`): the cell's own text (the
|
|
32664
|
+
* soft breaks stand as the run's `\n`) first, then the text children's text
|
|
32665
|
+
* joined with `\n` between the blocks; the non-text children contribute
|
|
32666
|
+
* nothing to the text. Parts the cell carries no text in are skipped.
|
|
32667
|
+
*/
|
|
32668
|
+
function cellPlainTextOf(blocks, cellId) {
|
|
32669
|
+
const cell = blocks[cellId];
|
|
32670
|
+
if (cell === void 0 || cell.type !== "table-cell") return "";
|
|
32671
|
+
const parts = [];
|
|
32672
|
+
const own = textOf("content" in cell ? cell.content : void 0);
|
|
32673
|
+
if (own !== "") parts.push(own);
|
|
32674
|
+
for (const childId of cell.children ?? EMPTY_IDS) {
|
|
32675
|
+
const block = blocks[childId];
|
|
32676
|
+
if (block === void 0 || !BLOCK_REGISTRY[block.type].content) continue;
|
|
32677
|
+
const text = textOf("content" in block ? block.content : void 0);
|
|
32678
|
+
if (text !== "") parts.push(text);
|
|
32679
|
+
}
|
|
32680
|
+
return parts.join("\n");
|
|
32681
|
+
}
|
|
32682
|
+
/**
|
|
32683
|
+
* The first row's plain text per column (the auto-sizing's header basis).
|
|
32684
|
+
* The cell's `columnId` binding places the text on its column (the row's
|
|
32685
|
+
* cell order may diverge from the column order over the short-row race
|
|
32686
|
+
* residue); a merged header's text stands its anchor column (the covered
|
|
32687
|
+
* columns keep the empty stand — their base falls to the floor).
|
|
32688
|
+
*/
|
|
32689
|
+
function headerColumnTexts(blocks, table) {
|
|
32690
|
+
const columns = table.columnOrder;
|
|
32691
|
+
const texts = new Array(columns.length).fill("");
|
|
32692
|
+
const rowId = table.children?.[0];
|
|
32693
|
+
if (rowId === void 0) return texts;
|
|
32694
|
+
const row = blocks[rowId];
|
|
32695
|
+
if (row === void 0 || row.type !== "table-row") return texts;
|
|
32696
|
+
for (const cellId of row.children ?? EMPTY_IDS) {
|
|
32697
|
+
const cell = blocks[cellId];
|
|
32698
|
+
if (cell === void 0 || cell.type !== "table-cell") continue;
|
|
32699
|
+
const columnId = cell.attrs?.columnId;
|
|
32700
|
+
const index = columnId === void 0 ? -1 : columns.indexOf(columnId);
|
|
32701
|
+
if (index < 0 || texts[index] !== "") continue;
|
|
32702
|
+
const text = cellPlainTextOf(blocks, cellId);
|
|
32703
|
+
if (text !== "") texts[index] = text;
|
|
32704
|
+
}
|
|
32705
|
+
return texts;
|
|
32706
|
+
}
|
|
32707
|
+
/**
|
|
32708
|
+
* The auto-sized column widths (px). The base is a column's measured header
|
|
32709
|
+
* text width + the cell's box overhead (the padding + the border — the
|
|
32710
|
+
* text stands one line without the wrap), floored at the minimum width;
|
|
32711
|
+
* when the bases' sum stands under the container's width the columns
|
|
32712
|
+
* stretch proportionally so the table spans the content. The first
|
|
32713
|
+
* `length - 1` columns round independently; the last one absorbs the
|
|
32714
|
+
* rounding drift so the sum stands the container's width exactly (the
|
|
32715
|
+
* floor stands when the drift would dip the last column under it). A sum
|
|
32716
|
+
* at or over the container stands un-stretched (the overflow scrolls).
|
|
32717
|
+
*/
|
|
32718
|
+
function autoTableWidths(textWidths, containerWidth) {
|
|
32719
|
+
const bases = textWidths.map((width) => Math.max(Math.round(width), 50));
|
|
32720
|
+
const sum = bases.reduce((total, width) => total + width, 0);
|
|
32721
|
+
if (containerWidth <= 0 || sum >= containerWidth) return bases;
|
|
32722
|
+
const scaled = [];
|
|
32723
|
+
for (let i = 0; i < bases.length - 1; i += 1) scaled.push(Math.max(50, Math.round(bases[i] * containerWidth / sum)));
|
|
32724
|
+
const last = Math.max(50, containerWidth - scaled.reduce((total, width) => total + width, 0));
|
|
32725
|
+
scaled.push(last);
|
|
32726
|
+
return scaled;
|
|
32727
|
+
}
|
|
32728
|
+
// src/blocks/table/use-table-auto-widths.ts
|
|
32729
|
+
/** The table's auto-sizing stand: a table with no stored column widths
|
|
32730
|
+
* (the import / the paste stand) sizes its columns to the header text (one
|
|
32731
|
+
* line, the minimum floor) and stretches the sum to the container's content
|
|
32732
|
+
* width; a table with stored widths stands the doc's widths (the explicit
|
|
32733
|
+
* stand takes priority). The stand is view state only — no doc write (the
|
|
32734
|
+
* first seam gesture materializes the layout over the seam's commit). */
|
|
32735
|
+
const FALLBACK_FONT_FAMILY = "Inter, sans-serif";
|
|
32736
|
+
const FALLBACK_FONT_SIZE_PX = 16;
|
|
32737
|
+
const FALLBACK_FONT_WEIGHT = "400";
|
|
32738
|
+
const FALLBACK_CELL_PADDING_X = 8;
|
|
32739
|
+
const FALLBACK_BORDER_WIDTH = 1;
|
|
32740
|
+
/** The measuring canvas (one per page — the 2D context's `measureText`). */
|
|
32741
|
+
let measureContext;
|
|
32742
|
+
/** The text's width in the given font (the canvas's `measureText` — the
|
|
32743
|
+
* DOM's rendering stand without the layout). */
|
|
32744
|
+
function measuredTextWidth(text, font) {
|
|
32745
|
+
if (typeof document === "undefined" || text === "") return 0;
|
|
32746
|
+
if (measureContext === void 0) measureContext = document.createElement("canvas").getContext("2d") ?? null;
|
|
32747
|
+
const ctx = measureContext;
|
|
32748
|
+
if (ctx === null) return 0;
|
|
32749
|
+
ctx.font = font;
|
|
32750
|
+
return ctx.measureText(text.replace(/\s+/g, " ").trim()).width;
|
|
32751
|
+
}
|
|
32752
|
+
/** The cell padding's x component (the token's `y x` stand; the single
|
|
32753
|
+
* value stands both axes). */
|
|
32754
|
+
function cellPaddingXOf(value) {
|
|
32755
|
+
const parts = value.trim().split(/\s+/).filter((part) => part !== "");
|
|
32756
|
+
const of = (part) => {
|
|
32757
|
+
const parsed = Number.parseFloat(part);
|
|
32758
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
32759
|
+
};
|
|
32760
|
+
if (parts.length === 0) return FALLBACK_CELL_PADDING_X;
|
|
32761
|
+
return parts.length === 1 ? of(parts[0]) : of(parts[1]);
|
|
32762
|
+
}
|
|
32763
|
+
/**
|
|
32764
|
+
* The auto-sized widths over a widthless table (null = no stand: an
|
|
32765
|
+
* explicit-widths table or an unmeasurable stand). The container's width
|
|
32766
|
+
* reads the block's root (it spans the page column's content — the
|
|
32767
|
+
* consumer's width override stands, the token's value does not); the
|
|
32768
|
+
* header's font reads the root's computed style (the cells inherit the
|
|
32769
|
+
* editor's text font — no per-cell override stands), over the editor
|
|
32770
|
+
* fonts' readiness re-stand.
|
|
32771
|
+
*/
|
|
32772
|
+
function useTableAutoWidths({ store, id, block, rootRef }) {
|
|
32773
|
+
const explicit = block.attrs?.columnWidths !== void 0;
|
|
32774
|
+
const headerKey = useStore(store, (state) => {
|
|
32775
|
+
if (explicit) return "";
|
|
32776
|
+
const table = state.blocks[id];
|
|
32777
|
+
if (table === void 0 || table.type !== "table") return "";
|
|
32778
|
+
return headerColumnTexts(state.blocks, table).join("\0");
|
|
32779
|
+
});
|
|
32780
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
32781
|
+
const [textWidths, setTextWidths] = useState(null);
|
|
32782
|
+
const [fontReady, setFontReady] = useState(0);
|
|
32783
|
+
useLayoutEffect(() => {
|
|
32784
|
+
if (explicit) return;
|
|
32785
|
+
const el = rootRef.current;
|
|
32786
|
+
if (el === null || typeof ResizeObserver === "undefined") return;
|
|
32787
|
+
const measure = () => {
|
|
32788
|
+
const border = Number.parseFloat(getComputedStyle(el).getPropertyValue("--docblocks-table-border-width")) || 0;
|
|
32789
|
+
setContainerWidth(el.clientWidth - 20 - border);
|
|
32790
|
+
};
|
|
32791
|
+
measure();
|
|
32792
|
+
const observer = new ResizeObserver(measure);
|
|
32793
|
+
observer.observe(el);
|
|
32794
|
+
return () => observer.disconnect();
|
|
32795
|
+
}, [rootRef, explicit]);
|
|
32796
|
+
useLayoutEffect(() => {
|
|
32797
|
+
if (explicit) return;
|
|
32798
|
+
if (typeof document === "undefined" || document.fonts === void 0) return;
|
|
32799
|
+
let cancelled = false;
|
|
32800
|
+
document.fonts.ready.then(() => {
|
|
32801
|
+
if (!cancelled) setFontReady((tick) => tick + 1);
|
|
32802
|
+
}).catch(() => void 0);
|
|
32803
|
+
return () => {
|
|
32804
|
+
cancelled = true;
|
|
32805
|
+
};
|
|
32806
|
+
}, [explicit]);
|
|
32807
|
+
useLayoutEffect(() => {
|
|
32808
|
+
if (explicit) return;
|
|
32809
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
32810
|
+
const el = rootRef.current;
|
|
32811
|
+
if (el === null) return;
|
|
32812
|
+
const blocks = store.getState().blocks;
|
|
32813
|
+
const table = blocks[id];
|
|
32814
|
+
if (table === void 0 || table.type !== "table") return;
|
|
32815
|
+
const style = getComputedStyle(el);
|
|
32816
|
+
const fontFamily = style.fontFamily !== "" ? style.fontFamily : FALLBACK_FONT_FAMILY;
|
|
32817
|
+
const fontSize = Number.parseFloat(style.fontSize) || FALLBACK_FONT_SIZE_PX;
|
|
32818
|
+
const font = `${style.fontWeight !== "" ? style.fontWeight : FALLBACK_FONT_WEIGHT} ${fontSize}px ${fontFamily}`;
|
|
32819
|
+
const overhead = 2 * cellPaddingXOf(style.getPropertyValue("--docblocks-table-cell-padding")) + (Number.parseFloat(style.getPropertyValue("--docblocks-table-border-width")) || FALLBACK_BORDER_WIDTH);
|
|
32820
|
+
setTextWidths(headerColumnTexts(blocks, table).map((text) => measuredTextWidth(text, font) + overhead));
|
|
32821
|
+
}, [
|
|
32822
|
+
store,
|
|
32823
|
+
id,
|
|
32824
|
+
explicit,
|
|
32825
|
+
fontReady,
|
|
32826
|
+
headerKey,
|
|
32827
|
+
rootRef
|
|
32828
|
+
]);
|
|
32829
|
+
return useMemo(() => {
|
|
32830
|
+
if (explicit || containerWidth <= 0 || textWidths === null) return null;
|
|
32831
|
+
return autoTableWidths(textWidths, containerWidth);
|
|
32832
|
+
}, [
|
|
32833
|
+
explicit,
|
|
32834
|
+
textWidths,
|
|
32835
|
+
containerWidth
|
|
32836
|
+
]);
|
|
32837
|
+
}
|
|
32370
32838
|
// src/blocks/table/use-table-cell-menu.ts
|
|
32371
32839
|
/** The table cell's right-click menu (copy / paste / clear): the
|
|
32372
32840
|
* release-open gesture (the held right press's open stands the gesture's
|
|
@@ -32593,17 +33061,19 @@ function useTableHandleActions({ doc, rows, tableBlockId, setMenu, scrollRef })
|
|
|
32593
33061
|
* against the table's edges), the release (a non-drag press opens the
|
|
32594
33062
|
* handle's menu; a drag commits the move after validating the live doc
|
|
32595
33063
|
* against the press-time snapshot — a concurrent structural change stands,
|
|
32596
|
-
* no command, the rows resync from the doc), and the cancel. The
|
|
33064
|
+
* no command, the rows resync from the doc), and the cancel. The drop's
|
|
33065
|
+
* widths stand the rendered stand (the doc's or the auto-sized ones — the
|
|
33066
|
+
* on-screen geometry's truth). The preview's
|
|
32597
33067
|
* state stands in the hook (the view reads the dragged row/column's live
|
|
32598
33068
|
* position + the parting shift). */
|
|
32599
|
-
function useTableHandleDrag({ sessionRef, setHover, setMenu, tableEl, doc, rows, block, id }) {
|
|
33069
|
+
function useTableHandleDrag({ sessionRef, setHover, setMenu, tableEl, doc, rows, block, widths, id }) {
|
|
32600
33070
|
const [preview, setPreview] = useState(null);
|
|
32601
33071
|
const onHandlePointerDown = (kind, index) => (event) => {
|
|
32602
33072
|
if (event.button !== 0 || sessionRef.current !== null) return;
|
|
32603
33073
|
event.preventDefault();
|
|
32604
33074
|
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
32605
33075
|
const table = tableEl();
|
|
32606
|
-
const startSize = kind === "column" ?
|
|
33076
|
+
const startSize = kind === "column" ? widths[index] ?? DEFAULT_TABLE_COLUMN_WIDTH : table?.querySelectorAll("tbody > tr")[index]?.offsetHeight ?? 0;
|
|
32607
33077
|
sessionRef.current = {
|
|
32608
33078
|
kind,
|
|
32609
33079
|
index,
|
|
@@ -32622,15 +33092,16 @@ function useTableHandleDrag({ sessionRef, setHover, setMenu, tableEl, doc, rows,
|
|
|
32622
33092
|
* pre-move doc index of the landing slot) for a pointer x: the
|
|
32623
33093
|
* stationary columns' widths (the dragged column's own width is
|
|
32624
33094
|
* excluded) against the table's left edge — the release's commit and
|
|
32625
|
-
* the live parting preview share the measurement.
|
|
33095
|
+
* the live parting preview share the measurement. A structural change
|
|
33096
|
+
* (the column count) stands the no-drop.
|
|
32626
33097
|
*/
|
|
32627
33098
|
const columnToIndexAt = (clientX, excludeIndex) => {
|
|
32628
33099
|
const table = tableEl();
|
|
32629
33100
|
if (table === null) return null;
|
|
32630
33101
|
const live = doc.getBlock(id);
|
|
32631
|
-
if (live === null || live.type !== "table") return null;
|
|
33102
|
+
if (live === null || live.type !== "table" || live.columnOrder.length !== widths.length) return null;
|
|
32632
33103
|
const rect = table.getBoundingClientRect();
|
|
32633
|
-
return columnDropPosition(
|
|
33104
|
+
return columnDropPosition(widths.filter((_, i) => i !== excludeIndex), clientX - rect.left);
|
|
32634
33105
|
};
|
|
32635
33106
|
/** The dragged row's drop index (the final visible index — the pre-move
|
|
32636
33107
|
* doc index of the landing slot) for a pointer y: the stationary rows'
|
|
@@ -32840,16 +33311,37 @@ function useTableRegions({ doc, tableId }) {
|
|
|
32840
33311
|
/** The table's column-seam resize: the seam's press + drag (the live
|
|
32841
33312
|
* preview overrides the dragged column's width — no wire traffic until the
|
|
32842
33313
|
* release commits the width), the release (the clamped width commits when
|
|
32843
|
-
* it changed — one
|
|
32844
|
-
* the cancel. The
|
|
33314
|
+
* it changed — one transact, one undo step; a 0 px drag stands a no-op), and
|
|
33315
|
+
* the cancel. The commit stands the table's final widths over the whole
|
|
33316
|
+
* column set: an equal-value set is a zero-byte no-op (a width-set table
|
|
33317
|
+
* writes only the changed column), and a widthless table (the auto-sizing's
|
|
33318
|
+
* stand) materializes the full layout over the first gesture. The preview's
|
|
33319
|
+
* state stands in the hook (the view's read of
|
|
32845
33320
|
* the dragged column's width). */
|
|
32846
|
-
function useTableSeamResize({
|
|
33321
|
+
function useTableSeamResize({ widths, doc, id, resizeSessionRef }) {
|
|
32847
33322
|
const [resizePreview, setResizePreview] = useState(null);
|
|
33323
|
+
/**
|
|
33324
|
+
* The width's commit: the final widths over the whole column set in one
|
|
33325
|
+
* transact (one undo step, one wire update). The unchanged columns stand
|
|
33326
|
+
* their standing widths (the equal-value no-op writes nothing); the
|
|
33327
|
+
* widthless table's first gesture stands the full layout's materialization
|
|
33328
|
+
* (the auto's stand takes its explicit's stand). A structural change over
|
|
33329
|
+
* the column count (a concurrent restructure) stands the no-commit.
|
|
33330
|
+
*/
|
|
33331
|
+
const commitWidths = (index, width) => {
|
|
33332
|
+
const live = doc.getBlock(id);
|
|
33333
|
+
if (live === null || live.type !== "table" || live.columnOrder.length !== widths.length) return;
|
|
33334
|
+
try {
|
|
33335
|
+
doc.transact(() => {
|
|
33336
|
+
for (let i = 0; i < widths.length; i += 1) doc.setTableColumnWidth(id, i, i === index ? width : widths[i]);
|
|
33337
|
+
});
|
|
33338
|
+
} catch {}
|
|
33339
|
+
};
|
|
32848
33340
|
const onSeamPointerDown = (col) => (event) => {
|
|
32849
33341
|
if (event.button !== 0 || resizeSessionRef.current !== null) return;
|
|
32850
33342
|
event.preventDefault();
|
|
32851
33343
|
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
32852
|
-
const startWidth =
|
|
33344
|
+
const startWidth = widths[col - 1] ?? 50;
|
|
32853
33345
|
resizeSessionRef.current = {
|
|
32854
33346
|
col,
|
|
32855
33347
|
startX: event.clientX,
|
|
@@ -32868,7 +33360,7 @@ function useTableSeamResize({ docWidths, doc, id, resizeSessionRef }) {
|
|
|
32868
33360
|
};
|
|
32869
33361
|
/**
|
|
32870
33362
|
* The seam release: the clamped width commits when it changed (one
|
|
32871
|
-
*
|
|
33363
|
+
* transact, one undo step); a 0 px drag stands a no-op (no wire traffic).
|
|
32872
33364
|
*/
|
|
32873
33365
|
const onSeamPointerUp = (event) => {
|
|
32874
33366
|
const session = resizeSessionRef.current;
|
|
@@ -32876,25 +33368,25 @@ function useTableSeamResize({ docWidths, doc, id, resizeSessionRef }) {
|
|
|
32876
33368
|
setResizePreview(null);
|
|
32877
33369
|
if (session === null || session.width === session.startWidth) return;
|
|
32878
33370
|
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
32879
|
-
|
|
32880
|
-
doc.setTableColumnWidth(id, session.col - 1, session.width);
|
|
32881
|
-
} catch {}
|
|
33371
|
+
commitWidths(session.col - 1, session.width);
|
|
32882
33372
|
};
|
|
32883
33373
|
/**
|
|
32884
33374
|
* The seam's keyboard resize (the ARIA separator's pattern): the arrows
|
|
32885
|
-
* step the column's width by the key step — one
|
|
32886
|
-
*
|
|
33375
|
+
* step the column's width by the key step — one commit per press (one
|
|
33376
|
+
* undo step), the clamp stands the no-op at the edges. The start stands
|
|
33377
|
+
* the stored width (the explicit's stand) or the rendered width over a
|
|
33378
|
+
* widthless table (the auto's stand — the minimum's stand would stand a
|
|
33379
|
+
* jump).
|
|
32887
33380
|
*/
|
|
32888
33381
|
const onSeamKeyDown = (col) => (event) => {
|
|
32889
33382
|
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
|
|
32890
33383
|
event.preventDefault();
|
|
32891
33384
|
const table = doc.getBlock(id);
|
|
32892
|
-
|
|
33385
|
+
if (table === null || table.type !== "table") return;
|
|
33386
|
+
const current = table.attrs?.columnWidths?.[col - 1] ?? widths[col - 1] ?? 50;
|
|
32893
33387
|
const next = clampColumnWidth(current + (event.key === "ArrowRight" ? 8 : -8));
|
|
32894
33388
|
if (next === current) return;
|
|
32895
|
-
|
|
32896
|
-
doc.setTableColumnWidth(id, col - 1, next);
|
|
32897
|
-
} catch {}
|
|
33389
|
+
commitWidths(col - 1, next);
|
|
32898
33390
|
};
|
|
32899
33391
|
const onSeamPointerCancel = () => {
|
|
32900
33392
|
resizeSessionRef.current = null;
|
|
@@ -32945,8 +33437,12 @@ function useTableStructureGuard(structureKey, open, close) {
|
|
|
32945
33437
|
*
|
|
32946
33438
|
* Layout: the width is the sum of the column widths (the `columnWidths`
|
|
32947
33439
|
* attr; an absent entry falls back to the default) under `table-fixed`; a
|
|
32948
|
-
* wider-than-the-page table scrolls horizontally.
|
|
32949
|
-
*
|
|
33440
|
+
* wider-than-the-page table scrolls horizontally. A widthless table (no
|
|
33441
|
+
* stored widths — the import / the paste's stand) auto-sizes: the columns
|
|
33442
|
+
* stand the header text (the minimum's floor) over the container's content
|
|
33443
|
+
* width (`use-table-auto-widths` — no doc write; the first seam gesture
|
|
33444
|
+
* materializes the layout). The cell background is the column color over
|
|
33445
|
+
* the row color (the column wins).
|
|
32950
33446
|
*
|
|
32951
33447
|
* The chrome stands over the gesture modules: the handles' reorder drag +
|
|
32952
33448
|
* the menu (`TableHandles` + `use-table-handle-drag` +
|
|
@@ -32959,24 +33455,30 @@ function useTableStructureGuard(structureKey, open, close) {
|
|
|
32959
33455
|
* over `use-table-metrics`.
|
|
32960
33456
|
*/
|
|
32961
33457
|
function TableBlock({ id, block }) {
|
|
32962
|
-
const { doc, viewMode } = useEditorContext();
|
|
33458
|
+
const { doc, viewMode, store } = useEditorContext();
|
|
32963
33459
|
const palette = useFormatPalette();
|
|
32964
33460
|
const rows = block.children ?? EMPTY_IDS;
|
|
32965
33461
|
const contextValue = useBlockContextValue(id, rows, "table");
|
|
32966
33462
|
const docWidths = Array.from({ length: block.columnOrder.length }, (_, index) => block.attrs?.columnWidths?.[index] ?? DEFAULT_TABLE_COLUMN_WIDTH);
|
|
33463
|
+
const frameRef = useRef(null);
|
|
33464
|
+
const baseWidths = useTableAutoWidths({
|
|
33465
|
+
store,
|
|
33466
|
+
id,
|
|
33467
|
+
block,
|
|
33468
|
+
rootRef: frameRef
|
|
33469
|
+
}) ?? docWidths;
|
|
32967
33470
|
const resizeSessionRef = useRef(null);
|
|
32968
33471
|
const { resizePreview, onSeamPointerDown, onSeamPointerMove, onSeamPointerUp, onSeamPointerCancel, onSeamKeyDown } = useTableSeamResize({
|
|
32969
|
-
|
|
33472
|
+
widths: baseWidths,
|
|
32970
33473
|
doc,
|
|
32971
33474
|
id,
|
|
32972
33475
|
resizeSessionRef
|
|
32973
33476
|
});
|
|
32974
|
-
const widths = resizePreview !== null ?
|
|
33477
|
+
const widths = resizePreview !== null ? baseWidths.map((width, i) => i === resizePreview.col - 1 ? resizePreview.width : width) : baseWidths;
|
|
32975
33478
|
const tableWidth = widths.reduce((sum, width) => sum + width, 0);
|
|
32976
33479
|
const scrollRef = useRef(null);
|
|
32977
33480
|
const [menu, setMenu] = useState(null);
|
|
32978
33481
|
const sessionRef = useRef(null);
|
|
32979
|
-
const frameRef = useRef(null);
|
|
32980
33482
|
const addSessionRef = useRef(null);
|
|
32981
33483
|
const [addPreview, setAddPreview] = useState(null);
|
|
32982
33484
|
const addDragClickRef = useRef(false);
|
|
@@ -33011,6 +33513,7 @@ function TableBlock({ id, block }) {
|
|
|
33011
33513
|
doc,
|
|
33012
33514
|
rows,
|
|
33013
33515
|
block,
|
|
33516
|
+
widths: baseWidths,
|
|
33014
33517
|
id
|
|
33015
33518
|
});
|
|
33016
33519
|
const { rangeHandlers } = useTableCellRangeWiring({
|
|
@@ -33704,6 +34207,124 @@ function CanvasOverlays({ viewport, previewFrom, previewEnd, previewSnap, hoverS
|
|
|
33704
34207
|
})
|
|
33705
34208
|
] });
|
|
33706
34209
|
}
|
|
34210
|
+
// src/canvas/canvas-view/CanvasWaypointHandles.tsx
|
|
34211
|
+
/**
|
|
34212
|
+
* The selected line's waypoint dots (the bend points): the screen-space
|
|
34213
|
+
* stand over the route at any zoom (the line's own options toolbar sits
|
|
34214
|
+
* above them, z-60). The dot's press opens the waypoint's drag (the
|
|
34215
|
+
* container keeps the pointer, the release commits the point); the dot's
|
|
34216
|
+
* double-click stands the point's removal — the drag's pointer capture
|
|
34217
|
+
* retargets the double-click to the canvas container, so the removal
|
|
34218
|
+
* stands in the content's double-click handler (the point's element is
|
|
34219
|
+
* the read there).
|
|
34220
|
+
*/
|
|
34221
|
+
function CanvasWaypointHandles({ connectorId, points, screenOf, onPress }) {
|
|
34222
|
+
if (points.length === 0) return null;
|
|
34223
|
+
return /* @__PURE__ */ jsx("div", {
|
|
34224
|
+
"data-slot": "docblocks/connector-waypoints",
|
|
34225
|
+
className: "pointer-events-none absolute inset-0 z-50",
|
|
34226
|
+
children: points.map((point, index) => {
|
|
34227
|
+
const screen = screenOf(point);
|
|
34228
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
34229
|
+
"data-connector-waypoint": index,
|
|
34230
|
+
"data-connector-waypoint-id": connectorId,
|
|
34231
|
+
width: 16,
|
|
34232
|
+
height: 16,
|
|
34233
|
+
style: {
|
|
34234
|
+
position: "absolute",
|
|
34235
|
+
left: `calc(50% + ${screen.x}px - 8px)`,
|
|
34236
|
+
top: `calc(50% + ${screen.y}px - 8px)`
|
|
34237
|
+
},
|
|
34238
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
34239
|
+
cx: 8,
|
|
34240
|
+
cy: 8,
|
|
34241
|
+
r: 8,
|
|
34242
|
+
fill: "transparent",
|
|
34243
|
+
pointerEvents: "all",
|
|
34244
|
+
className: "cursor-grab",
|
|
34245
|
+
onPointerDown: (event) => onPress(connectorId, index, event)
|
|
34246
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
34247
|
+
cx: 8,
|
|
34248
|
+
cy: 8,
|
|
34249
|
+
r: 4,
|
|
34250
|
+
fill: SURFACE_BG,
|
|
34251
|
+
strokeWidth: 1.5,
|
|
34252
|
+
pointerEvents: "none",
|
|
34253
|
+
className: "stroke-(--docblocks-canvas-selected-stroke)"
|
|
34254
|
+
})]
|
|
34255
|
+
}, `${index}-${point.x}-${point.y}`);
|
|
34256
|
+
})
|
|
34257
|
+
});
|
|
34258
|
+
}
|
|
34259
|
+
// src/canvas/canvas-view/CanvasConnectorChrome.tsx
|
|
34260
|
+
function CanvasConnectorChrome({ viewport, blocks, target, handles, onEndpointPress, onWaypointPress, onAddWaypoint }) {
|
|
34261
|
+
const mid = canvasToScreen(target.mid, viewport.zoom, viewport.pan);
|
|
34262
|
+
const waypointPoints = connectorWaypointPoints(blocks[target.id], {
|
|
34263
|
+
movePreview: viewport.movePreview,
|
|
34264
|
+
resizePreview: viewport.resizePreview,
|
|
34265
|
+
endpointDrag: viewport.connectorEndpoint,
|
|
34266
|
+
endpointPreview: viewport.connectorEndpointPreview
|
|
34267
|
+
});
|
|
34268
|
+
const screenOf = (point) => canvasToScreen(point, viewport.zoom, viewport.pan);
|
|
34269
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
34270
|
+
/* @__PURE__ */ jsx(ConnectorToolbar, {
|
|
34271
|
+
id: target.id,
|
|
34272
|
+
variant: target.variant,
|
|
34273
|
+
strokeColor: target.strokeColor,
|
|
34274
|
+
strokeWidth: target.strokeWidth,
|
|
34275
|
+
strokeStyle: target.strokeStyle,
|
|
34276
|
+
arrowHead: target.arrowHead,
|
|
34277
|
+
arrowStart: target.arrowStart,
|
|
34278
|
+
zStand: target.zStand,
|
|
34279
|
+
onAddWaypoint,
|
|
34280
|
+
style: {
|
|
34281
|
+
left: `calc(50% + ${mid.x}px)`,
|
|
34282
|
+
top: `calc(50% + ${mid.y - 48}px)`
|
|
34283
|
+
}
|
|
34284
|
+
}),
|
|
34285
|
+
handles !== null && /* @__PURE__ */ jsx("div", {
|
|
34286
|
+
"data-slot": "docblocks/connector-handles",
|
|
34287
|
+
className: "pointer-events-none absolute inset-0 z-50",
|
|
34288
|
+
children: ["start", "end"].map((which) => {
|
|
34289
|
+
const point = screenOf(handles[which]);
|
|
34290
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
34291
|
+
"data-connector-endpoint": which,
|
|
34292
|
+
"data-connector-endpoint-id": target.id,
|
|
34293
|
+
width: 16,
|
|
34294
|
+
height: 16,
|
|
34295
|
+
style: {
|
|
34296
|
+
position: "absolute",
|
|
34297
|
+
left: `calc(50% + ${point.x}px - 8px)`,
|
|
34298
|
+
top: `calc(50% + ${point.y}px - 8px)`
|
|
34299
|
+
},
|
|
34300
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
34301
|
+
cx: 8,
|
|
34302
|
+
cy: 8,
|
|
34303
|
+
r: 8,
|
|
34304
|
+
fill: "transparent",
|
|
34305
|
+
pointerEvents: "all",
|
|
34306
|
+
className: "cursor-grab",
|
|
34307
|
+
onPointerDown: (event) => onEndpointPress(which, event)
|
|
34308
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
34309
|
+
cx: 8,
|
|
34310
|
+
cy: 8,
|
|
34311
|
+
r: 4,
|
|
34312
|
+
fill: "var(--docblocks-canvas-surface-background, var(--card, #ffffff))",
|
|
34313
|
+
strokeWidth: 1.5,
|
|
34314
|
+
pointerEvents: "none",
|
|
34315
|
+
className: "stroke-(--docblocks-canvas-selected-stroke)"
|
|
34316
|
+
})]
|
|
34317
|
+
}, which);
|
|
34318
|
+
})
|
|
34319
|
+
}),
|
|
34320
|
+
/* @__PURE__ */ jsx(CanvasWaypointHandles, {
|
|
34321
|
+
connectorId: target.id,
|
|
34322
|
+
points: waypointPoints,
|
|
34323
|
+
screenOf,
|
|
34324
|
+
onPress: onWaypointPress
|
|
34325
|
+
})
|
|
34326
|
+
] });
|
|
34327
|
+
}
|
|
33707
34328
|
// src/canvas/canvas-view/CanvasCycleIndicator.tsx
|
|
33708
34329
|
/** The drill-down's `i / N` indicator: the small chip at the click point
|
|
33709
34330
|
* that names the selected candidate's position in the stack and the stack's
|
|
@@ -33857,12 +34478,81 @@ function CanvasTitleChips({ surfaces, blocks, visibleIds, selection, viewport, v
|
|
|
33857
34478
|
selected,
|
|
33858
34479
|
slot: block.type,
|
|
33859
34480
|
ariaLabel: block.type === "group" ? t("titleChip.containerTitle") : t("titleChip.frameTitle"),
|
|
33860
|
-
restBorderColor:
|
|
34481
|
+
restBorderColor: "var(--docblocks-canvas-group-border-color)",
|
|
33861
34482
|
interactive: !viewMode
|
|
33862
34483
|
})
|
|
33863
34484
|
}, `${surfaceId}-${childId}`);
|
|
33864
34485
|
})) });
|
|
33865
34486
|
}
|
|
34487
|
+
const ABOVE_TRANSFORM = "translate(-50%, -100%)";
|
|
34488
|
+
const BELOW_TRANSFORM = "translate(-50%, 0)";
|
|
34489
|
+
/**
|
|
34490
|
+
* The toolbar's placement: above the box's top edge when the toolbar's own
|
|
34491
|
+
* height fits between the box and the canvas's top edge, below the box's
|
|
34492
|
+
* bottom edge otherwise (clamped into the canvas's vertical band when the
|
|
34493
|
+
* flipped stand overflows it). The horizontal center clamps into the
|
|
34494
|
+
* canvas's width.
|
|
34495
|
+
*/
|
|
34496
|
+
function placeToolbar(centerX, boxTop, boxBottom, container, toolbar) {
|
|
34497
|
+
const measured = toolbar.height > 0;
|
|
34498
|
+
const containerTop = -container.height / 2;
|
|
34499
|
+
const containerBottom = container.height / 2;
|
|
34500
|
+
const fitsAbove = !measured || boxTop - 48 - toolbar.height >= containerTop;
|
|
34501
|
+
let top;
|
|
34502
|
+
let transform;
|
|
34503
|
+
if (fitsAbove) {
|
|
34504
|
+
top = boxTop - 48;
|
|
34505
|
+
transform = ABOVE_TRANSFORM;
|
|
34506
|
+
} else {
|
|
34507
|
+
top = boxBottom + 8;
|
|
34508
|
+
transform = BELOW_TRANSFORM;
|
|
34509
|
+
if (top + toolbar.height > containerBottom) top = containerBottom - toolbar.height;
|
|
34510
|
+
}
|
|
34511
|
+
const halfWidth = toolbar.width / 2;
|
|
34512
|
+
return {
|
|
34513
|
+
left: measured && container.width > toolbar.width ? Math.min(Math.max(centerX, -container.width / 2 + halfWidth), container.width / 2 - halfWidth) : centerX,
|
|
34514
|
+
top,
|
|
34515
|
+
transform
|
|
34516
|
+
};
|
|
34517
|
+
}
|
|
34518
|
+
// src/canvas/canvas-view/CanvasToolbarAnchor.tsx
|
|
34519
|
+
const EMPTY_SIZE = {
|
|
34520
|
+
width: 0,
|
|
34521
|
+
height: 0
|
|
34522
|
+
};
|
|
34523
|
+
function CanvasToolbarAnchor({ centerX, boxTop, boxBottom, container, children }) {
|
|
34524
|
+
const ref = useRef(null);
|
|
34525
|
+
const [size, setSize] = useState(EMPTY_SIZE);
|
|
34526
|
+
useLayoutEffect(() => {
|
|
34527
|
+
const element = ref.current;
|
|
34528
|
+
if (element === null) return;
|
|
34529
|
+
const measure = () => {
|
|
34530
|
+
const next = {
|
|
34531
|
+
width: element.offsetWidth,
|
|
34532
|
+
height: element.offsetHeight
|
|
34533
|
+
};
|
|
34534
|
+
setSize((prev) => prev.width === next.width && prev.height === next.height ? prev : next);
|
|
34535
|
+
};
|
|
34536
|
+
measure();
|
|
34537
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
34538
|
+
const observer = new ResizeObserver(measure);
|
|
34539
|
+
observer.observe(element);
|
|
34540
|
+
return () => observer.disconnect();
|
|
34541
|
+
}, []);
|
|
34542
|
+
const placement = placeToolbar(centerX, boxTop, boxBottom, container, size);
|
|
34543
|
+
const style = {
|
|
34544
|
+
left: `calc(50% + ${placement.left}px)`,
|
|
34545
|
+
top: `calc(50% + ${placement.top}px)`,
|
|
34546
|
+
transform: placement.transform
|
|
34547
|
+
};
|
|
34548
|
+
return /* @__PURE__ */ jsx("div", {
|
|
34549
|
+
ref,
|
|
34550
|
+
"data-slot": "docblocks/canvas-toolbar-anchor",
|
|
34551
|
+
className: "absolute z-50",
|
|
34552
|
+
style,
|
|
34553
|
+
children
|
|
34554
|
+
});
|
|
34555
|
+
}
|
|
33866
34556
|
// src/canvas/canvas-view/ZoomControls.tsx
|
|
33867
34557
|
/** The canvas zoom controls (the floating chrome, top-right): the fit / zoom-out /
|
|
33868
34558
|
* current / zoom-in buttons. The zoom stands in the view state only — no
|
|
@@ -33918,12 +34608,36 @@ const ZoomControls = memo(function ZoomControls({ zoom, onStep, onReset, onFit }
|
|
|
33918
34608
|
});
|
|
33919
34609
|
}, (prev, next) => prev.zoom === next.zoom && prev.onStep === next.onStep && prev.onFit === next.onFit);
|
|
33920
34610
|
// src/canvas/canvas-view/CanvasScreenChrome.tsx
|
|
33921
|
-
function CanvasScreenChrome({ viewport, blocks, surfaces, culling, selection, viewMode, targets, onChipPress, onChipDoubleClick,
|
|
34611
|
+
function CanvasScreenChrome({ containerSize, viewport, blocks, surfaces, culling, selection, viewMode, targets, onChipPress, onChipDoubleClick, beginEndpointDrag, beginWaypointDrag, addConnectorWaypoint, onResetZoom, onFit }) {
|
|
33922
34612
|
const { multiSelectionBox, handleTarget, displayBox, connectorToolbarTarget, selectedConnectorHandles, shapeToolbarTarget, textToolbarTarget, arrangeToolbarTarget } = targets;
|
|
33923
|
-
const
|
|
34613
|
+
const boxTop = (box) => canvasToScreen({
|
|
34614
|
+
x: box.x,
|
|
34615
|
+
y: box.y
|
|
34616
|
+
}, viewport.zoom, viewport.pan).y - box.h / 2 * viewport.zoom;
|
|
34617
|
+
const boxBottom = (box) => canvasToScreen({
|
|
33924
34618
|
x: box.x,
|
|
33925
34619
|
y: box.y
|
|
33926
|
-
}, viewport.zoom, viewport.pan).y
|
|
34620
|
+
}, viewport.zoom, viewport.pan).y + box.h / 2 * viewport.zoom;
|
|
34621
|
+
const connectorId = connectorToolbarTarget?.id ?? null;
|
|
34622
|
+
const onEndpointPress = (which, event) => {
|
|
34623
|
+
if (connectorId === null) return;
|
|
34624
|
+
event.stopPropagation();
|
|
34625
|
+
event.preventDefault();
|
|
34626
|
+
beginEndpointDrag(connectorId, which, event.pointerId, event.clientX, event.clientY);
|
|
34627
|
+
};
|
|
34628
|
+
const onWaypointPress = (id, index, event) => {
|
|
34629
|
+
event.stopPropagation();
|
|
34630
|
+
event.preventDefault();
|
|
34631
|
+
beginWaypointDrag(id, index, event.pointerId, event.clientX, event.clientY);
|
|
34632
|
+
};
|
|
34633
|
+
const onAddWaypoint = () => {
|
|
34634
|
+
if (connectorId === null) return;
|
|
34635
|
+
addConnectorWaypoint(connectorId);
|
|
34636
|
+
};
|
|
34637
|
+
const boxCenterX = (box) => canvasToScreen({
|
|
34638
|
+
x: box.x,
|
|
34639
|
+
y: box.y
|
|
34640
|
+
}, viewport.zoom, viewport.pan).x;
|
|
33927
34641
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
33928
34642
|
/* @__PURE__ */ jsx(CanvasSelectionOverlay, {
|
|
33929
34643
|
viewport,
|
|
@@ -33953,104 +34667,61 @@ function CanvasScreenChrome({ viewport, blocks, surfaces, culling, selection, vi
|
|
|
33953
34667
|
style
|
|
33954
34668
|
}, handleId))
|
|
33955
34669
|
}),
|
|
33956
|
-
connectorToolbarTarget !== null && /* @__PURE__ */ jsx(
|
|
33957
|
-
|
|
33958
|
-
|
|
33959
|
-
|
|
33960
|
-
|
|
33961
|
-
|
|
33962
|
-
|
|
33963
|
-
|
|
33964
|
-
zStand: connectorToolbarTarget.zStand,
|
|
33965
|
-
style: {
|
|
33966
|
-
left: `calc(50% + ${canvasToScreen(connectorToolbarTarget.mid, viewport.zoom, viewport.pan).x}px)`,
|
|
33967
|
-
top: `calc(50% + ${canvasToScreen(connectorToolbarTarget.mid, viewport.zoom, viewport.pan).y - 48}px)`
|
|
33968
|
-
}
|
|
34670
|
+
connectorToolbarTarget !== null && /* @__PURE__ */ jsx(CanvasConnectorChrome, {
|
|
34671
|
+
viewport,
|
|
34672
|
+
blocks,
|
|
34673
|
+
target: connectorToolbarTarget,
|
|
34674
|
+
handles: selectedConnectorHandles,
|
|
34675
|
+
onEndpointPress,
|
|
34676
|
+
onWaypointPress,
|
|
34677
|
+
onAddWaypoint
|
|
33969
34678
|
}),
|
|
33970
|
-
|
|
33971
|
-
|
|
33972
|
-
|
|
33973
|
-
|
|
33974
|
-
|
|
33975
|
-
|
|
33976
|
-
|
|
33977
|
-
|
|
33978
|
-
|
|
33979
|
-
|
|
33980
|
-
|
|
33981
|
-
|
|
33982
|
-
|
|
33983
|
-
|
|
33984
|
-
|
|
33985
|
-
|
|
33986
|
-
|
|
33987
|
-
|
|
33988
|
-
|
|
33989
|
-
fill: "transparent",
|
|
33990
|
-
pointerEvents: "all",
|
|
33991
|
-
className: "cursor-grab",
|
|
33992
|
-
onPointerDown: onEndpointPointerDown(which)
|
|
33993
|
-
}), /* @__PURE__ */ jsx("circle", {
|
|
33994
|
-
cx: 8,
|
|
33995
|
-
cy: 8,
|
|
33996
|
-
r: 4,
|
|
33997
|
-
fill: "var(--docblocks-canvas-surface-background, var(--card, #ffffff))",
|
|
33998
|
-
strokeWidth: 1.5,
|
|
33999
|
-
pointerEvents: "none",
|
|
34000
|
-
className: "stroke-(--docblocks-canvas-selected-stroke)"
|
|
34001
|
-
})]
|
|
34002
|
-
}, which);
|
|
34679
|
+
shapeToolbarTarget !== null && displayBox !== null && /* @__PURE__ */ jsx(CanvasToolbarAnchor, {
|
|
34680
|
+
centerX: boxCenterX(displayBox),
|
|
34681
|
+
boxTop: boxTop(displayBox),
|
|
34682
|
+
boxBottom: boxBottom(displayBox),
|
|
34683
|
+
container: containerSize,
|
|
34684
|
+
children: /* @__PURE__ */ jsx(ShapeToolbar, {
|
|
34685
|
+
id: shapeToolbarTarget.id,
|
|
34686
|
+
fill: shapeToolbarTarget.fill,
|
|
34687
|
+
stroke: shapeToolbarTarget.stroke,
|
|
34688
|
+
strokeWidth: shapeToolbarTarget.strokeWidth,
|
|
34689
|
+
strokeStyle: shapeToolbarTarget.strokeStyle,
|
|
34690
|
+
variant: shapeToolbarTarget.variant,
|
|
34691
|
+
text: shapeToolbarTarget.text,
|
|
34692
|
+
fontSize: shapeToolbarTarget.fontSize,
|
|
34693
|
+
fontFamily: shapeToolbarTarget.fontFamily,
|
|
34694
|
+
textColor: shapeToolbarTarget.textColor,
|
|
34695
|
+
textStyle: shapeToolbarTarget.textStyle,
|
|
34696
|
+
textAlign: shapeToolbarTarget.textAlign,
|
|
34697
|
+
zStand: shapeToolbarTarget.zStand
|
|
34003
34698
|
})
|
|
34004
34699
|
}),
|
|
34005
|
-
|
|
34006
|
-
|
|
34007
|
-
|
|
34008
|
-
|
|
34009
|
-
|
|
34010
|
-
|
|
34011
|
-
|
|
34012
|
-
|
|
34013
|
-
|
|
34014
|
-
|
|
34015
|
-
|
|
34016
|
-
|
|
34017
|
-
|
|
34018
|
-
|
|
34019
|
-
style: {
|
|
34020
|
-
left: `calc(50% + ${canvasToScreen({
|
|
34021
|
-
x: displayBox.x,
|
|
34022
|
-
y: displayBox.y
|
|
34023
|
-
}, viewport.zoom, viewport.pan).x}px)`,
|
|
34024
|
-
top: `calc(50% + ${toolbarTop(displayBox)}px)`
|
|
34025
|
-
}
|
|
34026
|
-
}),
|
|
34027
|
-
textToolbarTarget !== null && displayBox !== null && /* @__PURE__ */ jsx(CanvasTextToolbar, {
|
|
34028
|
-
id: textToolbarTarget.id,
|
|
34029
|
-
fontFamily: textToolbarTarget.fontFamily,
|
|
34030
|
-
textColor: textToolbarTarget.textColor,
|
|
34031
|
-
textStyle: textToolbarTarget.textStyle,
|
|
34032
|
-
fontSize: textToolbarTarget.fontSize,
|
|
34033
|
-
textAlign: textToolbarTarget.textAlign,
|
|
34034
|
-
zStand: textToolbarTarget.zStand,
|
|
34035
|
-
style: {
|
|
34036
|
-
left: `calc(50% + ${canvasToScreen({
|
|
34037
|
-
x: displayBox.x,
|
|
34038
|
-
y: displayBox.y
|
|
34039
|
-
}, viewport.zoom, viewport.pan).x}px)`,
|
|
34040
|
-
top: `calc(50% + ${toolbarTop(displayBox)}px)`
|
|
34041
|
-
}
|
|
34700
|
+
textToolbarTarget !== null && displayBox !== null && /* @__PURE__ */ jsx(CanvasToolbarAnchor, {
|
|
34701
|
+
centerX: boxCenterX(displayBox),
|
|
34702
|
+
boxTop: boxTop(displayBox),
|
|
34703
|
+
boxBottom: boxBottom(displayBox),
|
|
34704
|
+
container: containerSize,
|
|
34705
|
+
children: /* @__PURE__ */ jsx(CanvasTextToolbar, {
|
|
34706
|
+
id: textToolbarTarget.id,
|
|
34707
|
+
fontFamily: textToolbarTarget.fontFamily,
|
|
34708
|
+
textColor: textToolbarTarget.textColor,
|
|
34709
|
+
textStyle: textToolbarTarget.textStyle,
|
|
34710
|
+
fontSize: textToolbarTarget.fontSize,
|
|
34711
|
+
textAlign: textToolbarTarget.textAlign,
|
|
34712
|
+
zStand: textToolbarTarget.zStand
|
|
34713
|
+
})
|
|
34042
34714
|
}),
|
|
34043
|
-
arrangeToolbarTarget !== null && displayBox !== null && /* @__PURE__ */ jsx(
|
|
34044
|
-
|
|
34045
|
-
|
|
34046
|
-
|
|
34047
|
-
|
|
34048
|
-
|
|
34049
|
-
|
|
34050
|
-
|
|
34051
|
-
|
|
34052
|
-
|
|
34053
|
-
}
|
|
34715
|
+
arrangeToolbarTarget !== null && displayBox !== null && /* @__PURE__ */ jsx(CanvasToolbarAnchor, {
|
|
34716
|
+
centerX: boxCenterX(displayBox),
|
|
34717
|
+
boxTop: boxTop(displayBox),
|
|
34718
|
+
boxBottom: boxBottom(displayBox),
|
|
34719
|
+
container: containerSize,
|
|
34720
|
+
children: /* @__PURE__ */ jsx(ZOrderToolbar, {
|
|
34721
|
+
id: arrangeToolbarTarget.id,
|
|
34722
|
+
kind: arrangeToolbarTarget.kind,
|
|
34723
|
+
zStand: arrangeToolbarTarget.zStand
|
|
34724
|
+
})
|
|
34054
34725
|
}),
|
|
34055
34726
|
/* @__PURE__ */ jsx(ZoomControls, {
|
|
34056
34727
|
zoom: viewport.zoom,
|
|
@@ -34144,15 +34815,9 @@ function ConnectorLabelEdit({ id, mid, stroke, width, lineStyle, label, onClose
|
|
|
34144
34815
|
* previews) + the screen-space chrome over the world (the marquee, the
|
|
34145
34816
|
* handles, the toolbars, the dock). The body (CanvasView) stands the
|
|
34146
34817
|
* session's hooks + the target's reads; this component is the paint. */
|
|
34147
|
-
function CanvasSurface({ containerRef, cursor, viewport, handlers, pageContext, pageChildren, pageCardSelected, pageCardDisplayStyle, surfaces, culling, storeSelection, blocks, viewMode, targets, beginEndpointDrag, onResetZoom, onFit }) {
|
|
34818
|
+
function CanvasSurface({ containerRef, containerSize, cursor, viewport, handlers, pageContext, pageChildren, pageCardSelected, pageCardDisplayStyle, surfaces, culling, storeSelection, blocks, viewMode, targets, beginEndpointDrag, beginWaypointDrag, addConnectorWaypoint, onResetZoom, onFit }) {
|
|
34148
34819
|
const { t } = useTranslation("canvas");
|
|
34149
34820
|
const { handleTarget, displayBox, multiSelectionBox, shapeToolbarTarget, textToolbarTarget, arrangeToolbarTarget, connectorToolbarTarget, connectorLabelTarget, selectedConnectorHandles, previewFrom, previewSnap, previewEnd, hoverSnapPoint } = targets;
|
|
34150
|
-
const onEndpointPointerDown = (which) => (event) => {
|
|
34151
|
-
if (connectorToolbarTarget === null) return;
|
|
34152
|
-
event.stopPropagation();
|
|
34153
|
-
event.preventDefault();
|
|
34154
|
-
beginEndpointDrag(connectorToolbarTarget.id, which, event.pointerId, event.clientX, event.clientY);
|
|
34155
|
-
};
|
|
34156
34821
|
return /* @__PURE__ */ jsxs("div", {
|
|
34157
34822
|
"data-slot": "docblocks/canvas-view",
|
|
34158
34823
|
ref: containerRef,
|
|
@@ -34228,6 +34893,7 @@ function CanvasSurface({ containerRef, cursor, viewport, handlers, pageContext,
|
|
|
34228
34893
|
})
|
|
34229
34894
|
]
|
|
34230
34895
|
}), /* @__PURE__ */ jsx(CanvasScreenChrome, {
|
|
34896
|
+
containerSize,
|
|
34231
34897
|
viewport,
|
|
34232
34898
|
blocks,
|
|
34233
34899
|
surfaces,
|
|
@@ -34246,7 +34912,9 @@ function CanvasSurface({ containerRef, cursor, viewport, handlers, pageContext,
|
|
|
34246
34912
|
textToolbarTarget,
|
|
34247
34913
|
arrangeToolbarTarget
|
|
34248
34914
|
},
|
|
34249
|
-
|
|
34915
|
+
beginEndpointDrag,
|
|
34916
|
+
beginWaypointDrag,
|
|
34917
|
+
addConnectorWaypoint,
|
|
34250
34918
|
onResetZoom,
|
|
34251
34919
|
onFit
|
|
34252
34920
|
})]
|
|
@@ -34412,8 +35080,7 @@ function computeCulling(visible, surfaces, blocks, keep) {
|
|
|
34412
35080
|
* the surfaces' children's memo holds), the fresh set over the content's
|
|
34413
35081
|
* change (an item enters / leaves the viewport band).
|
|
34414
35082
|
*/
|
|
34415
|
-
function useCanvasCulling(
|
|
34416
|
-
const size = useContainerSize(containerRef);
|
|
35083
|
+
function useCanvasCulling(size, viewport, surfaces, blocks) {
|
|
34417
35084
|
const measured = size.width > 0 && size.height > 0 ? size : FALLBACK_SIZE;
|
|
34418
35085
|
const visible = visibleWorldRectOf(viewport.zoom, viewport.pan, measured, 300);
|
|
34419
35086
|
const cacheRef = useRef(null);
|
|
@@ -34580,7 +35247,8 @@ function handleCanvasEscape({ viewport, selection, doc, sessionRef }) {
|
|
|
34580
35247
|
return "stop";
|
|
34581
35248
|
}
|
|
34582
35249
|
if (viewport.connectorEndpoint !== null) {
|
|
34583
|
-
viewport.
|
|
35250
|
+
if (viewport.connectorEndpoint.which === "waypoint") viewport.cancelConnectorWaypoint();
|
|
35251
|
+
else viewport.cancelConnectorEndpoint();
|
|
34584
35252
|
return "stop";
|
|
34585
35253
|
}
|
|
34586
35254
|
if (viewport.resizePreview !== null) {
|
|
@@ -35303,6 +35971,16 @@ function chipDoubleClick(ctx, id, event) {
|
|
|
35303
35971
|
function createContentDoubleClick(ctx) {
|
|
35304
35972
|
return (event) => {
|
|
35305
35973
|
if (ctx.viewMode) return;
|
|
35974
|
+
const waypointDot = pointElementOf(event) instanceof Element ? pointElementOf(event).closest("[data-connector-waypoint]") : null;
|
|
35975
|
+
if (waypointDot !== null) {
|
|
35976
|
+
const connectorId = waypointDot.getAttribute("data-connector-waypoint-id");
|
|
35977
|
+
const index = Number(waypointDot.getAttribute("data-connector-waypoint"));
|
|
35978
|
+
if (connectorId !== null && Number.isInteger(index)) {
|
|
35979
|
+
event.preventDefault();
|
|
35980
|
+
ctx.viewport.removeConnectorWaypoint(connectorId, index);
|
|
35981
|
+
return;
|
|
35982
|
+
}
|
|
35983
|
+
}
|
|
35306
35984
|
if (event.altKey) return;
|
|
35307
35985
|
const touchStep = ctx.viewport.cycleIndicator;
|
|
35308
35986
|
if (touchStep !== null && ctx.viewport.cycle?.pointerType === "touch") {
|
|
@@ -35679,6 +36357,19 @@ function beginEndpointDrag(ctx, connectorId, which, pointerId, clientX, clientY)
|
|
|
35679
36357
|
y: clientY - rect.top - rect.height / 2
|
|
35680
36358
|
}, clientX, clientY);
|
|
35681
36359
|
}
|
|
36360
|
+
/** The waypoint handle's press (the selected line's bend dot): the endpoint
|
|
36361
|
+
* handle's contract — the container keeps the pointer, the release reads the
|
|
36362
|
+
* session. */
|
|
36363
|
+
function beginWaypointDrag(ctx, connectorId, index, pointerId, clientX, clientY) {
|
|
36364
|
+
const container = ctx.containerRef.current;
|
|
36365
|
+
if (container === null) return;
|
|
36366
|
+
container.setPointerCapture?.(pointerId);
|
|
36367
|
+
const rect = container.getBoundingClientRect();
|
|
36368
|
+
ctx.viewport.beginConnectorWaypoint(connectorId, index, {
|
|
36369
|
+
x: clientX - rect.left - rect.width / 2,
|
|
36370
|
+
y: clientY - rect.top - rect.height / 2
|
|
36371
|
+
}, clientX, clientY);
|
|
36372
|
+
}
|
|
35682
36373
|
/** The pen's press: the live stroke's begin (the first point is the press's canvas point). */
|
|
35683
36374
|
function penPress(ctx, event, point) {
|
|
35684
36375
|
if (ctx.viewport.activeTool !== "pen") return false;
|
|
@@ -35770,6 +36461,14 @@ function panPress(ctx, event) {
|
|
|
35770
36461
|
return true;
|
|
35771
36462
|
}
|
|
35772
36463
|
// src/canvas/canvas-view/canvas-session-release.ts
|
|
36464
|
+
/** Whether the marquee's rect reaches the container's border band: the
|
|
36465
|
+
* box's own rect minus the inset band (the press hit's parity — a
|
|
36466
|
+
* container's interior stands transparent to what lies beneath, so a
|
|
36467
|
+
* marquee drawn in the interior selects the contents, never the box). */
|
|
36468
|
+
function sweepsBorderBand(rect, box) {
|
|
36469
|
+
if (!rectsIntersect(rect, box)) return false;
|
|
36470
|
+
return !(rect.left >= box.left + 6 && rect.left + rect.width <= box.left + box.width - 6 && rect.top >= box.top + 6 && rect.top + rect.height <= box.top + box.height - 6);
|
|
36471
|
+
}
|
|
35773
36472
|
/** The release handlers (the pointerup's commits + the session's drop + the pointer cancel). The OS / browser takeover (a pointer cancel, a lost capture, a button-less move over a surviving session) drops every in-flight session: the move's preview would otherwise stand until the next release, and that release would commit a stale setGeometry. The no-session calls are no-ops (the state stays, no re-render). */
|
|
35774
36473
|
function createReleaseHandlers(ctx) {
|
|
35775
36474
|
const dropCanvasSessions = () => {
|
|
@@ -35781,6 +36480,7 @@ function createReleaseHandlers(ctx) {
|
|
|
35781
36480
|
ctx.viewport.cancelMove();
|
|
35782
36481
|
ctx.viewport.cancelResize();
|
|
35783
36482
|
ctx.viewport.cancelConnectorEndpoint();
|
|
36483
|
+
ctx.viewport.cancelConnectorWaypoint();
|
|
35784
36484
|
ctx.viewport.setMarquee(null);
|
|
35785
36485
|
ctx.viewport.setPenPoints([]);
|
|
35786
36486
|
};
|
|
@@ -35788,7 +36488,8 @@ function createReleaseHandlers(ctx) {
|
|
|
35788
36488
|
ctx.cardPressRef.current = false;
|
|
35789
36489
|
if (ctx.viewport.connectorEndpoint !== null) {
|
|
35790
36490
|
ctx.cycleStepRef.current = null;
|
|
35791
|
-
ctx.viewport.
|
|
36491
|
+
if (ctx.viewport.connectorEndpoint.which === "waypoint") ctx.viewport.endConnectorWaypoint(event.clientX, event.clientY);
|
|
36492
|
+
else ctx.viewport.endConnectorEndpoint(event.clientX, event.clientY);
|
|
35792
36493
|
return;
|
|
35793
36494
|
}
|
|
35794
36495
|
if (ctx.viewport.activeTool === "connector" && (ctx.viewport.pendingConnector !== null || ctx.viewport.pendingFree !== null)) {
|
|
@@ -35863,26 +36564,32 @@ function createReleaseHandlers(ctx) {
|
|
|
35863
36564
|
const id = el.getAttribute("data-block-id");
|
|
35864
36565
|
if (id === null || ctx.blocks[id]?.type === "connector") continue;
|
|
35865
36566
|
const box = el.getBoundingClientRect();
|
|
35866
|
-
|
|
36567
|
+
const itemRect = {
|
|
35867
36568
|
left: box.left - containerRect.left - center.x,
|
|
35868
36569
|
top: box.top - containerRect.top - center.y,
|
|
35869
36570
|
width: box.width,
|
|
35870
36571
|
height: box.height
|
|
35871
|
-
}
|
|
36572
|
+
};
|
|
36573
|
+
const type = ctx.blocks[id]?.type;
|
|
36574
|
+
if (type === "group" || type === "frame" ? sweepsBorderBand(rect, itemRect) : rectsIntersect(rect, itemRect)) ids.push(id);
|
|
35872
36575
|
}
|
|
36576
|
+
const swept = new Set(ids);
|
|
36577
|
+
const picked = ids.filter((id) => {
|
|
36578
|
+
return !(ctx.blocks[id]?.type === "group" ? ctx.blocks[id]?.attrs?.members ?? [] : []).some((member) => member !== id && swept.has(member));
|
|
36579
|
+
});
|
|
35873
36580
|
if (additive) {
|
|
35874
36581
|
const sel = ctx.selection.view?.get();
|
|
35875
36582
|
const base = sel?.kind === "blocks" ? sel.ids : [];
|
|
35876
|
-
const merged = [...base, ...
|
|
36583
|
+
const merged = [...base, ...picked.filter((id) => !base.includes(id))];
|
|
35877
36584
|
ctx.selection.view?.set(merged.length > 0 ? {
|
|
35878
36585
|
kind: "blocks",
|
|
35879
36586
|
ids: merged,
|
|
35880
36587
|
anchorId: base.length > 0 && sel?.kind === "blocks" ? sel.anchorId : merged[0]
|
|
35881
36588
|
} : { kind: "none" });
|
|
35882
|
-
} else ctx.selection.view?.set(
|
|
36589
|
+
} else ctx.selection.view?.set(picked.length > 0 ? {
|
|
35883
36590
|
kind: "blocks",
|
|
35884
|
-
ids,
|
|
35885
|
-
anchorId:
|
|
36591
|
+
ids: picked,
|
|
36592
|
+
anchorId: picked[0]
|
|
35886
36593
|
} : { kind: "none" });
|
|
35887
36594
|
ctx.containerRef.current?.focus();
|
|
35888
36595
|
}
|
|
@@ -35940,7 +36647,10 @@ function useCanvasSessions(deps) {
|
|
|
35940
36647
|
}
|
|
35941
36648
|
ctx.viewport.moveDrag(event.clientX, event.clientY);
|
|
35942
36649
|
ctx.viewport.resizeDrag(event.clientX, event.clientY, event.shiftKey);
|
|
35943
|
-
if (ctx.viewport.connectorEndpoint !== null)
|
|
36650
|
+
if (ctx.viewport.connectorEndpoint !== null) {
|
|
36651
|
+
if (ctx.viewport.connectorEndpoint.which === "waypoint") ctx.viewport.moveConnectorWaypoint(ctx.centerRelativePoint(event));
|
|
36652
|
+
else ctx.viewport.moveConnectorEndpoint(ctx.centerRelativePoint(event));
|
|
36653
|
+
}
|
|
35944
36654
|
const session = ctx.sessionRef.current;
|
|
35945
36655
|
if (session === null) return;
|
|
35946
36656
|
const point = ctx.centerRelativePoint(event);
|
|
@@ -35979,6 +36689,7 @@ function useCanvasSessions(deps) {
|
|
|
35979
36689
|
onPointerCancel,
|
|
35980
36690
|
dropCanvasSessions,
|
|
35981
36691
|
beginEndpointDrag: (connectorId, which, pointerId, clientX, clientY) => beginEndpointDrag(ctx, connectorId, which, pointerId, clientX, clientY),
|
|
36692
|
+
beginWaypointDrag: (connectorId, index, pointerId, clientX, clientY) => beginWaypointDrag(ctx, connectorId, index, pointerId, clientX, clientY),
|
|
35982
36693
|
onContentDoubleClick,
|
|
35983
36694
|
onChipPress: (id, event) => chipPress(ctx, event, id),
|
|
35984
36695
|
onChipDoubleClick: (id, event) => chipDoubleClick(ctx, id, event)
|
|
@@ -36281,10 +36992,11 @@ function CanvasView() {
|
|
|
36281
36992
|
viewport,
|
|
36282
36993
|
rootBlockId
|
|
36283
36994
|
});
|
|
36284
|
-
const
|
|
36995
|
+
const containerSize = useContainerSize(containerRef);
|
|
36996
|
+
const culling = useCanvasCulling(containerSize, viewport, surfaces, blocks);
|
|
36285
36997
|
if (root === void 0) return null;
|
|
36286
36998
|
const isEditingSurface = (target) => target instanceof Element && target.closest("[contenteditable=\"true\"], input, textarea") !== null;
|
|
36287
|
-
const { onPointerDown, onPointerMove, onPointerUp, onMouseDown, onPointerCancel, dropCanvasSessions, beginEndpointDrag, onContentDoubleClick, onChipPress, onChipDoubleClick } = useCanvasSessions({
|
|
36999
|
+
const { onPointerDown, onPointerMove, onPointerUp, onMouseDown, onPointerCancel, dropCanvasSessions, beginEndpointDrag, beginWaypointDrag, onContentDoubleClick, onChipPress, onChipDoubleClick } = useCanvasSessions({
|
|
36288
37000
|
containerRef,
|
|
36289
37001
|
sessionRef,
|
|
36290
37002
|
lastPointerRef,
|
|
@@ -36327,6 +37039,7 @@ function CanvasView() {
|
|
|
36327
37039
|
setCanvasTextEditingId: viewport.setCanvasTextEditing,
|
|
36328
37040
|
children: /* @__PURE__ */ jsx(CanvasSurface, {
|
|
36329
37041
|
containerRef,
|
|
37042
|
+
containerSize,
|
|
36330
37043
|
cursor,
|
|
36331
37044
|
viewport,
|
|
36332
37045
|
handlers: {
|
|
@@ -36367,6 +37080,8 @@ function CanvasView() {
|
|
|
36367
37080
|
hoverSnapPoint
|
|
36368
37081
|
},
|
|
36369
37082
|
beginEndpointDrag,
|
|
37083
|
+
beginWaypointDrag,
|
|
37084
|
+
addConnectorWaypoint: viewport.addConnectorWaypoint,
|
|
36370
37085
|
onResetZoom: () => viewport.setZoom(1),
|
|
36371
37086
|
onFit
|
|
36372
37087
|
})
|
|
@@ -39304,6 +40019,65 @@ function CoverTintController({ cardRef }) {
|
|
|
39304
40019
|
}, [cardRef, color]);
|
|
39305
40020
|
return null;
|
|
39306
40021
|
}
|
|
40022
|
+
// src/editing/EmptyPageActivation.tsx
|
|
40023
|
+
/**
|
|
40024
|
+
* The empty page's input stand: a local contenteditable that stands over an
|
|
40025
|
+
* empty page (the full document, the page view, the edit mode) so the page
|
|
40026
|
+
* has a visible, focusable caret home while the root holds no blocks. The
|
|
40027
|
+
* FIRST gesture (the mousedown over the stand) materializes the first
|
|
40028
|
+
* paragraph (one transaction, one undo step, one wire update) and seats the
|
|
40029
|
+
* caret in it; from there the real block's input path takes over (the normal
|
|
40030
|
+
* page surface's commit). Nothing is written while the stand merely stands —
|
|
40031
|
+
* an untouched document stands no version.
|
|
40032
|
+
*
|
|
40033
|
+
* The first paragraph takes a FRESH id (not the reserved `${docId}-tail`):
|
|
40034
|
+
* the reserved id is the trailing-paragraph guarantee's own stand, and
|
|
40035
|
+
* consuming it here would leave a later non-text tail without its editable
|
|
40036
|
+
* paragraph (the guarantee is a no-op once the reserved block stands). Two
|
|
40037
|
+
* peers' simultaneous first gestures stand one paragraph each — the rare
|
|
40038
|
+
* race converges over the wire to two lines, each peer's text intact.
|
|
40039
|
+
*
|
|
40040
|
+
* The stand's own content is never committed (the store-driven swap renders
|
|
40041
|
+
* the real paragraph the moment one stands, unmounting the stand), so it
|
|
40042
|
+
* stands no input/paste handlers of its own: the page surface dispatches
|
|
40043
|
+
* container-targeted input, and the seat re-targets the caret into the
|
|
40044
|
+
* materialized block's inner on the next frame.
|
|
40045
|
+
*/
|
|
40046
|
+
function EmptyPageActivation() {
|
|
40047
|
+
const { doc, commandPalettePlaceholder } = useEditorContext();
|
|
40048
|
+
const { t: tEditor } = useTranslation("editor");
|
|
40049
|
+
const ref = useRef(null);
|
|
40050
|
+
const materializedRef = useRef(false);
|
|
40051
|
+
const onMouseDown = (event) => {
|
|
40052
|
+
if (materializedRef.current) return;
|
|
40053
|
+
const rootId = doc.meta.id;
|
|
40054
|
+
if (doc.getChildren(rootId).length !== 0) return;
|
|
40055
|
+
const scope = ref.current?.closest("[data-slot=\"docblocks/editor\"]") ?? document;
|
|
40056
|
+
let paragraph = null;
|
|
40057
|
+
try {
|
|
40058
|
+
doc.transact(() => {
|
|
40059
|
+
if (doc.getChildren(rootId).length !== 0) return;
|
|
40060
|
+
paragraph = doc.insertBlock("paragraph", void 0, { parent: rootId });
|
|
40061
|
+
});
|
|
40062
|
+
} catch {
|
|
40063
|
+
return;
|
|
40064
|
+
}
|
|
40065
|
+
if (paragraph === null) return;
|
|
40066
|
+
materializedRef.current = true;
|
|
40067
|
+
event.preventDefault();
|
|
40068
|
+
focusCaretIn(paragraph, 0, scope);
|
|
40069
|
+
};
|
|
40070
|
+
return /* @__PURE__ */ jsx("div", {
|
|
40071
|
+
ref,
|
|
40072
|
+
contentEditable: true,
|
|
40073
|
+
suppressContentEditableWarning: true,
|
|
40074
|
+
spellCheck: false,
|
|
40075
|
+
"data-slot": "docblocks/empty-page",
|
|
40076
|
+
"data-placeholder": commandPalettePlaceholder ?? tEditor("commandPalettePlaceholder"),
|
|
40077
|
+
className: "min-h-(--docblocks-line-box-height) w-full cursor-text outline-none",
|
|
40078
|
+
onMouseDown
|
|
40079
|
+
});
|
|
40080
|
+
}
|
|
39307
40081
|
// src/editing/cross-drag/page-guards.ts
|
|
39308
40082
|
/** The editor root's page-flow mousedown guard (the span model's native
|
|
39309
40083
|
* selection suppression) and the triple press's whole-block select — the
|
|
@@ -41192,7 +41966,8 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
41192
41966
|
const pageRef = useRef(null);
|
|
41193
41967
|
const surfaceMapRef = useRef(null);
|
|
41194
41968
|
if (surfaceMapRef.current === null) surfaceMapRef.current = /* @__PURE__ */ new Map();
|
|
41195
|
-
const
|
|
41969
|
+
const emptyStand = rootBlockId === doc.meta.id && !viewMode;
|
|
41970
|
+
const surface = usePageSurfaceDispatch(pageRef, doc, surfaceMapRef.current, emptyStand);
|
|
41196
41971
|
const { nodesById, collapsedRowKeys } = usePageSequence({
|
|
41197
41972
|
store,
|
|
41198
41973
|
rootChildren,
|
|
@@ -41293,18 +42068,22 @@ function Editor({ view = "page", formatPalette = FORMAT_PALETTE }) {
|
|
|
41293
42068
|
onInput: surface.onInput,
|
|
41294
42069
|
onPaste: surface.onPaste,
|
|
41295
42070
|
className: "\n mx-auto w-full max-w-(--docblocks-page-column-max-width) px-(--docblocks-page-padding-x)\n ",
|
|
41296
|
-
children: [
|
|
41297
|
-
|
|
41298
|
-
|
|
41299
|
-
|
|
41300
|
-
|
|
41301
|
-
|
|
41302
|
-
|
|
41303
|
-
|
|
41304
|
-
|
|
41305
|
-
|
|
41306
|
-
|
|
41307
|
-
|
|
42071
|
+
children: [
|
|
42072
|
+
/* @__PURE__ */ jsx(AttributesPanel, {}),
|
|
42073
|
+
/* @__PURE__ */ jsx(RowList, {
|
|
42074
|
+
order,
|
|
42075
|
+
nodesById,
|
|
42076
|
+
layoutSlide: layoutSlide || draggingKey !== null,
|
|
42077
|
+
draggingKey,
|
|
42078
|
+
previewIndent,
|
|
42079
|
+
animated: enterGate.current,
|
|
42080
|
+
onReorder: onRowReorder,
|
|
42081
|
+
onDragStart: onRowDragStart,
|
|
42082
|
+
onDragMove: onRowDragMove,
|
|
42083
|
+
onDragEnd: onRowDragEnd
|
|
42084
|
+
}),
|
|
42085
|
+
rootBlockId === doc.meta.id && !viewMode && rootChildren.length === 0 ? /* @__PURE__ */ jsx(EmptyPageActivation, {}) : null
|
|
42086
|
+
]
|
|
41308
42087
|
})
|
|
41309
42088
|
}), viewMode ? null : /* @__PURE__ */ jsx(PresenceCaretOverlay, { rootRef })]
|
|
41310
42089
|
})
|