Skip to content

Commit d63ae90

Browse files
committed
Encapsulate anchor pass records
The anchor runtime now exposes only the questions that features ask — `isMarked`, `placedAt`, and a snapshot from `pendingMarkParts` — instead of direct access to the internal maps and arrays. This prevents accidental second writers through the entrypoint and clarifies the anchor's public interface.
1 parent db1100e commit d63ae90

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎plugins/leaf/skills/leaf/CLAUDE.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,9 @@ element outlines, and the open composer's pending mark. It clears and paints
938938
through the same composed-tree helpers, then records exactly what it drew in
939939
`marked`, `pendingMarks`, and `pendingOutline`. Other features consult those
940940
records rather than looking for arbitrary DOM paint.
941+
The anchor runtime exposes only the questions those features ask — `isMarked`,
942+
`placedAt`, and a snapshot from `pendingMarkParts` — so the pass-owned maps and
943+
arrays cannot acquire a second writer through the entrypoint.
941944

942945
The same pass answers a second question and records it apart. `placed` is where
943946
each thread's passage lands in this version; `marked` is what was drawn for it.

‎plugins/leaf/skills/leaf/assets/leaf.js‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ const {
14521452
paintStanding: (...args) => conversationRuntime.paintStanding(...args),
14531453
panel,
14541454
panelCovers,
1455-
pendingMarks: () => anchorRuntime.pendingMarks,
1455+
pendingMarkParts,
14561456
pointerAt,
14571457
reactionTokens: () => reactionTokens(),
14581458
reactionsOn: (anchor) => conversationRuntime.reactionsOn(anchor),
@@ -3339,6 +3339,15 @@ function refreshHover(...args) {
33393339
function pageShifted(...args) {
33403340
return anchorRuntime.pageShifted(...args);
33413341
}
3342+
function isMarked(...args) {
3343+
return anchorRuntime.isMarked(...args);
3344+
}
3345+
function placedAt(...args) {
3346+
return anchorRuntime.placedAt(...args);
3347+
}
3348+
function pendingMarkParts(...args) {
3349+
return anchorRuntime.pendingMarkParts(...args);
3350+
}
33423351

33433352
const passageRuntime = createPassages({
33443353
PAGE_PAINT_ATTRIBUTE,
@@ -3501,7 +3510,7 @@ conversationRuntime = createConversation({
35013510
generalRow,
35023511
highlightBlocks,
35033512
inChrome,
3504-
isMarked: (id) => marked.has(id),
3513+
isMarked,
35053514
itemSays,
35063515
itemWord,
35073516
keys,
@@ -3521,7 +3530,7 @@ conversationRuntime = createConversation({
35213530
paintKeys,
35223531
panelIsOpen: () => panelOpen,
35233532
panelTitle,
3524-
placedAt: (id) => placed.get(id),
3533+
placedAt,
35253534
post,
35263535
PRESS,
35273536
quietSince,
@@ -3626,7 +3635,7 @@ anchorRuntime = createAnchors({
36263635
withdraw,
36273636
worksSelector: WORKS,
36283637
});
3629-
const { VIEW_KEY, ITEM, NOTE, marked, placed } = anchorRuntime;
3638+
const { VIEW_KEY, ITEM, NOTE } = anchorRuntime;
36303639

36313640
createConversationLanding({ scrollToThread });
36323641
createConversationBox({ post, renderPanel, showToast, wireInput });

‎plugins/leaf/skills/leaf/assets/runtime/anchors.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,9 @@ export function createAnchors(dependencies) {
13211321
visualPartLabel,
13221322
resolveAnchor,
13231323
NOTE,
1324-
marked,
1325-
placed,
1324+
isMarked: (id) => marked.has(id),
1325+
placedAt: (id) => placed.get(id),
1326+
pendingMarkParts: () => [...pendingMarks],
13261327
refreshAim,
13271328
dockSeats,
13281329
paintAnchors,
@@ -1333,9 +1334,6 @@ export function createAnchors(dependencies) {
13331334
paintStanding,
13341335
refreshHover,
13351336
pageShifted,
1336-
get pendingMarks() {
1337-
return pendingMarks;
1338-
},
13391337
};
13401338
publishedAnchors = anchors;
13411339
return anchors;

‎plugins/leaf/skills/leaf/assets/runtime/composing/surface.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function createSelectionSurface({
3030
panel,
3131
panelCovers,
3232
paintStanding,
33-
pendingMarks,
33+
pendingMarkParts,
3434
pointerAt,
3535
reactionTokens,
3636
reactionsOn,
@@ -104,7 +104,8 @@ export function createSelectionSurface({
104104
// better spot.
105105
function placeComposer(left, top) {
106106
place(composer, left, top);
107-
const rects = pendingMarks().flatMap((where) =>
107+
const marks = pendingMarkParts();
108+
const rects = marks.flatMap((where) =>
108109
where instanceof Range
109110
? [...where.getClientRects()]
110111
: [where.getBoundingClientRect()],
@@ -132,7 +133,7 @@ export function createSelectionSurface({
132133
// one object, so a box standing anywhere on it is a box between them and the thing they
133134
// are writing about. ⌥-click made that plain by opening the composer under the pointer,
134135
// which is by definition inside what was clicked.
135-
const whole = pendingMarks().some((where) => where instanceof Element);
136+
const whole = marks.some((where) => where instanceof Element);
136137
const touching = (r) =>
137138
r.left < box.right &&
138139
box.left < r.right &&

0 commit comments

Comments
 (0)