@open-press/core 0.7.1 → 1.0.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 (144) hide show
  1. package/README.md +6 -3
  2. package/engine/cli.mjs +8 -8
  3. package/engine/commands/_shared.mjs +37 -15
  4. package/engine/commands/dev.mjs +2 -2
  5. package/engine/commands/image.mjs +29 -0
  6. package/engine/commands/skills-sync.mjs +71 -0
  7. package/engine/commands/typecheck.mjs +63 -1
  8. package/engine/commands/upgrade.mjs +3 -3
  9. package/engine/document-export.mjs +1 -1
  10. package/engine/output/chrome-pdf.mjs +110 -3
  11. package/engine/output/static-server.mjs +87 -9
  12. package/engine/react/comment-endpoint.mjs +13 -39
  13. package/engine/react/comment-marker.mjs +43 -19
  14. package/engine/react/document-entry.mjs +46 -28
  15. package/engine/react/document-export.mjs +328 -164
  16. package/engine/react/http-json.mjs +24 -0
  17. package/engine/react/mdx-compile.mjs +126 -3
  18. package/engine/react/measurement-css.mjs +114 -1
  19. package/engine/react/object-entities.mjs +204 -0
  20. package/engine/react/pagination/allocator.mjs +48 -3
  21. package/engine/react/pagination.mjs +1 -1
  22. package/engine/react/pipeline/allocate.mjs +41 -72
  23. package/engine/react/pipeline/frame-measurement.mjs +6 -0
  24. package/engine/react/press-tree-inspection.mjs +172 -0
  25. package/engine/react/project-asset-endpoint.mjs +6 -24
  26. package/engine/react/source-edit-endpoint.d.mts +10 -0
  27. package/engine/react/source-edit-endpoint.mjs +75 -0
  28. package/engine/react/sources/mdx-resolver.mjs +13 -15
  29. package/engine/react/style-discovery.mjs +23 -8
  30. package/engine/runtime/config.d.mts +8 -0
  31. package/engine/runtime/config.mjs +57 -60
  32. package/engine/runtime/file-utils.mjs +9 -1
  33. package/engine/runtime/file-walk.mjs +22 -0
  34. package/engine/runtime/inspection.mjs +1 -20
  35. package/engine/runtime/page-geometry.mjs +131 -0
  36. package/engine/runtime/path-utils.mjs +20 -0
  37. package/engine/runtime/source-text-tools.d.mts +102 -0
  38. package/engine/runtime/source-text-tools.mjs +551 -16
  39. package/engine/runtime/source-workspace.mjs +16 -34
  40. package/engine/runtime/validation.mjs +19 -10
  41. package/package.json +3 -5
  42. package/src/openpress/app/OpenPressApp.tsx +296 -0
  43. package/src/openpress/{renderer.tsx → app/OpenPressRuntime.tsx} +20 -9
  44. package/src/openpress/app/WorkspaceGalleryPage.tsx +219 -0
  45. package/src/openpress/app/index.ts +2 -0
  46. package/src/openpress/core/Frame.tsx +26 -15
  47. package/src/openpress/core/FrameContext.tsx +10 -3
  48. package/src/openpress/core/MdxArea.tsx +11 -12
  49. package/src/openpress/core/Press.tsx +25 -4
  50. package/src/openpress/core/Workspace.tsx +36 -0
  51. package/src/openpress/core/cn.ts +4 -0
  52. package/src/openpress/core/index.tsx +11 -3
  53. package/src/openpress/core/primitives.tsx +74 -6
  54. package/src/openpress/core/types.ts +94 -41
  55. package/src/openpress/core/useSource.ts +1 -1
  56. package/src/openpress/{anchorMap.ts → document-model/anchorMapModel.ts} +1 -1
  57. package/src/openpress/{indexes.ts → document-model/documentIndexes.ts} +1 -1
  58. package/src/openpress/{types.ts → document-model/documentTypes.ts} +51 -0
  59. package/src/openpress/document-model/index.ts +7 -0
  60. package/src/openpress/document-model/objectEntityModel.ts +55 -0
  61. package/src/openpress/{projectIdentity.ts → document-model/projectIdentityModel.ts} +1 -1
  62. package/src/openpress/{reactDocumentMetadata.ts → document-model/reactDocumentMetadataModel.ts} +1 -1
  63. package/src/openpress/document-model/workspaceManifestModel.ts +57 -0
  64. package/src/openpress/manuscript/index.tsx +49 -7
  65. package/src/openpress/mdx/index.ts +15 -7
  66. package/src/openpress/reader/PageThumbnailsPanel.tsx +168 -0
  67. package/src/openpress/{publicPage.tsx → reader/PublicReaderPage.tsx} +31 -51
  68. package/src/openpress/{workbenchPanels.tsx → reader/ReaderNavigationPanel.tsx} +6 -5
  69. package/src/openpress/reader/index.ts +11 -0
  70. package/src/openpress/reader/pageViewportScaleModel.ts +73 -0
  71. package/src/openpress/reader/readerTypes.ts +4 -0
  72. package/src/openpress/reader/usePageViewportScale.ts +119 -0
  73. package/src/openpress/reader/usePanelState.ts +56 -0
  74. package/src/openpress/reader/useReaderHashSync.ts +61 -0
  75. package/src/openpress/reader/useReaderKeyboardNav.ts +48 -0
  76. package/src/openpress/reader/useReaderRuntime.ts +146 -0
  77. package/src/openpress/reader/useReaderScrollAnchor.ts +64 -0
  78. package/src/openpress/shared/Panel.tsx +77 -0
  79. package/src/openpress/shared/index.ts +4 -0
  80. package/src/openpress/shared/numberUtils.ts +3 -0
  81. package/src/openpress/{runtimeMode.ts → shared/runtimeMode.ts} +0 -11
  82. package/src/openpress/workbench/Workbench.tsx +506 -0
  83. package/src/openpress/workbench/actions/DeploymentControl.tsx +157 -0
  84. package/src/openpress/workbench/actions/ExportImageControl.tsx +96 -0
  85. package/src/openpress/workbench/actions/PageZoomControl.tsx +182 -0
  86. package/src/openpress/workbench/actions/SearchControl.tsx +345 -0
  87. package/src/openpress/workbench/actions/deploymentStatusModel.ts +112 -0
  88. package/src/openpress/workbench/actions/index.ts +6 -0
  89. package/src/openpress/workbench/actions/useDeploymentWorkbench.ts +136 -0
  90. package/src/openpress/workbench/dialog/WorkbenchDialog.tsx +72 -0
  91. package/src/openpress/workbench/dialog/index.ts +1 -0
  92. package/src/openpress/workbench/document/components/DocumentPanel.tsx +127 -0
  93. package/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +207 -0
  94. package/src/openpress/workbench/document/components/ReaderStage.tsx +9 -0
  95. package/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +34 -0
  96. package/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +525 -0
  97. package/src/openpress/workbench/document/index.ts +10 -0
  98. package/src/openpress/workbench/index.ts +2 -0
  99. package/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +459 -0
  100. package/src/openpress/workbench/inspector/index.ts +5 -0
  101. package/src/openpress/workbench/inspector/inlineCommentModel.ts +125 -0
  102. package/src/openpress/workbench/inspector/inspectorGeometryModel.ts +160 -0
  103. package/src/openpress/workbench/inspector/inspectorModel.ts +408 -0
  104. package/src/openpress/workbench/inspector/useInspectorComments.ts +254 -0
  105. package/src/openpress/workbench/mentions/MentionSuggestionList.tsx +41 -0
  106. package/src/openpress/workbench/mentions/index.ts +2 -0
  107. package/src/openpress/{composerMentions.ts → workbench/mentions/useComposerMentions.ts} +1 -4
  108. package/src/openpress/workbench/panels/Panel.tsx +1 -0
  109. package/src/openpress/workbench/panels/PendingCommentsPanel.tsx +80 -0
  110. package/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +29 -0
  111. package/src/openpress/workbench/panels/index.ts +3 -0
  112. package/src/openpress/workbench/project/ProjectEntryPanel.tsx +525 -0
  113. package/src/openpress/workbench/project/ProjectPreviewDialog.tsx +35 -0
  114. package/src/openpress/workbench/project/index.ts +2 -0
  115. package/src/openpress/workbench/project/projectPreviewTypes.ts +11 -0
  116. package/src/openpress/workbench/shell/WorkbenchShell.tsx +167 -0
  117. package/src/openpress/workbench/shell/index.ts +1 -0
  118. package/src/openpress/workbench/workbenchFormatters.ts +120 -0
  119. package/src/openpress/workbench/workbenchTypes.ts +35 -0
  120. package/src/styles/openpress/print-route.css +0 -2
  121. package/src/styles/openpress/{project-workspace.css → project-preview-panel.css} +13 -407
  122. package/src/styles/openpress/public-viewer.css +25 -320
  123. package/src/styles/openpress/reader-runtime.css +252 -55
  124. package/src/styles/openpress/responsive.css +145 -270
  125. package/src/styles/openpress/workbench-panels.css +327 -178
  126. package/src/styles/openpress/workbench.css +986 -451
  127. package/src/styles/openpress/workspace-gallery.css +300 -0
  128. package/src/styles/openpress.css +2 -1
  129. package/tsconfig.json +1 -1
  130. package/vite.config.ts +50 -0
  131. package/engine/commands/init.mjs +0 -24
  132. package/engine/init.mjs +0 -90
  133. package/src/openpress/App.tsx +0 -127
  134. package/src/openpress/inspector.ts +0 -282
  135. package/src/openpress/projectWorkspace.tsx +0 -919
  136. package/src/openpress/readerRuntime.ts +0 -230
  137. package/src/openpress/workbench.tsx +0 -1265
  138. package/src/openpress/workbenchTypes.ts +0 -4
  139. /package/src/openpress/{readerPageRegistry.ts → reader/readerPageRegistry.ts} +0 -0
  140. /package/src/openpress/{pageRoute.ts → reader/readerPageRoute.ts} +0 -0
  141. /package/src/openpress/{readerScroll.ts → reader/readerScroll.ts} +0 -0
  142. /package/src/openpress/{readerState.ts → reader/readerStateModel.ts} +0 -0
  143. /package/src/openpress/{frameScheduler.ts → shared/frameScheduler.ts} +0 -0
  144. /package/src/openpress/{projectSources.ts → workbench/project/projectSourceModel.ts} +0 -0
@@ -1,18 +1,15 @@
1
- import { useContext, type ReactNode } from "react";
1
+ import { useContext } from "react";
2
+ import { cn } from "./cn";
2
3
  import { FrameContext, type FrameContextValue } from "./FrameContext";
3
4
  import { PressContext } from "./Press";
4
5
  import type { FrameProps } from "./types";
6
+ import { createFrameObjectEntityId, createPageObjectEntityId, createScopedObjectEntityId } from "../document-model/objectEntityModel";
5
7
 
6
8
  // Substring reserved for the overflow extension pipeline.
7
9
  const RESERVED_EXTENDED = ":extended:";
8
10
 
9
11
  export const FRAME_MARKER: unique symbol = Symbol.for("@open-press/core:Frame");
10
12
 
11
- function classNames(...values: Array<string | undefined>) {
12
- const joined = values.filter(Boolean).join(" ");
13
- return joined.length > 0 ? joined : undefined;
14
- }
15
-
16
13
  export function Frame({
17
14
  frameKey,
18
15
  role,
@@ -31,37 +28,51 @@ export function Frame({
31
28
  );
32
29
  }
33
30
 
31
+ const parentFrame = useContext(FrameContext);
34
32
  const press = useContext(PressContext);
35
33
  const allocation = press?.allocation ?? null;
36
34
  const frameAllocation = frameKey && allocation ? allocation[frameKey] : undefined;
35
+ const pageId = parentFrame?.pageId ?? createPageObjectEntityId(frameKey);
36
+ const objectId = parentFrame
37
+ ? createScopedObjectEntityId("frame", parentFrame.objectId, frameKey)
38
+ : createFrameObjectEntityId(frameKey);
37
39
 
38
40
  // Mutable per-render counter. SSR renders a Frame exactly once, so a plain
39
41
  // object is fine — no useRef needed.
40
42
  const areaCounts: Record<string, number> = {};
41
43
  const frameContextValue: FrameContextValue = {
42
44
  frameKey: frameKey ?? "",
43
- consumeArea(chainId: string): ReactNode | null {
45
+ objectId,
46
+ pageId,
47
+ consumeArea(chainId: string) {
44
48
  const index = areaCounts[chainId] ?? 0;
45
49
  areaCounts[chainId] = index + 1;
46
- if (!frameAllocation) return null;
50
+ if (!frameAllocation) return { indexInFrame: index, blocks: null };
47
51
  const chainSlots = frameAllocation[chainId];
48
- if (!chainSlots) return null;
49
- return chainSlots[index] ?? null;
52
+ if (!chainSlots) return { indexInFrame: index, blocks: null };
53
+ return { indexInFrame: index, blocks: chainSlots[index] ?? null };
50
54
  },
51
55
  };
52
56
 
53
57
  const pageKind = derivePageKind(role);
58
+ const isNestedFrame = Boolean(parentFrame);
54
59
 
55
60
  return (
56
61
  <FrameContext.Provider value={frameContextValue}>
57
62
  <section
58
63
  {...(rest as Record<string, unknown>)}
59
- className={classNames("reader-page", className)}
60
- data-openpress-frame-key={frameKey}
64
+ className={cn(isNestedFrame ? undefined : "reader-page", className)}
65
+ data-openpress-frame-key={isNestedFrame ? undefined : frameKey}
66
+ data-openpress-region-frame-key={isNestedFrame ? frameKey : undefined}
67
+ data-openpress-object-id={objectId}
68
+ data-openpress-object-kind="frame"
69
+ data-openpress-object-label={role ?? frameKey}
70
+ data-openpress-object-parent-id={parentFrame?.objectId ?? (isNestedFrame ? undefined : pageId)}
71
+ data-openpress-object-page-id={pageId}
61
72
  data-frame-role={role}
62
- data-page-kind={pageKind}
63
- data-frame-chrome={chrome ? "true" : "false"}
64
- data-page-footer={chrome ? "true" : "false"}
73
+ data-page-kind={isNestedFrame ? undefined : pageKind}
74
+ data-frame-chrome={isNestedFrame ? undefined : chrome ? "true" : "false"}
75
+ data-page-footer={isNestedFrame ? undefined : chrome ? "true" : "false"}
65
76
  >
66
77
  {children}
67
78
  </section>
@@ -9,11 +9,18 @@ import { createContext, type ReactNode } from "react";
9
9
  // and so on. Empty Frames (no allocation) return null, which renders the
10
10
  // MdxArea as a measurement placeholder.
11
11
 
12
+ export interface ConsumedMdxArea {
13
+ indexInFrame: number;
14
+ // Null when the frame has no allocation (measurement pass) or no blocks
15
+ // for this chain at the claimed index.
16
+ blocks: ReactNode | null;
17
+ }
18
+
12
19
  export interface FrameContextValue {
13
20
  frameKey: string;
14
- // Consume the next allocation slot for this chainId. Returns null if the
15
- // frame has no allocation (measurement pass) or no blocks for this chain.
16
- consumeArea(chainId: string): ReactNode | null;
21
+ objectId: string;
22
+ pageId: string;
23
+ consumeArea(chainId: string): ConsumedMdxArea;
17
24
  }
18
25
 
19
26
  export const FrameContext = createContext<FrameContextValue | null>(null);
@@ -1,11 +1,8 @@
1
1
  import { useContext, type ReactNode } from "react";
2
+ import { cn } from "./cn";
2
3
  import { FrameContext } from "./FrameContext";
3
4
  import type { MdxAreaProps } from "./types";
4
-
5
- function classNames(...values: Array<string | undefined>) {
6
- const joined = values.filter(Boolean).join(" ");
7
- return joined.length > 0 ? joined : undefined;
8
- }
5
+ import { createMdxAreaObjectEntityId } from "../document-model/objectEntityModel";
9
6
 
10
7
  export function MdxArea({
11
8
  chainId,
@@ -14,20 +11,22 @@ export function MdxArea({
14
11
  ...rest
15
12
  }: MdxAreaProps) {
16
13
  const frame = useContext(FrameContext);
17
-
18
- let blocks: ReactNode | null = null;
19
- if (frame) {
20
- blocks = frame.consumeArea(chainId);
21
- }
14
+ const consumed = frame?.consumeArea(chainId) ?? null;
15
+ const blocks: ReactNode | null = consumed?.blocks ?? null;
16
+ const objectId = frame && consumed
17
+ ? createMdxAreaObjectEntityId(frame.frameKey, chainId, consumed.indexInFrame)
18
+ : undefined;
22
19
 
23
20
  return (
24
21
  <div
25
22
  {...(rest as Record<string, unknown>)}
26
- className={classNames("openpress-mdx-area", className)}
23
+ className={cn("openpress-mdx-area", className)}
27
24
  data-openpress-mdx-area="true"
28
25
  data-openpress-mdx-area-chain={chainId}
26
+ data-openpress-mdx-area-index={consumed?.indexInFrame}
27
+ data-openpress-object-id={objectId}
29
28
  data-openpress-mdx-area-overflow={overflow}
30
- data-openpress-mdx-area-empty={blocks == null ? "true" : undefined}
29
+ data-openpress-mdx-area-empty={blocks == null ? "true" : "false"}
31
30
  >
32
31
  {blocks}
33
32
  </div>
@@ -1,5 +1,5 @@
1
- import { createContext, Fragment, type ReactNode } from "react";
2
- import type { FrameAllocation, ResolvedSource, TocEntry } from "./types";
1
+ import { createContext, Fragment } from "react";
2
+ import type { FrameAllocation, PressProps, ResolvedSource, TocEntry } from "./types";
3
3
 
4
4
  // Marker the engine uses to distinguish a Press default export from any other
5
5
  // React component. Workspaces register a default export whose `type` is this
@@ -14,6 +14,18 @@ export interface AllocationHints {
14
14
  totalPagesPerChain: Record<string, number>;
15
15
  }
16
16
 
17
+ // Metadata read from <Press> props by the engine pipeline. The 1.0 contract
18
+ // declares these on the component; v0.x reads them from openpress.config.mjs
19
+ // instead and leaves these as undefined. The engine merges both sources
20
+ // (props override config) until v1.0 removes config support.
21
+ export interface PressMetadata {
22
+ title?: string;
23
+ page?: PressProps["page"];
24
+ slug?: string;
25
+ theme?: string;
26
+ componentsDir?: string;
27
+ }
28
+
17
29
  export interface PressContextValue {
18
30
  sources: Record<string, ResolvedSource>;
19
31
  // Allocation map keyed by frameKey -> chainId -> areaIndex -> blocks.
@@ -23,12 +35,21 @@ export interface PressContextValue {
23
35
  // the first measurement pass.
24
36
  hints: AllocationHints | null;
25
37
  toc: Record<string, TocEntry[]> | null;
38
+ // Metadata declared on <Press> props in v1.0. Engine providers may
39
+ // omit this on v0.x; consumers should treat undefined as "no metadata
40
+ // declared on Press — fall back to openpress.config.mjs values".
41
+ metadata?: PressMetadata;
26
42
  }
27
43
 
28
44
  export const PressContext = createContext<PressContextValue | null>(null);
29
45
 
30
- export function Press({ children }: { children: ReactNode }) {
31
- return <Fragment>{children}</Fragment>;
46
+ export function Press(props: PressProps) {
47
+ // Press is intentionally inert at render time — the engine reads its
48
+ // props and children through React.Children inspection during the
49
+ // export pipeline, then injects context above any nested helpers.
50
+ // For the v0.x shape (children-only usage), this still passes children
51
+ // through unchanged.
52
+ return <Fragment>{props.children}</Fragment>;
32
53
  }
33
54
 
34
55
  (Press as unknown as { openpressMarker: typeof PRESS_MARKER }).openpressMarker = PRESS_MARKER;
@@ -0,0 +1,36 @@
1
+ import { createContext, Fragment } from "react";
2
+ import type { WorkspaceProps } from "./types";
3
+
4
+ // Marker the engine uses to identify a Workspace default export, in the
5
+ // same way PRESS_MARKER identifies Press. Multi-doc projects nest one
6
+ // or more <Press> children inside <Workspace>; single-doc projects use
7
+ // a Workspace with one Press child (uniform shape — no exceptions).
8
+ export const WORKSPACE_MARKER: unique symbol = Symbol.for("@open-press/core:Workspace");
9
+
10
+ export interface WorkspaceContextValue {
11
+ // Project-level label surfaced in the gallery header / tab bar / PDF
12
+ // metadata. Undefined if the Workspace did not declare a name.
13
+ name?: string;
14
+ // Workspace-level shared theme directory. Press children that don't
15
+ // set their own `theme` prop inherit from this.
16
+ theme?: string;
17
+ // Workspace-level shared media directory.
18
+ media?: string;
19
+ // Number of Press children registered in this Workspace. Set by the
20
+ // engine during expansion; useful to detect "gallery vs single-doc"
21
+ // routing without re-walking the tree.
22
+ pressCount: number;
23
+ }
24
+
25
+ export const WorkspaceContext = createContext<WorkspaceContextValue | null>(null);
26
+
27
+ // Workspace is intentionally inert at render time. The engine inspects
28
+ // its props (name / theme / media) and iterates Press children during
29
+ // the export pipeline; rendering just passes children through so the
30
+ // Press → Frame → MdxArea tree underneath behaves identically to v0.x
31
+ // when there's only one Press child.
32
+ export function Workspace(props: WorkspaceProps) {
33
+ return <Fragment>{props.children}</Fragment>;
34
+ }
35
+
36
+ (Workspace as unknown as { openpressMarker: typeof WORKSPACE_MARKER }).openpressMarker = WORKSPACE_MARKER;
@@ -0,0 +1,4 @@
1
+ export function cn(...values: Array<string | false | null | undefined>) {
2
+ const joined = values.filter(Boolean).join(" ");
3
+ return joined.length > 0 ? joined : undefined;
4
+ }
@@ -6,11 +6,12 @@
6
6
  // the engine is not allowed to know about higher-level conventions.
7
7
 
8
8
  export { Press, PressContext, PRESS_MARKER } from "./Press";
9
+ export { Workspace, WorkspaceContext, WORKSPACE_MARKER } from "./Workspace";
9
10
  export { Frame, FRAME_MARKER } from "./Frame";
10
11
  export { FrameContext } from "./FrameContext";
11
12
  export { MdxArea } from "./MdxArea";
12
13
  export { useSource } from "./useSource";
13
- export { BaseFigure, BaseCallout } from "./primitives";
14
+ export { ObjectEntity, Text, BaseFigure, BaseCallout, MediaFigure, ImageFigure } from "./primitives";
14
15
 
15
16
  export type {
16
17
  FrameProps,
@@ -18,10 +19,16 @@ export type {
18
19
  MdxAreaProps,
19
20
  MdxAreaOverflow,
20
21
  PressProps,
22
+ PageGeometry,
23
+ PressSource,
24
+ WorkspaceProps,
21
25
  BaseFigureProps,
26
+ MediaFigureProps,
22
27
  BaseCalloutKind,
23
28
  BaseCalloutProps,
24
- Manifest,
29
+ ObjectEntityElement,
30
+ ObjectEntityProps,
31
+ TextProps,
25
32
  // Source-side types are re-exported here for convenience so authors can
26
33
  // import `ResolvedSource` from the same place they import primitives.
27
34
  ResolvedSource,
@@ -35,5 +42,6 @@ export type {
35
42
  FrameAllocation,
36
43
  } from "./types";
37
44
 
38
- export type { PressContextValue, AllocationHints } from "./Press";
45
+ export type { PressContextValue, AllocationHints, PressMetadata } from "./Press";
46
+ export type { WorkspaceContextValue } from "./Workspace";
39
47
  export type { FrameContextValue } from "./FrameContext";
@@ -1,13 +1,56 @@
1
- import type { BaseCalloutProps, BaseFigureProps } from "./types";
1
+ import { cn } from "./cn";
2
+ import { useContext } from "react";
3
+ import { FrameContext } from "./FrameContext";
4
+ import type { BaseCalloutProps, BaseFigureProps, MediaFigureProps, ObjectEntityProps, TextProps } from "./types";
5
+ import { createScopedObjectEntityId } from "../document-model/objectEntityModel";
2
6
 
3
- function classNames(...values: Array<string | undefined>) {
4
- const joined = values.filter(Boolean).join(" ");
5
- return joined.length > 0 ? joined : undefined;
7
+ export function ObjectEntity({
8
+ as: Element = "span",
9
+ objectId,
10
+ kind,
11
+ label,
12
+ parentId,
13
+ pageId,
14
+ blockId,
15
+ frameKey,
16
+ chainId,
17
+ source,
18
+ metadata,
19
+ children,
20
+ ...entityProps
21
+ }: ObjectEntityProps) {
22
+ const frame = useContext(FrameContext);
23
+ const resolvedParentId = parentId ?? frame?.objectId;
24
+ const resolvedPageId = pageId ?? frame?.pageId;
25
+ const resolvedFrameKey = frameKey ?? frame?.frameKey;
26
+ const resolvedObjectId = createScopedObjectEntityId(kind, resolvedParentId, objectId);
27
+
28
+ return (
29
+ <Element
30
+ {...entityProps}
31
+ data-openpress-object-id={resolvedObjectId}
32
+ data-openpress-object-kind={kind}
33
+ data-openpress-object-label={label}
34
+ data-openpress-object-parent-id={resolvedParentId}
35
+ data-openpress-object-page-id={resolvedPageId}
36
+ data-openpress-block-id={blockId}
37
+ data-openpress-object-frame-key={resolvedFrameKey}
38
+ data-openpress-object-chain-id={chainId}
39
+ data-openpress-object-source={source ? JSON.stringify(source) : undefined}
40
+ data-openpress-object-metadata={metadata ? JSON.stringify(metadata) : undefined}
41
+ >
42
+ {children}
43
+ </Element>
44
+ );
45
+ }
46
+
47
+ export function Text(props: TextProps) {
48
+ return <ObjectEntity {...props} kind="text" />;
6
49
  }
7
50
 
8
51
  export function BaseFigure({ caption, className, children, ...figureProps }: BaseFigureProps) {
9
52
  return (
10
- <figure {...figureProps} className={classNames("openpress-figure", className)}>
53
+ <figure {...figureProps} className={cn("openpress-figure", className)}>
11
54
  <div data-figure-body>{children}</div>
12
55
  {caption === undefined ? null : <figcaption>{caption}</figcaption>}
13
56
  </figure>
@@ -16,8 +59,33 @@ export function BaseFigure({ caption, className, children, ...figureProps }: Bas
16
59
 
17
60
  export function BaseCallout({ kind = "info", className, children, ...calloutProps }: BaseCalloutProps) {
18
61
  return (
19
- <aside {...calloutProps} className={classNames("openpress-callout", className)} data-callout-kind={kind}>
62
+ <aside {...calloutProps} className={cn("openpress-callout", className)} data-callout-kind={kind}>
20
63
  {children}
21
64
  </aside>
22
65
  );
23
66
  }
67
+
68
+ export function MediaFigure({
69
+ src,
70
+ alt,
71
+ caption,
72
+ className,
73
+ imgClassName,
74
+ loading = "eager",
75
+ ...figureProps
76
+ }: MediaFigureProps) {
77
+ return (
78
+ <BaseFigure {...figureProps} className={cn("openpress-media-figure", className)} caption={caption}>
79
+ <img src={resolveMediaSrc(src)} alt={alt} loading={loading} className={imgClassName} />
80
+ </BaseFigure>
81
+ );
82
+ }
83
+
84
+ export const ImageFigure = MediaFigure;
85
+
86
+ function resolveMediaSrc(src: string) {
87
+ const trimmed = String(src ?? "").trim();
88
+ if (!trimmed) return "";
89
+ if (/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(trimmed)) return trimmed;
90
+ return `/openpress/media/${trimmed.replace(/^\.?\/*/, "")}`;
91
+ }
@@ -1,4 +1,5 @@
1
1
  import type { HTMLAttributes, ReactNode } from "react";
2
+ import type { EditableSourceRef, ObjectEntityKind } from "../document-model/documentTypes";
2
3
 
3
4
  // ---------------------------------------------------------------------------
4
5
  // Frame / MdxArea / Press primitives
@@ -25,8 +26,72 @@ export type MdxAreaProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
25
26
  className?: string;
26
27
  };
27
28
 
29
+ // PageGeometry — a custom fixed-size geometry passed to <Press page>.
30
+ // Same shape as the engine's normalized geometry (CSS lengths,
31
+ // matching units between width / height).
32
+ export interface PageGeometry {
33
+ id?: string;
34
+ label?: string;
35
+ preset?: string;
36
+ width: string;
37
+ height: string;
38
+ }
39
+
40
+ // Source descriptor passed inside <Press sources>. The actual type is
41
+ // the return value of mdxSource() from @open-press/core/mdx; we accept
42
+ // "unknown" at the core boundary to avoid a circular type dependency.
43
+ // The engine validates the shape at render time.
44
+ export type PressSource = unknown;
45
+
28
46
  export interface PressProps {
47
+ // Document tree — Frames, manuscript helpers, etc.
48
+ children: ReactNode;
49
+ // -------------------------------------------------------------------------
50
+ // 1.0 metadata props — optional during v0.x deprecation, required in v1.0.
51
+ // -------------------------------------------------------------------------
52
+ // Document title. Required in 1.0. Used for PDF metadata, HTML <title>,
53
+ // OG tags, and the Workspace gallery / tab-bar label.
54
+ title?: string;
55
+ // Page geometry preset name or a custom geometry object. Optional;
56
+ // workspace default applies if not set.
57
+ page?: "a4" | "social-square" | "slide-16-9" | PageGeometry;
58
+ // Array of source registrations from mdxSource(). Replaces the v0.x
59
+ // `export const sources` named export.
60
+ sources?: ReadonlyArray<PressSource>;
61
+ // URL / output slug for this Press inside a Workspace. Defaults to
62
+ // "/" when only one Press exists in the Workspace; required when the
63
+ // Workspace has multiple Press children.
64
+ slug?: string;
65
+ // Optional per-Press theme directory. Defaults to "./theme" relative
66
+ // to the document file; inherits from <Workspace theme> if not set.
67
+ theme?: string;
68
+ // Optional per-Press components directory. Default "./components".
69
+ componentsDir?: string;
70
+ // Optional caption numbering overrides. Engine defaults to
71
+ // { figure: "Figure", table: "Table", separator: " " }.
72
+ captionNumbering?: {
73
+ figure?: string;
74
+ table?: string;
75
+ separator?: string;
76
+ };
77
+ }
78
+
79
+ // ---------------------------------------------------------------------------
80
+ // Workspace — root component holding one or more Press children
81
+ // ---------------------------------------------------------------------------
82
+
83
+ export interface WorkspaceProps {
84
+ // One or more <Press> children. 1 child = single-doc workspace; N
85
+ // children = multi-doc workspace (proposal + pitch + social, etc).
29
86
  children: ReactNode;
87
+ // Project label surfaced in the gallery header, tab bar, and PDF
88
+ // metadata. Optional.
89
+ name?: string;
90
+ // Workspace-level shared theme directory. Press children that don't
91
+ // set their own `theme` prop inherit from this. Default "./theme".
92
+ theme?: string;
93
+ // Workspace-level shared media directory. Default "./media".
94
+ media?: string;
30
95
  }
31
96
 
32
97
  // ---------------------------------------------------------------------------
@@ -38,6 +103,14 @@ export type BaseFigureProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
38
103
  children: ReactNode;
39
104
  };
40
105
 
106
+ export type MediaFigureProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
107
+ src: string;
108
+ alt: string;
109
+ caption: ReactNode;
110
+ imgClassName?: string;
111
+ loading?: "eager" | "lazy";
112
+ };
113
+
41
114
  export type BaseCalloutKind = "info" | "warn" | "success" | "error" | (string & {});
42
115
 
43
116
  export type BaseCalloutProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
@@ -45,6 +118,27 @@ export type BaseCalloutProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
45
118
  children: ReactNode;
46
119
  };
47
120
 
121
+ export type ObjectEntityElement = "span" | "div" | "section" | "article" | "figure" | "p";
122
+
123
+ export type ObjectEntityProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
124
+ as?: ObjectEntityElement;
125
+ objectId: string;
126
+ kind: ObjectEntityKind;
127
+ label: string;
128
+ parentId?: string;
129
+ pageId?: string;
130
+ blockId?: string;
131
+ frameKey?: string;
132
+ chainId?: string;
133
+ source?: EditableSourceRef;
134
+ metadata?: Record<string, string | number | boolean | null>;
135
+ children?: ReactNode;
136
+ };
137
+
138
+ export type TextProps = Omit<ObjectEntityProps, "kind"> & {
139
+ as?: "span" | "div" | "p";
140
+ };
141
+
48
142
  // ---------------------------------------------------------------------------
49
143
  // Source descriptors and resolved sources
50
144
  // ---------------------------------------------------------------------------
@@ -140,44 +234,3 @@ export interface ResolvedSource {
140
234
  // MdxArea by area index.
141
235
  export type FrameAllocation = Record<string, Record<string, ReactNode[]>>;
142
236
 
143
- // ---------------------------------------------------------------------------
144
- // Manifest
145
- // ---------------------------------------------------------------------------
146
-
147
- export interface Manifest {
148
- title: string;
149
- subtitle?: string;
150
- organization?: string;
151
- workspaceLabel?: string;
152
- documentDir?: string;
153
- sourceDir?: string;
154
- componentsDir?: string;
155
- mediaDir?: string;
156
- themeDir?: string;
157
- designDoc?: string;
158
- publicDir?: string;
159
- outputDir?: string;
160
- captionNumbering?: {
161
- figure?: string;
162
- table?: string;
163
- separator?: string;
164
- };
165
- pdf?: {
166
- filename?: string;
167
- };
168
- deploy?: {
169
- adapter?: string;
170
- source?: string;
171
- projectName?: string | null;
172
- commitDirty?: boolean;
173
- requiresConfirmation?: boolean;
174
- };
175
- paths?: {
176
- chaptersDir?: string;
177
- sourceDir?: string;
178
- componentsDir?: string;
179
- mediaDir?: string;
180
- themeDir?: string;
181
- designDoc?: string;
182
- };
183
- }
@@ -21,7 +21,7 @@ export function useSource<T extends ResolvedSource = ResolvedSource>(id: string)
21
21
  const knownText = known.length > 0 ? known.join(", ") : "(none)";
22
22
  throw new Error(
23
23
  `Unknown source "${id}". Available sources: ${knownText}. ` +
24
- `Register it under \`export const sources\` in document/index.tsx.`,
24
+ `Register it as a <Press sources={[mdxSource({ id: "${id}", ... })]}> entry in press/index.tsx.`,
25
25
  );
26
26
  }
27
27
  return source as T;
@@ -3,7 +3,7 @@
3
3
  // `PublicPage` / `HtmlWorkbench` HMR-clean (Fast Refresh expects component
4
4
  // files to export only components).
5
5
 
6
- import type { DisplayPage } from "./workbenchTypes";
6
+ import type { DisplayPage } from "../reader";
7
7
 
8
8
  export function createAnchorPageMap(pages: DisplayPage[]) {
9
9
  const map = new Map<string, number>();
@@ -1,4 +1,4 @@
1
- import type { BlockSource } from "./types";
1
+ import type { BlockSource } from "./documentTypes";
2
2
 
3
3
  export type MediaAssetKind = "image" | "svg";
4
4
 
@@ -25,6 +25,7 @@ export interface DocumentSource {
25
25
  editMode?: string;
26
26
  styles?: DocumentStyle[];
27
27
  blockMap?: Record<string, SourceBlock>;
28
+ objectEntities?: Record<string, ObjectEntity>;
28
29
  }
29
30
 
30
31
  export interface DocumentStyle {
@@ -49,6 +50,9 @@ export interface SourceBlock {
49
50
  pageIndex?: number;
50
51
  pageNumber?: number;
51
52
  source?: SourceLocation;
53
+ frameKey?: string;
54
+ chainId?: string;
55
+ sectionSlug?: string;
52
56
  }
53
57
 
54
58
  export interface DocumentMeta {
@@ -61,8 +65,12 @@ export interface DocumentMeta {
61
65
  }
62
66
 
63
67
  export interface Theme {
68
+ pagePreset?: string;
69
+ pageLabel?: string;
64
70
  pageWidth?: string;
65
71
  pageHeight?: string;
72
+ pageAspectRatio?: string;
73
+ pageHeightRatio?: string;
66
74
  pagePadding?: string;
67
75
  fontFamily?: string;
68
76
  accentColor?: string;
@@ -93,4 +101,47 @@ export interface HtmlPageBlock {
93
101
  anchors?: string[];
94
102
  className?: string;
95
103
  source?: BlockSource;
104
+ frameKey?: string;
105
+ role?: string | null;
106
+ chrome?: boolean;
107
+ blockIds?: string[];
108
+ }
109
+
110
+ export type ObjectEntityKind =
111
+ | "page"
112
+ | "frame"
113
+ | "mdx-area"
114
+ | "mdx-block"
115
+ | "text"
116
+ | "component"
117
+ | "media";
118
+
119
+ export interface EditableSourceRef {
120
+ path: string;
121
+ file?: string;
122
+ kind?: string;
123
+ objectId?: string;
124
+ scope?: string;
125
+ component?: string;
126
+ source?: SourceLocation;
127
+ line?: number;
128
+ column?: number;
129
+ }
130
+
131
+ export interface ObjectEntityRef {
132
+ id: string;
133
+ kind: ObjectEntityKind;
134
+ }
135
+
136
+ export interface ObjectEntity {
137
+ id: string;
138
+ kind: ObjectEntityKind;
139
+ label: string;
140
+ parentId?: string;
141
+ pageId?: string;
142
+ blockId?: string;
143
+ frameKey?: string;
144
+ chainId?: string;
145
+ source?: EditableSourceRef;
146
+ metadata?: Record<string, string | number | boolean | null>;
96
147
  }
@@ -0,0 +1,7 @@
1
+ export * from "./anchorMapModel";
2
+ export * from "./documentIndexes";
3
+ export * from "./documentTypes";
4
+ export * from "./objectEntityModel";
5
+ export * from "./projectIdentityModel";
6
+ export * from "./reactDocumentMetadataModel";
7
+ export * from "./workspaceManifestModel";