@liminis/editor 0.1.1 → 0.2.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/README.md +126 -14
- package/dist/annotations/types.d.ts +16 -0
- package/dist/app/App.d.ts +1 -1
- package/dist/app/App.js +3 -3
- package/dist/app/editor/AnchorScrollPlugin.js +2 -34
- package/dist/app/editor/AnnotationSurface.js +2 -1
- package/dist/app/editor/CorrectionPanelPlugin.js +10 -10
- package/dist/app/editor/DocumentOutline.d.ts +17 -0
- package/dist/app/editor/DocumentOutline.js +32 -0
- package/dist/app/editor/DragHandlePlugin.js +1 -1
- package/dist/app/editor/Editor.d.ts +10 -1
- package/dist/app/editor/Editor.js +3 -2
- package/dist/app/editor/OutlinePlugin.d.ts +14 -0
- package/dist/app/editor/OutlinePlugin.js +133 -0
- package/dist/app/editor/SelectionContextMenuPlugin.js +4 -4
- package/dist/app/editor/annotation-marks.d.ts +20 -0
- package/dist/app/editor/annotation-marks.js +40 -0
- package/dist/app/editor/documentOutlineHandle.d.ts +87 -0
- package/dist/app/editor/documentOutlineHandle.js +86 -0
- package/dist/app/editor/nodes/C4Component.js +6 -6
- package/dist/app/editor/nodes/DiagramContextMenu.js +5 -5
- package/dist/app/editor/scrollContainer.d.ts +18 -0
- package/dist/app/editor/scrollContainer.js +47 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/markdown/stringify.js +65 -0
- package/dist/styles.css +342 -221
- package/docs/decisions/adr-085.md +166 -0
- package/docs/decisions/adr-086.md +147 -0
- package/docs/decisions/adr-087.md +216 -0
- package/docs/decisions/adr-088.md +136 -0
- package/docs/decisions/adr-089.md +121 -0
- package/docs/editor-api.md +53 -1
- package/package.json +6 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# ADR-089: Existing-Mark Geometry (`getMarkRects`) Lives on `AnnotationEditorHandle`, Is Viewport-Relative, and Is Pull-Only
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-08-19
|
|
4
|
+
**Status:** Accepted
|
|
5
|
+
**Supersedes:** none
|
|
6
|
+
**Amends:** none
|
|
7
|
+
**Issue:** #73 (verveguy/liminis-editor)
|
|
8
|
+
|
|
9
|
+
## Context
|
|
10
|
+
|
|
11
|
+
ADR-088 (issue #69, the Document Outline widget) considered and declined to
|
|
12
|
+
add a new `EditorHostServices` member for scroll-container/element-rect data,
|
|
13
|
+
naming Zusammen [#126](https://github.com/verveguy/zusammen/issues/126) —
|
|
14
|
+
"margin comments aligned to text" — as the not-yet-planned consumer that
|
|
15
|
+
would want the same positional primitive, and deliberately deferred the
|
|
16
|
+
question until #126 "does start." That is now: #126 needs a host to look up
|
|
17
|
+
where an *existing* annotation's mark currently renders, so it can position a
|
|
18
|
+
margin note against the annotated text. Today `AnnotationEditorHandle`
|
|
19
|
+
exposes `removeMarksForAnnotation` and `collectLiveAnchorSnapshots`
|
|
20
|
+
(document-offset ranges, not screen geometry) for live marks, and
|
|
21
|
+
`AnnotationCreateEvent.rect` delivers a one-shot `DOMRect` only at the moment
|
|
22
|
+
an annotation is created — nothing lets a host ask "where is annotation X
|
|
23
|
+
*right now*."
|
|
24
|
+
|
|
25
|
+
Three questions were explicitly left open by the issue's spec for this
|
|
26
|
+
decision:
|
|
27
|
+
|
|
28
|
+
1. **Surface placement** — extend `AnnotationEditorHandle` (mechanics-side,
|
|
29
|
+
matching its two existing members) or add a new `EditorHostServices`
|
|
30
|
+
member (host-seam-side, the option ADR-088 deferred)?
|
|
31
|
+
2. **Coordinate space** — raw viewport-relative `getBoundingClientRect()`, or
|
|
32
|
+
rects adjusted relative to the editor's scroll container?
|
|
33
|
+
3. **Staleness model** — a pull-based snapshot the host re-requests, or a
|
|
34
|
+
subscription/observer the package pushes updates through?
|
|
35
|
+
|
|
36
|
+
## Decision
|
|
37
|
+
|
|
38
|
+
**`getMarkRects(annotationIds?)` is added to `AnnotationEditorHandle`, not to
|
|
39
|
+
`EditorHostServices`.** It keeps every live-mark operation — remove, snapshot,
|
|
40
|
+
and now geometry — on the one seam a host already holds a reference to for
|
|
41
|
+
annotations, rather than splitting positional queries onto a second surface
|
|
42
|
+
for no functional reason. This does not reopen ADR-088: that decision was
|
|
43
|
+
about the *outline widget's* scroll-container discovery (`AnchorScrollPlugin`
|
|
44
|
+
/ `scrollContainer.ts`), which stays exactly as it is. `getMarkRects` needs
|
|
45
|
+
none of that machinery — it resolves annotation ids to `MarkNode` elements
|
|
46
|
+
(already solved, and already tested, by `markElementsByAnnotationId`) and
|
|
47
|
+
reads each element's own `getBoundingClientRect()`.
|
|
48
|
+
|
|
49
|
+
**Rects are raw, viewport-relative `getBoundingClientRect()` output — no
|
|
50
|
+
scroll-container adjustment.** This matches the only existing precedent for
|
|
51
|
+
rect delivery in this package, `AnnotationCreateEvent.rect`
|
|
52
|
+
(`AnnotationPlugin.tsx`), which is also unadjusted. A host that wants
|
|
53
|
+
scroll-container-relative coordinates can subtract that container's own
|
|
54
|
+
`getBoundingClientRect()` origin itself — exactly what
|
|
55
|
+
`AnchorScrollPlugin.tsx` already does internally for its own purposes — so
|
|
56
|
+
nothing is lost by not building that adjustment into the package.
|
|
57
|
+
|
|
58
|
+
**`getMarkRects` is pull-only: a fresh snapshot computed at call time, with no
|
|
59
|
+
subscription or observer.** `getBoundingClientRect()` is inherently a live
|
|
60
|
+
query, so a pull-based method trivially satisfies "no caching, no staleness"
|
|
61
|
+
with zero extra machinery. ADR-088 declined to add a host-seam member for
|
|
62
|
+
positional data at all and deferred to "when #126 starts" — it did not
|
|
63
|
+
direct that the eventual mechanism be a subscription, only that the simpler
|
|
64
|
+
pull-based need (this issue's actual scope) be resolved once a real consumer
|
|
65
|
+
existed. Building a push/subscribe model now, before any consumer has asked
|
|
66
|
+
for continuous updates rather than an on-demand read, would be the same kind
|
|
67
|
+
of speculative, untested surface ADR-088 itself avoided.
|
|
68
|
+
|
|
69
|
+
Built directly on `markElementsByAnnotationId(editor, ids)`: for a multi-block
|
|
70
|
+
annotation (several sibling `MarkNode`s sharing one id), the result is one
|
|
71
|
+
`DOMRect` per constituent element, in document order — the host, not the
|
|
72
|
+
package, decides how to combine them. An id with no currently live mark is
|
|
73
|
+
simply absent from the result map, never a thrown error. Two ids can report
|
|
74
|
+
an identical rect when their marks share one `MarkNode` (overlapping
|
|
75
|
+
annotations) — expected, and documented on the method itself so a host does
|
|
76
|
+
not mistake it for a bug.
|
|
77
|
+
|
|
78
|
+
## Consequences
|
|
79
|
+
|
|
80
|
+
**Good:**
|
|
81
|
+
|
|
82
|
+
- Zero new architectural surface: `AnnotationEditorHandle` gains a third
|
|
83
|
+
closure over an already-existing, already-tested helper
|
|
84
|
+
(`markElementsByAnnotationId`), the same pattern its two existing members
|
|
85
|
+
already follow.
|
|
86
|
+
- A host that wants scroll-container-relative geometry can derive it trivially
|
|
87
|
+
from the container's own rect; the package is not left guessing which of a
|
|
88
|
+
host's several possible scroll containers is the relevant one.
|
|
89
|
+
- Resolves ADR-088's explicit deferral: #126 now has a concrete, shipped
|
|
90
|
+
primitive rather than a "wait until it's needed" placeholder.
|
|
91
|
+
- No subscription lifecycle (registration, teardown, re-render scheduling) to
|
|
92
|
+
design, test, or maintain until a consumer actually needs push updates.
|
|
93
|
+
|
|
94
|
+
**Bad / accepted:**
|
|
95
|
+
|
|
96
|
+
- A host that wants to keep UI glued to a mark across every scroll/resize/edit
|
|
97
|
+
must poll `getMarkRects` itself (e.g. on a `ResizeObserver`/scroll listener
|
|
98
|
+
it owns) — the package does no observing on the host's behalf. Accepted as
|
|
99
|
+
the deliberately smaller, already-demonstrated scope; a push model can be
|
|
100
|
+
layered on later without displacing this pull-based method.
|
|
101
|
+
- Viewport-relative coordinates mean a host embedding the editor inside a
|
|
102
|
+
transformed or nested scroll container must do its own translation to a
|
|
103
|
+
meaningful local space — no worse than the precedent
|
|
104
|
+
(`AnnotationCreateEvent.rect`) already accepts.
|
|
105
|
+
|
|
106
|
+
**Neutral:**
|
|
107
|
+
|
|
108
|
+
- If a genuinely continuous-update consumer emerges later, it can be added as
|
|
109
|
+
a second, additive API (e.g. a subscribe variant) without touching
|
|
110
|
+
`getMarkRects`'s existing shape or forcing every caller to opt into observer
|
|
111
|
+
bookkeeping they don't need.
|
|
112
|
+
|
|
113
|
+
## References
|
|
114
|
+
|
|
115
|
+
- Issue #73 (this decision)
|
|
116
|
+
- `src/app/editor/annotation-marks.ts` — `getMarkRects`, built on `markElementsByAnnotationId`
|
|
117
|
+
- `src/annotations/types.ts` — `AnnotationEditorHandle`, where `getMarkRects` joins `removeMarksForAnnotation` and `collectLiveAnchorSnapshots`
|
|
118
|
+
- `src/app/editor/AnnotationSurface.tsx` — `AnnotationEditorHandlePlugin`, where the closure is wired
|
|
119
|
+
- `src/app/editor/AnnotationPlugin.tsx` — the existing one-shot `AnnotationCreateEvent.rect`, the precedent for raw viewport-relative rects
|
|
120
|
+
- `docs/decisions/adr-088.md` — the deferred host-seam-vs-package-local question this decision resolves for positional annotation data specifically (ADR-088's own scroll-container-discovery decision is untouched)
|
|
121
|
+
- Zusammen issue [#126](https://github.com/verveguy/zusammen/issues/126) — the consumer this capability unblocks
|
package/docs/editor-api.md
CHANGED
|
@@ -56,9 +56,61 @@ All optional; supplying `annotationKinds` is what turns the mechanism on. See
|
|
|
56
56
|
| `scrollToAnnotation` | `{ id: string; nonce: number } \| null` | Host-driven scroll signal. Bump `nonce` to re-scroll to the same id. |
|
|
57
57
|
| `onCreateAnnotation` | `(event: AnnotationCreateEvent) => void` | Fires when a user creates one via a kind's create affordance. |
|
|
58
58
|
| `onActivateAnnotation` | `(id: string) => void` | Fires when a marker is activated. Your app opens its own panel. |
|
|
59
|
-
| `annotationEditorHandleRef` | `MutableRefObject<AnnotationEditorHandle \| null>` | Imperative handle for the mounted editor's live marks. |
|
|
59
|
+
| `annotationEditorHandleRef` | `MutableRefObject<AnnotationEditorHandle \| null>` | Imperative handle for the mounted editor's live marks: `removeMarksForAnnotation`, `collectLiveAnchorSnapshots`, and `getMarkRects(annotationIds?)` — current on-screen `DOMRect[]` per annotation id (one rect per constituent mark, omitted ids means "every live annotation"), for a host positioning UI against annotated text. |
|
|
60
60
|
| `annotationLogger` | `{ warn(message, ...args): void }` | Injected, so the package never imports a host logger. |
|
|
61
61
|
|
|
62
|
+
## Document outline
|
|
63
|
+
|
|
64
|
+
A live, navigable "on this page" heading list (issue #69) — `<Editor>` owns
|
|
65
|
+
the Lexical document and its heading DOM, so the package derives entries and
|
|
66
|
+
implements scroll-to-heading; you decide whether, where, and how the outline
|
|
67
|
+
is shown.
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { useState } from 'react'
|
|
71
|
+
import { Editor, DocumentOutline, createDocumentOutlineHandle } from '@liminis/editor'
|
|
72
|
+
|
|
73
|
+
function MyEditorWithOutline() {
|
|
74
|
+
// Create once per editor instance — the same object connects the two
|
|
75
|
+
// components. A second editor on the same page needs its own handle.
|
|
76
|
+
const [outlineHandle] = useState(() => createDocumentOutlineHandle())
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div style={{ display: 'flex' }}>
|
|
80
|
+
<Editor
|
|
81
|
+
initialContent={markdown}
|
|
82
|
+
onChange={setMarkdown}
|
|
83
|
+
documentOutlineHandle={outlineHandle}
|
|
84
|
+
/>
|
|
85
|
+
<aside>
|
|
86
|
+
<DocumentOutline handle={outlineHandle} />
|
|
87
|
+
</aside>
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
| Prop | Type | Notes |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `<Editor>`'s `documentOutlineHandle` | `DocumentOutlineHandle` | Connects this editor instance to a `<DocumentOutline>`. Omit it and no outline plugin mounts at all — an outline-less consumer pays nothing for it. |
|
|
96
|
+
| `<DocumentOutline>`'s `handle` | `DocumentOutlineHandle` | The same object passed to `<Editor>`. |
|
|
97
|
+
| `<DocumentOutline>`'s `className` | `string` | Additional class on the outer `<nav>`, for your own placement/layout. |
|
|
98
|
+
|
|
99
|
+
`createDocumentOutlineHandle()` returns the shared controller: a React
|
|
100
|
+
external store (`subscribe`/`getSnapshot`, so `<DocumentOutline>` re-renders
|
|
101
|
+
live as the reader scrolls and the document changes) plus an imperative
|
|
102
|
+
`scrollToHeading(index)`. You never call its methods directly — `<Editor>`
|
|
103
|
+
feeds it, `<DocumentOutline>` reads it.
|
|
104
|
+
|
|
105
|
+
- Entries are H1–H5 headings in document order, indented by level, with
|
|
106
|
+
inline formatting (including inline code) reduced to plain text. Identity
|
|
107
|
+
is by position, not text, so duplicate headings are handled correctly.
|
|
108
|
+
- The active entry — the heading at the top of the viewport — is tracked as
|
|
109
|
+
the reader scrolls and kept visible within the outline itself.
|
|
110
|
+
- `<DocumentOutline>` renders nothing when the document has no headings.
|
|
111
|
+
- Visibility, placement, width-gating, and any collapse/persistence are
|
|
112
|
+
entirely up to you — `<DocumentOutline>` imposes no layout policy.
|
|
113
|
+
|
|
62
114
|
## The host seam
|
|
63
115
|
|
|
64
116
|
The package boundary is drawn at **persistence**: text ranges, marks, rendering
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liminis/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"//publishing": "Publishing is deliberate, never incidental. `private: true` was this package's guard until verveguy/liminis-editor#39 took the publish decision; it is gone because that decision was taken, not because it was tidied away. The guard is now `prepublishOnly` -> scripts/guard-publish.mjs, which refuses unless LIMINIS_ALLOW_PUBLISH=1 is set explicitly. That variable is set at step scope in .github/workflows/publish.yml and nowhere else, so a release is the only path that publishes. Note that `npm publish --dry-run` does NOT report a private package as blocked (npm 10.8.2), which is why the guard is a script rather than a flag.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Lexical-based markdown WYSIWYG editor with mdast round-trip and a host-injection seam",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
],
|
|
19
19
|
"//packageManager": "Not cosmetic. This field used to live in the monorepo root manifest and did not travel with the package, so `pnpm/action-setup` had no version to read and CI failed before installing anything. It is also what pins the pnpm that resolves the lockfile.",
|
|
20
20
|
"packageManager": "pnpm@10.33.0",
|
|
21
|
+
"//engines": "A support statement, not a technical floor. Nothing in the dependency graph needs it — the highest `engines.node` among runtime dependencies is `>= 14.6` (yaml), and 18 of 21 declare none at all. It says which runtimes this package is maintained against: Node 20 reached end of life on 24 March 2026, and 22 and 24 are Active LTS. CI and the release both run 24, so 22 is supported by intent rather than by test — see the note in .github/workflows/ci.yml. Consumers get a warning rather than a hard failure unless they set engine-strict.",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
21
25
|
"type": "module",
|
|
22
26
|
"//entrypoints": "These point at dist/ here, in the checked-in manifest, and must stay that way. They lived under `publishConfig` until 0.1.1 so that in-workspace consumers could resolve raw TypeScript, and that silently shipped a broken 0.1.0: `publishConfig` manifest-field overrides (main/types/exports) are a pnpm and yarn feature, and npm honours `publishConfig` only for config values like access, registry and tag. `npm publish` therefore published src/ paths while `files` shipped only dist/, so every entry point resolved to a file that was not in the tarball. What is published is now exactly what is written here, and scripts/verify-package.mjs packs with the same client that publishes so the two cannot diverge again. See docs/decisions/adr-078.md.",
|
|
23
27
|
"main": "./dist/index.js",
|
|
@@ -70,6 +74,7 @@
|
|
|
70
74
|
"test:watch": "vitest",
|
|
71
75
|
"test:coverage": "vitest run --coverage",
|
|
72
76
|
"verify:package": "node scripts/verify-package.mjs",
|
|
77
|
+
"docs:theming": "node scripts/generate-theming-docs.mjs",
|
|
73
78
|
"demo": "node scripts/run-demo.mjs",
|
|
74
79
|
"build:examples": "node scripts/build-examples.mjs",
|
|
75
80
|
"build:site": "node scripts/build-site.mjs"
|