@open-document/core 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.
Files changed (35) hide show
  1. package/dist/{build-BzhYQKev.js → build-CFL7nhz0.js} +1 -1
  2. package/dist/{check-CCAaXofH.js → check-pEQh4jJE.js} +3 -3
  3. package/dist/cli/bin.js +6 -6
  4. package/dist/{config-CNr8hd5X.js → config-4nz5NnxW.js} +899 -159
  5. package/dist/{context-CJpdjYfU.js → context-BH8C-dSW.js} +1 -1
  6. package/dist/{dev-BhXgunme.js → dev-BCSUczXW.js} +1 -1
  7. package/dist/{export-B69kDkyp.js → export-BQ-GvMsb.js} +3 -3
  8. package/dist/{import-DBhCpUsl.js → import-Daat3L2J.js} +2 -2
  9. package/dist/index.d.ts +21 -3
  10. package/dist/index.js +41 -9
  11. package/dist/ops/index.d.ts +47 -3
  12. package/dist/ops/index.js +3 -3
  13. package/dist/{ops-BCBmRMCS.js → ops-DQfckiyp.js} +2 -45
  14. package/dist/{preview-Da4Aq9yF.js → preview-CwCrw-i3.js} +1 -1
  15. package/dist/vite/index.js +1 -1
  16. package/package.json +1 -1
  17. package/src/app/components/data-table.tsx +17 -2
  18. package/src/app/components/design-panel/design-panel.tsx +149 -274
  19. package/src/app/components/design-panel/design-provider.tsx +35 -15
  20. package/src/app/components/footnote.tsx +27 -10
  21. package/src/app/components/history-provider.tsx +125 -0
  22. package/src/app/components/inspector/inspector.tsx +1158 -146
  23. package/src/app/components/numbering.tsx +13 -1
  24. package/src/app/components/panel/edit-save-card.tsx +112 -0
  25. package/src/app/components/panel/fields.tsx +247 -0
  26. package/src/app/components/panel/panel-shell.tsx +71 -0
  27. package/src/app/components/panel/save-card.tsx +146 -0
  28. package/src/app/components/table-of-contents.tsx +4 -0
  29. package/src/app/lib/footnotes.ts +6 -3
  30. package/src/app/lib/href.ts +14 -0
  31. package/src/app/lib/inspector/inline-edit.test.ts +244 -0
  32. package/src/app/lib/inspector/inline-edit.ts +770 -0
  33. package/src/app/lib/source-loc.ts +15 -0
  34. package/src/app/routes/doc.tsx +109 -39
  35. package/src/app/styles.css +41 -0
@@ -0,0 +1,15 @@
1
+ /**
2
+ * In dev, `loc-tags-plugin` stamps `data-od-loc` onto the call site of a
3
+ * framework component that forwards it. The component puts it back on the
4
+ * host that prints the call site's words, so the inspector can select what it
5
+ * rendered — a table, a caption, a footnote — and find the source behind it.
6
+ * `data-od-prop` says which attribute of the call site those words come from.
7
+ */
8
+ export const LOC_PROP = 'data-od-loc';
9
+ export const PROP_ATTR = 'data-od-prop';
10
+
11
+ /** The attributes pointing a host back at its call site; nothing outside dev. */
12
+ export function sourceAttrs(loc: string | undefined, prop?: string): Record<string, string> {
13
+ if (!loc) return {};
14
+ return prop ? { [LOC_PROP]: loc, [PROP_ATTR]: prop } : { [LOC_PROP]: loc };
15
+ }
@@ -3,6 +3,7 @@ import {
3
3
  ArrowLeft,
4
4
  Check,
5
5
  Download,
6
+ Eye,
6
7
  FileCode2,
7
8
  FileImage,
8
9
  FileText,
@@ -11,10 +12,10 @@ import {
11
12
  Maximize,
12
13
  Minimize,
13
14
  Minus,
14
- MousePointerClick,
15
15
  MoveHorizontal,
16
16
  MoveVertical,
17
17
  Palette,
18
+ Pencil,
18
19
  Percent,
19
20
  Plus,
20
21
  } from 'lucide-react';
@@ -24,8 +25,10 @@ import { DesignPanel } from '../components/design-panel/design-panel';
24
25
  import { DesignProvider } from '../components/design-panel/design-provider';
25
26
  import { DocSearch } from '../components/doc-search';
26
27
  import { DocSidebar } from '../components/doc-sidebar';
27
- import { Inspector } from '../components/inspector/inspector';
28
+ import { HistoryProvider } from '../components/history-provider';
29
+ import { Inspector, type InspectorControls } from '../components/inspector/inspector';
28
30
  import { PageFrame } from '../components/page-frame';
31
+ import { EditSaveCard } from '../components/panel/edit-save-card';
29
32
  import { ThemeToggle } from '../components/theme-toggle';
30
33
  import { Menu, MenuItem } from '../components/ui/menu';
31
34
  import { useAgentBridge } from '../lib/agent-bridge';
@@ -92,6 +95,17 @@ const HeaderBackLink = () => {
92
95
  );
93
96
  };
94
97
 
98
+ const EDITING_KEY = 'open-doc:editing';
99
+
100
+ function readEditing(): boolean {
101
+ if (!import.meta.env.DEV) return false;
102
+ try {
103
+ return sessionStorage.getItem(EDITING_KEY) === '1';
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
108
+
95
109
  export function Doc() {
96
110
  const { docId } = useParams<{ docId: string }>();
97
111
  const state = useDocModule(docId);
@@ -111,7 +125,20 @@ export function Doc() {
111
125
  const [selection, setSelection] = useState<PageSelection>({ kind: 'all' });
112
126
  const [customRange, setCustomRange] = useState('');
113
127
  const [designOpen, setDesignOpen] = useState(false);
114
- const [inspecting, setInspecting] = useState(false);
128
+ const [editing, setEditingState] = useState(readEditing);
129
+ // The dev server reloads every open viewer when a document is added or
130
+ // removed anywhere in the workspace. Edit mode is per tab and survives that.
131
+ const setEditing = useCallback((next: boolean) => {
132
+ setEditingState(next);
133
+ try {
134
+ if (next) sessionStorage.setItem(EDITING_KEY, '1');
135
+ else sessionStorage.removeItem(EDITING_KEY);
136
+ } catch {}
137
+ }, []);
138
+ const leaveEditRef = useRef<(() => void) | null>(null);
139
+ const editControlsRef = useRef<InspectorControls | null>(null);
140
+ const [textPending, setTextPending] = useState(0);
141
+ const [cardShown, setCardShown] = useState(false);
115
142
  const [isFullscreen, setIsFullscreen] = useState(false);
116
143
 
117
144
  const geometry = useMemo(() => resolvePageGeometry(doc?.meta), [doc?.meta]);
@@ -322,6 +349,9 @@ export function Doc() {
322
349
  if (e.key === 'f' || e.key === 'F') {
323
350
  e.preventDefault();
324
351
  toggleFullscreen();
352
+ } else if (import.meta.env.DEV && (e.key === 'd' || e.key === 'D')) {
353
+ e.preventDefault();
354
+ setDesignOpen((open) => !open);
325
355
  }
326
356
  };
327
357
  window.addEventListener('keydown', onKeyDown);
@@ -418,22 +448,29 @@ export function Doc() {
418
448
  {!appConfig.build.showDocBrowser && <ThemeToggle />}
419
449
 
420
450
  {import.meta.env.DEV && (
421
- <button
422
- type="button"
423
- onClick={() => setInspecting((on) => !on)}
424
- title="Inspect and edit on the page"
425
- className={cn(
426
- 'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
427
- inspecting && 'border-transparent bg-[#3b82f6] text-white hover:bg-[#3b82f6]',
428
- )}
429
- >
430
- <MousePointerClick className="size-3.5" />
431
- Inspect
432
- </button>
451
+ // Same two modes as open-slide: reading the document, or editing it
452
+ // where it is printed. Leaving edit mode saves unsaved text first.
453
+ <fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
454
+ <legend className="sr-only">Mode</legend>
455
+ <IconButton
456
+ label="Preview"
457
+ active={!editing}
458
+ onClick={() => (leaveEditRef.current ? leaveEditRef.current() : setEditing(false))}
459
+ >
460
+ <Eye className="size-3.5" />
461
+ </IconButton>
462
+ <IconButton label="Edit" active={editing} onClick={() => setEditing(true)}>
463
+ <Pencil className="size-3.5" />
464
+ </IconButton>
465
+ </fieldset>
433
466
  )}
434
467
  {import.meta.env.DEV && (
435
468
  <button
436
469
  type="button"
470
+ aria-pressed={designOpen}
471
+ aria-label="Design"
472
+ aria-keyshortcuts="D"
473
+ title="Design tokens (D)"
437
474
  onClick={() => setDesignOpen((open) => !open)}
438
475
  className={cn(
439
476
  'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
@@ -442,6 +479,12 @@ export function Doc() {
442
479
  >
443
480
  <Palette className="size-3.5" />
444
481
  Design
482
+ <kbd
483
+ aria-hidden
484
+ className="hidden rounded-sm bg-foreground/10 px-1 font-mono text-[9.5px] text-muted-foreground md:inline"
485
+ >
486
+ D
487
+ </kbd>
445
488
  </button>
446
489
  )}
447
490
  <Menu
@@ -512,32 +555,54 @@ export function Doc() {
512
555
  onSelectPage={scrollToPage}
513
556
  onSelectEntry={scrollToEntry}
514
557
  />
515
- <div
516
- ref={scrollRef}
517
- data-od-viewer
518
- className="relative min-w-0 flex-1 overflow-auto bg-canvas"
519
- >
558
+ <div className="relative flex min-w-0 flex-1">
520
559
  <div
521
- ref={pagesRef}
522
- className="flex flex-col items-center"
523
- style={{ gap: PAGE_GAP, padding: `${GUTTER}px ${GUTTER}px ${GUTTER * 1.5}px` }}
560
+ ref={scrollRef}
561
+ data-od-viewer
562
+ className="relative min-w-0 flex-1 overflow-auto bg-canvas"
524
563
  >
525
- {pages.map((page, index) => (
526
- <PageFrame
527
- key={page.key}
528
- index={index}
529
- total={pages.length}
530
- geometry={geometry}
531
- scale={scale}
532
- design={doc.design}
533
- >
534
- {page.content}
535
- </PageFrame>
536
- ))}
564
+ <div
565
+ ref={pagesRef}
566
+ className="flex flex-col items-center"
567
+ style={{ gap: PAGE_GAP, padding: `${GUTTER}px ${GUTTER}px ${GUTTER * 1.5}px` }}
568
+ >
569
+ {pages.map((page, index) => (
570
+ <PageFrame
571
+ key={page.key}
572
+ index={index}
573
+ total={pages.length}
574
+ geometry={geometry}
575
+ scale={scale}
576
+ design={doc.design}
577
+ >
578
+ {page.content}
579
+ </PageFrame>
580
+ ))}
581
+ </div>
537
582
  </div>
583
+ {import.meta.env.DEV && docId && (
584
+ <EditSaveCard
585
+ textCount={textPending}
586
+ controlsRef={editControlsRef}
587
+ onShownChange={setCardShown}
588
+ />
589
+ )}
538
590
  </div>
539
- {inspecting && docId && (
540
- <Inspector docId={docId} containerRef={scrollRef} onExit={() => setInspecting(false)} />
591
+ {editing && docId && (
592
+ // Keyed by document: a selection, or an editor carried across a
593
+ // reload by source location, must never follow into another
594
+ // document where the same line:column is something else entirely.
595
+ <Inspector
596
+ key={docId}
597
+ docId={docId}
598
+ containerRef={scrollRef}
599
+ panelHidden={designOpen}
600
+ quiet={cardShown}
601
+ onExit={() => setEditing(false)}
602
+ exitRef={leaveEditRef}
603
+ controlsRef={editControlsRef}
604
+ onPendingChange={setTextPending}
605
+ />
541
606
  )}
542
607
  {designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
543
608
  </div>
@@ -545,9 +610,14 @@ export function Doc() {
545
610
  );
546
611
 
547
612
  // The design panel writes back to source through the dev server, so it only
548
- // exists while `open-doc dev` is running.
613
+ // exists while `open-doc dev` is running. The history is per document: an
614
+ // undo step from one must never replay onto another.
549
615
  if (!import.meta.env.DEV || !docId) return view;
550
- return <DesignProvider docId={docId}>{view}</DesignProvider>;
616
+ return (
617
+ <HistoryProvider key={docId}>
618
+ <DesignProvider docId={docId}>{view}</DesignProvider>
619
+ </HistoryProvider>
620
+ );
551
621
  }
552
622
 
553
623
  /**
@@ -46,10 +46,51 @@
46
46
  --border: oklch(0.28 0 0);
47
47
  }
48
48
 
49
+ /* The dock's content arrives from the edge it docks against. Opacity only
50
+ when motion is reduced; never the width, which would reflow the pages. */
51
+ @keyframes od-panel-in {
52
+ from {
53
+ opacity: 0;
54
+ transform: translateX(8px);
55
+ }
56
+ }
57
+ @keyframes od-fade-in {
58
+ from {
59
+ opacity: 0;
60
+ }
61
+ }
62
+ @keyframes od-card-in {
63
+ from {
64
+ opacity: 0;
65
+ translate: 0 6px;
66
+ }
67
+ }
68
+ .od-panel-in {
69
+ animation: od-panel-in 150ms ease-out;
70
+ }
71
+ /* The save card rises from the edge it sits on; `translate` rather than
72
+ `transform`, which already centres it. */
73
+ .od-card-in {
74
+ animation: od-card-in 150ms ease-out;
75
+ }
76
+ @media (prefers-reduced-motion: reduce) {
77
+ .od-panel-in,
78
+ .od-card-in {
79
+ animation-name: od-fade-in;
80
+ }
81
+ }
82
+
49
83
  @layer base {
50
84
  * {
51
85
  border-color: var(--border);
52
86
  }
87
+ /* The sheet is paper in both themes. Left alone, a selection on it takes the
88
+ dark theme's highlight — a muddy slate on white — so it takes the
89
+ inspector's blue instead, the colour of the frame around the text. */
90
+ [data-od-page] ::selection {
91
+ background-color: rgb(59 130 246 / 0.3);
92
+ color: inherit;
93
+ }
53
94
  /* A heading's space-above is what separates it from the section before it —
54
95
  but at the top of a page that space is just a dent. Strip it there so the
55
96
  first block of every flow page starts flush with the margin. */