@plannotator/ui 0.27.0 → 0.28.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
@@ -62,6 +62,22 @@ Building your own tooltip and removing the built-in double-click reset are host-
62
62
 
63
63
  Requires `@plannotator/markdown-editor ^0.3.2` and `@plannotator/atomic-editor ^0.7.0`. See HANDOFF.md § "Wiki-link seams (0.27.0)".
64
64
 
65
+ ### Frozen markdown diff (`MarkdownDiff`)
66
+
67
+ - **`MarkdownDiff` renders two markdown revisions as a frozen, themed comparison** — the newer revision as the real (uncollapsed) document, deletions projected struck-through in place, char/word change emphasis, a change-count toolbar with prev/next, a clickable keyboard-accessible overview rail, and a changed-line gutter. The surface is never editable (edits are rejected at the state and view boundaries; the content DOM is `contenteditable="false"`).
68
+ - **Same shim pattern as `MarkdownEditor`:** theme resolves from `ThemeProvider` (or pass `mode` directly), `gridEnabled` applies the identical card chrome, and `extensions` composes CM6 extensions — `wikiLinks` included — into the frozen view, with the same captured-once, stable-reference calling convention:
69
+ ```tsx
70
+ import { MarkdownDiff } from "@plannotator/ui/components/MarkdownDiff";
71
+ import { wikiLinks } from "@plannotator/ui/components/MarkdownEditor";
72
+
73
+ const diffExtensions = [wikiLinks({ resolve, onOpen })]; // stable reference!
74
+ <MarkdownDiff originalMarkdown={older} modifiedMarkdown={newer} documentId={docId}
75
+ editorHandleRef={ref} extensions={diffExtensions} />
76
+ ```
77
+ - **Bytes are the contract:** `ref.current.getMarkdown()` / `.getOriginalMarkdown()` return the exact input strings (CRLF and trailing whitespace included); `getChangeCount()` / `goToNextChange()` / `goToPreviousChange()` drive review navigation.
78
+
79
+ Requires `@plannotator/markdown-editor ^0.4.0` and `@plannotator/atomic-editor ^0.8.0` (which adds a `@codemirror/merge` peer — declared by this package). See HANDOFF.md § "Frozen markdown diff (0.28.0)".
80
+
65
81
  ## Consuming it (e.g. from Workspaces)
66
82
 
67
83
  ```bash
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import {
3
+ MarkdownDiff as PackagedMarkdownDiff,
4
+ type MarkdownDiffHandle,
5
+ type MarkdownDiffProps as PackagedMarkdownDiffProps,
6
+ } from '@plannotator/markdown-editor';
7
+ import '@plannotator/markdown-editor/themes/plannotator.css';
8
+ import { useTheme } from './ThemeProvider';
9
+
10
+ export type { MarkdownDiffHandle };
11
+
12
+ /* @plannotator/ui is the single supported contract for hosts — do NOT import
13
+ AtomicDiffEditor or @plannotator/atomic-editor directly (both are outside
14
+ the import allowlist). Extension builders (wikiLinks, slashCommands,
15
+ selectionToolbar) are re-exported from ./MarkdownEditor; build them there
16
+ and pass the result through the `extensions` prop below — the frozen diff
17
+ view composes them the same way the editor does. */
18
+
19
+ /* Grid-mode card utilities mirror components/MarkdownEditor.tsx exactly, so a
20
+ host toggling editor <-> diff keeps identical card chrome. They stay here
21
+ (not in the package) because they're Plannotator design-system Tailwind
22
+ classes and this file is @source-scanned. */
23
+ const GRID_CARD_CLASSES = 'px-5 md:px-8 lg:px-10 xl:px-12 shadow-xl border border-border/50';
24
+
25
+ export interface MarkdownDiffProps
26
+ extends Omit<PackagedMarkdownDiffProps, 'mode' | 'cardClassName'> {
27
+ /** Mirrors MarkdownEditor's grid card chrome so editor <-> diff doesn't jump. */
28
+ gridEnabled?: boolean;
29
+ /** Theme color mode. Defaults to the ThemeProvider's resolved mode (Plannotator
30
+ passes nothing); a host without ThemeProvider can supply it directly. */
31
+ mode?: PackagedMarkdownDiffProps['mode'];
32
+ }
33
+
34
+ /* Theme-bridging shim around @plannotator/markdown-editor's MarkdownDiff — the
35
+ frozen two-revision comparison surface (newer revision as the real document,
36
+ deletions projected struck-through in place). Same pattern as the
37
+ MarkdownEditor shim: resolve the color mode from ThemeProvider beneath the
38
+ host's provider and pass it down as a prop.
39
+
40
+ The byte contract lives on `editorHandleRef`: getMarkdown() returns the
41
+ exact `modifiedMarkdown` supplied, getOriginalMarkdown() the exact
42
+ `originalMarkdown` — both byte-identical to the inputs. The surface itself
43
+ is frozen: document-changing transactions are rejected at the state and
44
+ view boundaries, and the content DOM is contenteditable="false".
45
+
46
+ `extensions` follows the editor's calling convention: CAPTURED ONCE per
47
+ mounted comparison (keyed on `documentId` + both document strings) — pass a
48
+ stable array and feed changing data through callbacks that close over live
49
+ state. Build extensions against YOUR copy of the `@codemirror/*` packages;
50
+ two live copies of `@codemirror/state` break the view. */
51
+ export const MarkdownDiff: React.FC<MarkdownDiffProps> = ({ gridEnabled, mode, ...props }) => {
52
+ const { resolvedMode } = useTheme();
53
+ return (
54
+ <PackagedMarkdownDiff
55
+ {...props}
56
+ mode={mode ?? resolvedMode}
57
+ cardClassName={gridEnabled ? GRID_CARD_CLASSES : undefined}
58
+ />
59
+ );
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plannotator/ui",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./components/*": "./components/*.tsx",
@@ -57,6 +57,7 @@
57
57
  "@codemirror/lang-yaml": "^6.1.3",
58
58
  "@codemirror/language": "^6.12.3",
59
59
  "@codemirror/legacy-modes": "^6.5.3",
60
+ "@codemirror/merge": "^6.12.2",
60
61
  "@codemirror/search": "^6.7.0",
61
62
  "@codemirror/state": "^6.6.0",
62
63
  "@codemirror/view": "^6.43.0",
@@ -65,9 +66,9 @@
65
66
  "@lezer/common": "^1.5.2",
66
67
  "@lezer/highlight": "^1.2.3",
67
68
  "@pierre/diffs": "1.2.8",
68
- "@plannotator/atomic-editor": "^0.7.0",
69
+ "@plannotator/atomic-editor": "^0.8.0",
69
70
  "@plannotator/core": "0.22.0",
70
- "@plannotator/markdown-editor": "^0.3.2",
71
+ "@plannotator/markdown-editor": "^0.4.0",
71
72
  "@plannotator/web-highlighter": "^0.8.1",
72
73
  "@tanstack/react-table": "^8.21.3",
73
74
  "@viz-js/viz": "^3.25.0",