@liminis/editor 0.5.0 → 0.7.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 CHANGED
@@ -9,7 +9,7 @@ into this repository so it can stand on its own. MIT-licensed.
9
9
 
10
10
  Its history, and how to read the `ADR-0NNN`, `FR-NNN` and `#NNN` references that
11
11
  travelled with the code, are recorded in [`docs/provenance.md`](./docs/provenance.md)
12
- ([on the docs site](https://v3rv.com/liminis-editor/guide/provenance/)).
12
+ ([on the docs site](https://docs.liminis.app/liminis-editor/guide/provenance/)).
13
13
 
14
14
  ## What you get
15
15
 
@@ -17,7 +17,8 @@ travelled with the code, are recorded in [`docs/provenance.md`](./docs/provenanc
17
17
  ordered lists), footnotes, definition lists, callouts, toggles, code blocks
18
18
  with Prism highlighting, images, LaTeX equations, Mermaid diagrams, C4
19
19
  diagrams, YAML frontmatter, and wiki-links — including block-scoped links
20
- and live transclusion (`[[file#^id]]` / `![[file#^id]]`).
20
+ and live transclusion (`[[file#^id]]` / `![[file#^id]]`), with a `^ULID`
21
+ block anchor at its definition site rendering as a compact, copyable badge.
21
22
  - **A markdown pipeline** — `parseMarkdown` / `stringifyMarkdown` and the mdast
22
23
  ↔ Lexical mappers, usable with no editor mounted.
23
24
  - **An annotation mechanism** — range-anchored markers over document text that
@@ -45,10 +46,10 @@ produce a broken editor context — peering is what prevents both.
45
46
 
46
47
  ```bash
47
48
  pnpm add react@^19 react-dom@^19 \
48
- lexical@^0.49 @lexical/react@^0.49 @lexical/code@^0.49 \
49
- @lexical/code-prism@^0.49 @lexical/link@^0.49 @lexical/list@^0.49 \
50
- @lexical/mark@^0.49 @lexical/markdown@^0.49 @lexical/rich-text@^0.49 \
51
- @lexical/selection@^0.49 @lexical/table@^0.49 @lexical/utils@^0.49
49
+ lexical@^0.52 @lexical/react@^0.52 @lexical/code@^0.52 \
50
+ @lexical/code-prism@^0.52 @lexical/link@^0.52 @lexical/list@^0.52 \
51
+ @lexical/mark@^0.52 @lexical/markdown@^0.52 @lexical/rich-text@^0.52 \
52
+ @lexical/selection@^0.52 @lexical/table@^0.52 @lexical/utils@^0.52
52
53
  ```
53
54
 
54
55
  > **The Lexical peer ranges are single-caret, not a wide band.** Lexical is
@@ -486,6 +487,26 @@ today's file-only wiki-link navigation when it doesn't — no extra host
486
487
  wiring required beyond the resolver above, which also backs its
487
488
  "does this block exist" styling.
488
489
 
490
+ ## Block anchor badges
491
+
492
+ A block anchor — a bare `^ULID` at the point it was defined, most commonly
493
+ trailing an action-item checkbox (`- [ ] ... ^01M00VDX0S4JHMDNA7F776Y8R8`) —
494
+ renders as a compact badge instead of the raw 26-character id sitting inline
495
+ in the prose. Hover the badge to see the full id, or click it to copy the
496
+ exact id to the clipboard — the same id a `[[file#^id]]` reference above
497
+ needs. The underlying markdown, and the id itself, are never changed by
498
+ this: it is a display concern only, and the badge edits and deletes like
499
+ ordinary text.
500
+
501
+ Detection accepts every id form `[[file#^id]]` and its resolver accept —
502
+ ULIDs, raw-decimal snowflake ids, NanoID-style ids, mixed-case base62, UUIDs,
503
+ short alphanumeric ids — so the badge and the resolver agree on what counts
504
+ as an anchor. A caret in ordinary prose (`x^2`, `2^10`, `mc^2`, `a ^ b`) is
505
+ never mistaken for one, by the same position rule the resolver itself uses:
506
+ the caret must start a token, and the id must run to end of line — see
507
+ `docs/markdown-pipeline.md`'s "Block anchor badges" section for the full
508
+ rationale.
509
+
489
510
  ## Documentation
490
511
 
491
512
  - [`docs/editor-api.md`](./docs/editor-api.md) — the `<Editor>` props and the
@@ -536,7 +557,7 @@ every fixture-representable node class renders somewhere in it. See
536
557
  [`examples/demo/README.md`](./examples/demo/README.md).
537
558
 
538
559
  `examples/demo` is also the demo on the public GitHub Pages site, at
539
- **[v3rv.com/liminis-editor/demo/](https://v3rv.com/liminis-editor/demo/)** — a
560
+ **[docs.liminis.app/liminis-editor/demo/](https://docs.liminis.app/liminis-editor/demo/)** — a
540
561
  `release`-triggered (not merge-triggered) build of this same shell, showing a
541
562
  visible version badge for the published release it represents. Between releases
542
563
  the deployed site stays on the last published version even as `main` keeps
@@ -545,7 +566,7 @@ moving — that staleness is intentional, not a bug (see
545
566
 
546
567
  ## Documentation site
547
568
 
548
- **[v3rv.com/liminis-editor](https://v3rv.com/liminis-editor/)** publishes the
569
+ **[docs.liminis.app/liminis-editor](https://docs.liminis.app/liminis-editor/)** publishes the
549
570
  pages in [`docs/`](./docs/) with search, cross-links, and the C4 diagrams
550
571
  rendered live rather than as pictures.
551
572
 
@@ -17,6 +17,7 @@ import { registerCodeHighlighting } from '@lexical/code-prism';
17
17
  import { $createParagraphNode, $createRangeSelection, $getRoot, $getSelection, $isElementNode, $isLineBreakNode, $isRangeSelection, $isTextNode, $setSelection, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, } from 'lexical';
18
18
  import { mergeRegister } from '@lexical/utils';
19
19
  import { Toolbar } from './Toolbar.js';
20
+ import { MarkNodePastePlugin } from './MarkNodePastePlugin.js';
20
21
  import { SlashMenuPlugin } from './SlashMenuPlugin.js';
21
22
  import { DragHandlePlugin } from './DragHandlePlugin.js';
22
23
  import { MarkdownShortcutsPlugin } from './MarkdownShortcutsPlugin.js';
@@ -543,7 +544,7 @@ export function Editor({ initialContent, autoFocus = false, contentVersion = 0,
543
544
  onError: editorOnError,
544
545
  editable,
545
546
  };
546
- return (_jsx(AssetContext.Provider, { value: assetContextValue, children: _jsx(LexicalComposer, { initialConfig: initialConfig, children: _jsx("div", { className: "editor-container", children: _jsxs("div", { className: "editor-inner", children: [_jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "editor-input", "aria-label": "Markdown editor" }), placeholder: _jsx("div", { className: "editor-placeholder", children: "Type '/' for commands..." }), ErrorBoundary: LexicalErrorBoundary }), _jsx(HistoryPlugin, {}), _jsx(ListPlugin, {}), _jsx(CheckListPlugin, {}), _jsx(OrderedTaskListPlugin, {}), _jsx(TabIndentationPlugin, {}), _jsx(LinkPlugin, {}), _jsx(TablePlugin, {}), _jsx(CodeHighlightPlugin, {}), _jsx(OnChangePlugin, { onChange: handleChange, ignoreSelectionChange: true }), _jsx(InitializePlugin, { content: initialContent, onOffsets: handleOffsets }), _jsx(EditablePlugin, { editable: editable }), autoFocus && _jsx(AutoFocusPlugin, {}), _jsx(CursorTrackingPlugin, { onCursorChange: onCursorChange }), _jsx(CursorRestorePlugin, { contentVersion: contentVersion, cursorToRestoreRef: effectiveCursorRef }), _jsx(ExternalUpdatePlugin, { content: initialContent, lastExternalLoadRef: lastExternalLoadRef, currentContentRef: currentContentRef, lastEditorChangeRef: lastEditorChangeRef, onOffsets: handleOffsets }), _jsx(SlashMenuPlugin, {}), _jsx(DragHandlePlugin, {}), _jsx(MarkdownShortcutsPlugin, {}), _jsx(TableActionsPlugin, {}), _jsx(CodeBlockPlugin, {}), _jsx(TogglePlugin, {}), _jsx(ImagePlugin, {}), _jsx(BlockClickPlugin, {}), _jsx(LinkClickPlugin, { editable: editable }), _jsx(Toolbar, { annotationAffordances: toolbarAnnotationAffordances }), _jsx(SearchPlugin, {}), _jsx(FrontmatterPlugin, { filePath: filePath }), _jsx(WikiLinkExistencePlugin, {}), _jsx(WikiLinkFormatPlugin, {}), _jsx(AnchorScrollPlugin, {}), documentOutlineHandle && _jsx(OutlinePlugin, { handle: documentOutlineHandle }), _jsx(SelectionContextMenuPlugin, { onSelectionContextMenu: onSelectionContextMenu,
547
+ return (_jsx(AssetContext.Provider, { value: assetContextValue, children: _jsx(LexicalComposer, { initialConfig: initialConfig, children: _jsx("div", { className: "editor-container", children: _jsxs("div", { className: "editor-inner", children: [_jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "editor-input", "aria-label": "Markdown editor" }), placeholder: _jsx("div", { className: "editor-placeholder", children: "Type '/' for commands..." }), ErrorBoundary: LexicalErrorBoundary }), _jsx(HistoryPlugin, {}), _jsx(MarkNodePastePlugin, {}), _jsx(ListPlugin, {}), _jsx(CheckListPlugin, {}), _jsx(OrderedTaskListPlugin, {}), _jsx(TabIndentationPlugin, {}), _jsx(LinkPlugin, {}), _jsx(TablePlugin, {}), _jsx(CodeHighlightPlugin, {}), _jsx(OnChangePlugin, { onChange: handleChange, ignoreSelectionChange: true }), _jsx(InitializePlugin, { content: initialContent, onOffsets: handleOffsets }), _jsx(EditablePlugin, { editable: editable }), autoFocus && _jsx(AutoFocusPlugin, {}), _jsx(CursorTrackingPlugin, { onCursorChange: onCursorChange }), _jsx(CursorRestorePlugin, { contentVersion: contentVersion, cursorToRestoreRef: effectiveCursorRef }), _jsx(ExternalUpdatePlugin, { content: initialContent, lastExternalLoadRef: lastExternalLoadRef, currentContentRef: currentContentRef, lastEditorChangeRef: lastEditorChangeRef, onOffsets: handleOffsets }), _jsx(SlashMenuPlugin, {}), _jsx(DragHandlePlugin, {}), _jsx(MarkdownShortcutsPlugin, {}), _jsx(TableActionsPlugin, {}), _jsx(CodeBlockPlugin, {}), _jsx(TogglePlugin, {}), _jsx(ImagePlugin, {}), _jsx(BlockClickPlugin, {}), _jsx(LinkClickPlugin, { editable: editable }), _jsx(Toolbar, { annotationAffordances: toolbarAnnotationAffordances }), _jsx(SearchPlugin, {}), _jsx(FrontmatterPlugin, { filePath: filePath }), _jsx(WikiLinkExistencePlugin, {}), _jsx(WikiLinkFormatPlugin, {}), _jsx(AnchorScrollPlugin, {}), documentOutlineHandle && _jsx(OutlinePlugin, { handle: documentOutlineHandle }), _jsx(SelectionContextMenuPlugin, { onSelectionContextMenu: onSelectionContextMenu,
547
548
  // Only kinds that actually ask for a context-menu affordance:
548
549
  // with none configured, or one on another surface, AnnotationPlugin
549
550
  // would decline the command anyway, and dispatching from here would
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Pasted content never carries annotation marks.
3
+ *
4
+ * A live `MarkNode` is placed by the annotation surface for an annotation the
5
+ * host owns; it is not document content. Lexical 0.50 changed the in-editor
6
+ * clipboard payload to ask `excludeFromCopy('clone')`, which `MarkNode`
7
+ * answers by staying in the copy, so pasting annotated text produced a second
8
+ * mark with the same annotation ids — a highlight nothing placed, and a second
9
+ * rect reported for one annotation. Before 0.50 the mark was dropped on copy;
10
+ * this restores that by unwrapping marks on the way in, whatever the source.
11
+ *
12
+ * Mounted unconditionally: `MarkNode` is always registered, whether or not
13
+ * annotation kinds are configured.
14
+ */
15
+ export declare function MarkNodePastePlugin(): null;
@@ -0,0 +1,60 @@
1
+ import { useEffect } from 'react';
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { $isMarkNode } from '@lexical/mark';
4
+ import { $isElementNode, COMMAND_PRIORITY_CRITICAL, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, } from 'lexical';
5
+ /**
6
+ * Pasted content never carries annotation marks.
7
+ *
8
+ * A live `MarkNode` is placed by the annotation surface for an annotation the
9
+ * host owns; it is not document content. Lexical 0.50 changed the in-editor
10
+ * clipboard payload to ask `excludeFromCopy('clone')`, which `MarkNode`
11
+ * answers by staying in the copy, so pasting annotated text produced a second
12
+ * mark with the same annotation ids — a highlight nothing placed, and a second
13
+ * rect reported for one annotation. Before 0.50 the mark was dropped on copy;
14
+ * this restores that by unwrapping marks on the way in, whatever the source.
15
+ *
16
+ * Mounted unconditionally: `MarkNode` is always registered, whether or not
17
+ * annotation kinds are configured.
18
+ */
19
+ export function MarkNodePastePlugin() {
20
+ const [editor] = useLexicalComposerContext();
21
+ useEffect(() => editor.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, ({ nodes }) => {
22
+ // In place: every later handler, and the default insertion, read
23
+ // this same array.
24
+ nodes.splice(0, nodes.length, ...$unwrapMarks(nodes));
25
+ return false;
26
+ }, COMMAND_PRIORITY_CRITICAL), [editor]);
27
+ return null;
28
+ }
29
+ /** Replaces every `MarkNode` in `nodes`, at any depth, with its children. */
30
+ function $unwrapMarks(nodes) {
31
+ const out = [];
32
+ for (const node of nodes) {
33
+ if ($isMarkNode(node)) {
34
+ const children = node.getChildren();
35
+ for (const child of children)
36
+ child.remove(true);
37
+ out.push(...$unwrapMarks(children));
38
+ }
39
+ else {
40
+ if ($isElementNode(node))
41
+ $unwrapNestedMarks(node);
42
+ out.push(node);
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+ function $unwrapNestedMarks(element) {
48
+ for (const child of element.getChildren()) {
49
+ if ($isMarkNode(child)) {
50
+ for (const grandchild of child.getChildren())
51
+ child.insertBefore(grandchild);
52
+ child.remove();
53
+ // The moved children may themselves be (or contain) marks.
54
+ $unwrapNestedMarks(element);
55
+ return;
56
+ }
57
+ if ($isElementNode(child))
58
+ $unwrapNestedMarks(child);
59
+ }
60
+ }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useState, useRef } from 'react';
3
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
- import { $getSelection, $isRangeSelection, FORMAT_TEXT_COMMAND, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_LOW, } from 'lexical';
4
+ import { $getSelection, $isRangeSelection, $onUpdate, FORMAT_TEXT_COMMAND, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_LOW, } from 'lexical';
5
5
  import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
6
6
  import { getSelectedNode } from './utils.js';
7
7
  import { OPEN_ANNOTATION_COMPOSER_COMMAND } from './annotationCommands.js';
@@ -122,12 +122,18 @@ export function Toolbar({ annotationAffordances = [] }) {
122
122
  }, [editor, updateFormatFlags]);
123
123
  useEffect(() => {
124
124
  const unregisterSelection = editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
125
- updateVisibility();
126
- if (editor.isEditable()) {
127
- editor.getEditorState().read(() => {
128
- updateFormatFlags();
125
+ // Since Lexical 0.52 this command runs inside the pending update,
126
+ // before DOM reconciliation: `getEditorState()` would still hold the
127
+ // previous selection, and the native selection may not have moved
128
+ // yet. Defer both reads until the update has committed.
129
+ $onUpdate(() => {
130
+ editor.read('latest', () => {
131
+ updateVisibility();
132
+ if (editor.isEditable()) {
133
+ updateFormatFlags();
134
+ }
129
135
  });
130
- }
136
+ });
131
137
  return false;
132
138
  }, COMMAND_PRIORITY_CRITICAL);
133
139
  // Also listen for format changes to update button states
@@ -3,7 +3,7 @@ import { CodeNode, CodeHighlightNode } from '@lexical/code';
3
3
  import { AutoLinkNode } from '@lexical/link';
4
4
  import { MarkNode } from '@lexical/mark';
5
5
  import { TableNode, TableRowNode, TableCellNode } from '@lexical/table';
6
- import { CalloutNode, ToggleContainerNode, ToggleTitleNode, ToggleContentNode, ImageNode, HorizontalRuleNode, EquationNode, MermaidNode, C4Node, FrontmatterNode, FootnoteNode, HtmlNode, ListItemParagraphBreakNode, CustomLinkNode, CustomListNode, DefinitionListNode, DefinitionTermNode, DefinitionDescriptionNode, CustomListItemNode, TransclusionNode, } from './nodes/index.js';
6
+ import { CalloutNode, ToggleContainerNode, ToggleTitleNode, ToggleContentNode, ImageNode, HorizontalRuleNode, EquationNode, MermaidNode, C4Node, FrontmatterNode, FootnoteNode, BlockAnchorNode, HtmlNode, ListItemParagraphBreakNode, CustomLinkNode, CustomListNode, DefinitionListNode, DefinitionTermNode, DefinitionDescriptionNode, CustomListItemNode, TransclusionNode, } from './nodes/index.js';
7
7
  export const editorNodes = [
8
8
  HeadingNode,
9
9
  QuoteNode,
@@ -28,6 +28,7 @@ export const editorNodes = [
28
28
  C4Node,
29
29
  FrontmatterNode,
30
30
  FootnoteNode,
31
+ BlockAnchorNode,
31
32
  DefinitionListNode,
32
33
  DefinitionTermNode,
33
34
  DefinitionDescriptionNode,
@@ -0,0 +1,5 @@
1
+ interface BlockAnchorComponentProps {
2
+ id: string;
3
+ }
4
+ export default function BlockAnchorComponent({ id }: BlockAnchorComponentProps): JSX.Element;
5
+ export {};
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * BlockAnchorComponent — the compact badge a `BlockAnchorNode` decorates
4
+ * itself with (#122).
5
+ *
6
+ * User Story 2 (the id must remain readable and copyable) is satisfied with
7
+ * no new interaction pattern: the full id is exposed via the native `title`
8
+ * tooltip on hover, and a click copies it via `navigator.clipboard.writeText`
9
+ * with brief "Copied" feedback — mirroring `CodeBlockPlugin.tsx`'s existing
10
+ * copy-button pattern.
11
+ */
12
+ import { useCallback, useState } from 'react';
13
+ const COPIED_FEEDBACK_MS = 1500;
14
+ export default function BlockAnchorComponent({ id }) {
15
+ const [copied, setCopied] = useState(false);
16
+ const handleClick = useCallback(() => {
17
+ void navigator.clipboard.writeText(id).then(() => {
18
+ setCopied(true);
19
+ setTimeout(() => setCopied(false), COPIED_FEEDBACK_MS);
20
+ });
21
+ }, [id]);
22
+ return (_jsx("button", { type: "button", className: "block-anchor-badge", title: id, "aria-label": `Block anchor ${id}. Click to copy.`, onClick: handleClick, contentEditable: false, style: {
23
+ display: 'inline-block',
24
+ cursor: 'pointer',
25
+ border: 'none',
26
+ font: 'inherit',
27
+ fontSize: '0.75em',
28
+ lineHeight: '1.4em',
29
+ padding: '0 0.4em',
30
+ marginLeft: '0.3em',
31
+ borderRadius: '1em',
32
+ backgroundColor: 'var(--liminis-editor-muted-100)',
33
+ color: 'var(--liminis-editor-muted-foreground)',
34
+ userSelect: 'none',
35
+ verticalAlign: 'middle',
36
+ }, children: copied ? 'Copied' : '^' }));
37
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * BlockAnchorNode — Inline decorator node for a block anchor (`^ULID`, #122).
3
+ * Renders a compact badge at the anchor's definition site instead of the raw
4
+ * `^ULID` text, and preserves the id for byte-identical round-trip back to
5
+ * markdown (`stringify.ts`'s `blockAnchor` handler emits `^` + this id, and
6
+ * nothing else).
7
+ */
8
+ import { DecoratorNode, DOMConversionMap, DOMExportOutput, LexicalNode, NodeKey, SerializedLexicalNode, Spread, TextFormatType } from 'lexical';
9
+ export type SerializedBlockAnchorNode = Spread<{
10
+ id: string;
11
+ format?: number;
12
+ strongMarker?: '_' | '*' | null;
13
+ emphasisMarker?: '_' | '*' | null;
14
+ }, SerializedLexicalNode>;
15
+ export declare class BlockAnchorNode extends DecoratorNode<JSX.Element> {
16
+ __id: string;
17
+ __format: number;
18
+ __strongMarker: '_' | '*' | null;
19
+ __emphasisMarker: '_' | '*' | null;
20
+ static getType(): string;
21
+ static clone(node: BlockAnchorNode): BlockAnchorNode;
22
+ constructor(id: string, key?: NodeKey);
23
+ getId(): string;
24
+ isInline(): boolean;
25
+ static importJSON(serializedNode: SerializedBlockAnchorNode): BlockAnchorNode;
26
+ exportJSON(): SerializedBlockAnchorNode;
27
+ getFormat(): number;
28
+ hasFormat(type: TextFormatType): boolean;
29
+ setFormat(format: number): this;
30
+ toggleFormat(type: TextFormatType): this;
31
+ getStrongMarker(): '_' | '*' | null;
32
+ setStrongMarker(marker: '_' | '*' | null): this;
33
+ getEmphasisMarker(): '_' | '*' | null;
34
+ setEmphasisMarker(marker: '_' | '*' | null): this;
35
+ createDOM(): HTMLElement;
36
+ updateDOM(): boolean;
37
+ exportDOM(): DOMExportOutput;
38
+ static importDOM(): DOMConversionMap | null;
39
+ decorate(): JSX.Element;
40
+ }
41
+ export declare function $createBlockAnchorNode(id: string): BlockAnchorNode;
42
+ export declare function $isBlockAnchorNode(node: LexicalNode | null | undefined): node is BlockAnchorNode;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * BlockAnchorNode — Inline decorator node for a block anchor (`^ULID`, #122).
3
+ * Renders a compact badge at the anchor's definition site instead of the raw
4
+ * `^ULID` text, and preserves the id for byte-identical round-trip back to
5
+ * markdown (`stringify.ts`'s `blockAnchor` handler emits `^` + this id, and
6
+ * nothing else).
7
+ */
8
+ import { DecoratorNode, TEXT_TYPE_TO_FORMAT, toggleTextFormatType, $applyNodeReplacement, } from 'lexical';
9
+ import { createElement } from 'react';
10
+ import BlockAnchorComponent from './BlockAnchorComponent.js';
11
+ // ---------------------------------------------------------------------------
12
+ // DOM conversion (copy/paste support)
13
+ // ---------------------------------------------------------------------------
14
+ function $convertBlockAnchorElement(domNode) {
15
+ const id = domNode.getAttribute('data-block-anchor-id');
16
+ if (id) {
17
+ return { node: $createBlockAnchorNode(id) };
18
+ }
19
+ return null;
20
+ }
21
+ // ---------------------------------------------------------------------------
22
+ // BlockAnchorNode
23
+ // ---------------------------------------------------------------------------
24
+ export class BlockAnchorNode extends DecoratorNode {
25
+ __id;
26
+ __format;
27
+ __strongMarker;
28
+ __emphasisMarker;
29
+ static getType() {
30
+ return 'blockAnchor';
31
+ }
32
+ static clone(node) {
33
+ const cloned = new BlockAnchorNode(node.__id, node.__key);
34
+ cloned.__format = node.__format;
35
+ cloned.__strongMarker = node.__strongMarker;
36
+ cloned.__emphasisMarker = node.__emphasisMarker;
37
+ return cloned;
38
+ }
39
+ constructor(id, key) {
40
+ super(key);
41
+ this.__id = id;
42
+ this.__format = 0;
43
+ this.__strongMarker = null;
44
+ this.__emphasisMarker = null;
45
+ }
46
+ getId() {
47
+ return this.__id;
48
+ }
49
+ // Inline node — sits within text flow
50
+ isInline() {
51
+ return true;
52
+ }
53
+ // Serialization
54
+ static importJSON(serializedNode) {
55
+ const node = $createBlockAnchorNode(serializedNode.id).setFormat(serializedNode.format ?? 0);
56
+ if (serializedNode.strongMarker) {
57
+ node.setStrongMarker(serializedNode.strongMarker);
58
+ }
59
+ if (serializedNode.emphasisMarker) {
60
+ node.setEmphasisMarker(serializedNode.emphasisMarker);
61
+ }
62
+ return node;
63
+ }
64
+ exportJSON() {
65
+ return {
66
+ type: 'blockAnchor',
67
+ version: 1,
68
+ id: this.__id,
69
+ format: this.__format,
70
+ strongMarker: this.__strongMarker,
71
+ emphasisMarker: this.__emphasisMarker,
72
+ };
73
+ }
74
+ // Mirrors TextNode's format bitmask API so this node can carry
75
+ // bold/italic/strikethrough state through the mdast<->Lexical round-trip.
76
+ getFormat() {
77
+ return this.getLatest().__format;
78
+ }
79
+ hasFormat(type) {
80
+ const formatFlag = TEXT_TYPE_TO_FORMAT[type];
81
+ return (this.getFormat() & formatFlag) !== 0;
82
+ }
83
+ setFormat(format) {
84
+ const self = this.getWritable();
85
+ self.__format = format;
86
+ return self;
87
+ }
88
+ toggleFormat(type) {
89
+ const format = this.getFormat();
90
+ const newFormat = toggleTextFormatType(format, type, null);
91
+ return this.setFormat(newFormat);
92
+ }
93
+ // Mirrors TextNode's --md-strong-marker/--md-emphasis-marker style hooks
94
+ // (via setMarkdownMarker/getMarkdownMarker in the mappers) so a bare
95
+ // anchor sitting inside `**bold**`/`_italic_` still round-trips its
96
+ // original underscore-vs-asterisk marker on export.
97
+ getStrongMarker() {
98
+ return this.getLatest().__strongMarker;
99
+ }
100
+ setStrongMarker(marker) {
101
+ const self = this.getWritable();
102
+ self.__strongMarker = marker;
103
+ return self;
104
+ }
105
+ getEmphasisMarker() {
106
+ return this.getLatest().__emphasisMarker;
107
+ }
108
+ setEmphasisMarker(marker) {
109
+ const self = this.getWritable();
110
+ self.__emphasisMarker = marker;
111
+ return self;
112
+ }
113
+ // DOM creation (editor view)
114
+ createDOM() {
115
+ const el = document.createElement('span');
116
+ el.className = 'block-anchor';
117
+ return el;
118
+ }
119
+ updateDOM() {
120
+ return false;
121
+ }
122
+ // DOM export (copy/paste)
123
+ exportDOM() {
124
+ const el = document.createElement('span');
125
+ el.setAttribute('data-block-anchor-id', this.__id);
126
+ el.textContent = `^${this.__id}`;
127
+ return { element: el };
128
+ }
129
+ static importDOM() {
130
+ return {
131
+ span: (domNode) => {
132
+ if (!domNode.hasAttribute('data-block-anchor-id'))
133
+ return null;
134
+ return { conversion: $convertBlockAnchorElement, priority: 1 };
135
+ },
136
+ };
137
+ }
138
+ // Render as React element
139
+ decorate() {
140
+ return createElement(BlockAnchorComponent, { id: this.__id });
141
+ }
142
+ }
143
+ // ---------------------------------------------------------------------------
144
+ // Factory + type guard
145
+ // ---------------------------------------------------------------------------
146
+ export function $createBlockAnchorNode(id) {
147
+ return $applyNodeReplacement(new BlockAnchorNode(id));
148
+ }
149
+ export function $isBlockAnchorNode(node) {
150
+ return node instanceof BlockAnchorNode;
151
+ }
@@ -10,7 +10,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
10
  */
11
11
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
12
12
  import { mergeRegister } from '@lexical/utils';
13
- import { $getNodeByKey, $getSelection, $isNodeSelection, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND, } from 'lexical';
13
+ import { $getNodeByKey, $getSelection, $isNodeSelection, $onUpdate, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND, } from 'lexical';
14
14
  import { useCallback, useEffect, useRef, useState, forwardRef } from 'react';
15
15
  import { createBrowserAdaptorDocument } from '../../../mathjax-config.js';
16
16
  import { $isEquationNode } from './EquationNode.js';
@@ -89,11 +89,13 @@ export default function EquationComponent({ equation, inline, nodeKey, }) {
89
89
  }
90
90
  if (showEquationEditor) {
91
91
  return mergeRegister(editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
92
- const activeElement = document.activeElement;
93
- const inputElem = inputRef.current;
94
- if (inputElem !== activeElement) {
95
- onHide();
96
- }
92
+ // Since Lexical 0.52 this runs before DOM reconciliation; check
93
+ // focus once the update has committed, as it did before.
94
+ $onUpdate(() => {
95
+ if (inputRef.current !== document.activeElement) {
96
+ onHide();
97
+ }
98
+ });
97
99
  return false;
98
100
  }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ESCAPE_COMMAND, () => {
99
101
  const activeElement = document.activeElement;
@@ -12,11 +12,18 @@ import { useHostMessages } from '../../../host/messages.js';
12
12
  import { $isMermaidNode } from './MermaidNode.js';
13
13
  import { DiagramContextMenu, useDiagramContextMenu } from './DiagramContextMenu.js';
14
14
  // Initialize mermaid with default config
15
+ //
16
+ // `layout` and `look` pin mermaid 11's appearance. Mermaid 12 made ELK the
17
+ // default layout and `neo` the default look, which re-lays out and restyles
18
+ // every existing diagram in a user's documents. A dependency upgrade should
19
+ // not do that silently; adopting the new defaults is a decision of its own.
15
20
  mermaid.initialize({
16
21
  startOnLoad: false,
17
22
  theme: 'dark',
18
23
  securityLevel: 'strict',
19
24
  fontFamily: 'inherit',
25
+ layout: 'dagre',
26
+ look: 'classic',
20
27
  });
21
28
  // Mermaid Renderer component using Shadow DOM
22
29
  function MermaidRenderer({ code, onDoubleClick, }) {
@@ -24,6 +24,8 @@ export { CustomListItemNode, $createCustomListItemNode, $isCustomListItemNode }
24
24
  export type { SerializedCustomListItemNode } from './CustomListItemNode.js';
25
25
  export { FootnoteNode, $createFootnoteNode, $isFootnoteNode } from './FootnoteNode.js';
26
26
  export type { SerializedFootnoteNode } from './FootnoteNode.js';
27
+ export { BlockAnchorNode, $createBlockAnchorNode, $isBlockAnchorNode } from './BlockAnchorNode.js';
28
+ export type { SerializedBlockAnchorNode } from './BlockAnchorNode.js';
27
29
  export { DefinitionListNode, DefinitionTermNode, DefinitionDescriptionNode, $createDefinitionListNode, $createDefinitionTermNode, $createDefinitionDescriptionNode, $isDefinitionListNode, $isDefinitionTermNode, $isDefinitionDescriptionNode, } from './DefinitionListNode.js';
28
30
  export type { SerializedDefinitionListNode, SerializedDefinitionTermNode, SerializedDefinitionDescriptionNode, } from './DefinitionListNode.js';
29
31
  export { HtmlNode, $createHtmlNode, $isHtmlNode } from './HtmlNode.js';
@@ -13,6 +13,7 @@ export { CustomLinkNode, $createCustomLinkNode, $isCustomLinkNode } from './Cust
13
13
  export { CustomListNode, $createCustomListNode, $isCustomListNode } from './CustomListNode.js';
14
14
  export { CustomListItemNode, $createCustomListItemNode, $isCustomListItemNode } from './CustomListItemNode.js';
15
15
  export { FootnoteNode, $createFootnoteNode, $isFootnoteNode } from './FootnoteNode.js';
16
+ export { BlockAnchorNode, $createBlockAnchorNode, $isBlockAnchorNode } from './BlockAnchorNode.js';
16
17
  export { DefinitionListNode, DefinitionTermNode, DefinitionDescriptionNode, $createDefinitionListNode, $createDefinitionTermNode, $createDefinitionDescriptionNode, $isDefinitionListNode, $isDefinitionTermNode, $isDefinitionDescriptionNode, } from './DefinitionListNode.js';
17
18
  export { HtmlNode, $createHtmlNode, $isHtmlNode } from './HtmlNode.js';
18
19
  export { ListItemParagraphBreakNode, $createListItemParagraphBreakNode, $isListItemParagraphBreakNode, } from './ListItemParagraphBreakNode.js';