@open-press/cli 0.8.0 → 1.1.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 (250) hide show
  1. package/README.md +33 -23
  2. package/dist/cli.js +320 -252
  3. package/package.json +9 -8
  4. package/template/core/AGENTS.md +0 -126
  5. package/template/core/CHANGELOG.md +0 -215
  6. package/template/core/README.md +0 -40
  7. package/template/core/engine/cli.mjs +0 -96
  8. package/template/core/engine/commands/_shared.mjs +0 -177
  9. package/template/core/engine/commands/deploy.mjs +0 -31
  10. package/template/core/engine/commands/dev.mjs +0 -49
  11. package/template/core/engine/commands/doctor.mjs +0 -229
  12. package/template/core/engine/commands/export.mjs +0 -8
  13. package/template/core/engine/commands/init.mjs +0 -24
  14. package/template/core/engine/commands/inspect.mjs +0 -35
  15. package/template/core/engine/commands/pdf.mjs +0 -26
  16. package/template/core/engine/commands/preview.mjs +0 -26
  17. package/template/core/engine/commands/render.mjs +0 -17
  18. package/template/core/engine/commands/replace.mjs +0 -41
  19. package/template/core/engine/commands/search.mjs +0 -33
  20. package/template/core/engine/commands/typecheck.mjs +0 -5
  21. package/template/core/engine/commands/upgrade.mjs +0 -159
  22. package/template/core/engine/commands/validate.mjs +0 -17
  23. package/template/core/engine/document-export.mjs +0 -15
  24. package/template/core/engine/init.mjs +0 -90
  25. package/template/core/engine/output/chrome-pdf.d.mts +0 -34
  26. package/template/core/engine/output/chrome-pdf.mjs +0 -358
  27. package/template/core/engine/output/deploy-sync.mjs +0 -15
  28. package/template/core/engine/output/fonts.mjs +0 -62
  29. package/template/core/engine/output/katex-assets.mjs +0 -45
  30. package/template/core/engine/output/page-block.mjs +0 -30
  31. package/template/core/engine/output/pdf-media.mjs +0 -45
  32. package/template/core/engine/output/public-assets.mjs +0 -19
  33. package/template/core/engine/output/static-server.mjs +0 -532
  34. package/template/core/engine/react/caption-numbering.mjs +0 -73
  35. package/template/core/engine/react/comment-endpoint.d.mts +0 -11
  36. package/template/core/engine/react/comment-endpoint.mjs +0 -102
  37. package/template/core/engine/react/comment-marker.mjs +0 -374
  38. package/template/core/engine/react/document-entry.mjs +0 -324
  39. package/template/core/engine/react/document-export.mjs +0 -373
  40. package/template/core/engine/react/http-json.mjs +0 -24
  41. package/template/core/engine/react/mdx-compile.mjs +0 -599
  42. package/template/core/engine/react/measurement-css.mjs +0 -136
  43. package/template/core/engine/react/object-entities.mjs +0 -119
  44. package/template/core/engine/react/pagination/allocator.mjs +0 -122
  45. package/template/core/engine/react/pagination/regions.mjs +0 -81
  46. package/template/core/engine/react/pagination-constants.mjs +0 -3
  47. package/template/core/engine/react/pagination.mjs +0 -9
  48. package/template/core/engine/react/pipeline/allocate.mjs +0 -251
  49. package/template/core/engine/react/pipeline/final-render.mjs +0 -94
  50. package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
  51. package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
  52. package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
  53. package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
  54. package/template/core/engine/react/section-css.mjs +0 -56
  55. package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
  56. package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
  57. package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
  58. package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
  59. package/template/core/engine/react/style-discovery.mjs +0 -142
  60. package/template/core/engine/runtime/config.d.mts +0 -40
  61. package/template/core/engine/runtime/config.mjs +0 -175
  62. package/template/core/engine/runtime/file-utils.mjs +0 -106
  63. package/template/core/engine/runtime/file-walk.mjs +0 -22
  64. package/template/core/engine/runtime/inspection.mjs +0 -328
  65. package/template/core/engine/runtime/issue-report.mjs +0 -44
  66. package/template/core/engine/runtime/path-utils.mjs +0 -20
  67. package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
  68. package/template/core/engine/runtime/source-text-tools.mjs +0 -832
  69. package/template/core/engine/runtime/source-workspace.mjs +0 -159
  70. package/template/core/engine/runtime/validation.mjs +0 -174
  71. package/template/core/index.html +0 -13
  72. package/template/core/openpress.config.mjs +0 -12
  73. package/template/core/package.json +0 -91
  74. package/template/core/src/main.tsx +0 -16
  75. package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
  76. package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
  77. package/template/core/src/openpress/app/index.ts +0 -2
  78. package/template/core/src/openpress/core/Frame.tsx +0 -78
  79. package/template/core/src/openpress/core/FrameContext.tsx +0 -24
  80. package/template/core/src/openpress/core/MdxArea.tsx +0 -34
  81. package/template/core/src/openpress/core/Press.tsx +0 -34
  82. package/template/core/src/openpress/core/cn.ts +0 -4
  83. package/template/core/src/openpress/core/index.tsx +0 -40
  84. package/template/core/src/openpress/core/primitives.tsx +0 -44
  85. package/template/core/src/openpress/core/types.ts +0 -191
  86. package/template/core/src/openpress/core/useSource.ts +0 -28
  87. package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
  88. package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
  89. package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
  90. package/template/core/src/openpress/document-model/index.ts +0 -6
  91. package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
  92. package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
  93. package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
  94. package/template/core/src/openpress/manuscript/index.tsx +0 -238
  95. package/template/core/src/openpress/mdx/index.ts +0 -88
  96. package/template/core/src/openpress/numbering/index.ts +0 -294
  97. package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
  98. package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
  99. package/template/core/src/openpress/reader/index.ts +0 -10
  100. package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
  101. package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
  102. package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
  103. package/template/core/src/openpress/reader/readerScroll.ts +0 -92
  104. package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
  105. package/template/core/src/openpress/reader/readerTypes.ts +0 -4
  106. package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
  107. package/template/core/src/openpress/reader/usePanelState.ts +0 -56
  108. package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
  109. package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
  110. package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
  111. package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
  112. package/template/core/src/openpress/shared/Panel.tsx +0 -77
  113. package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
  114. package/template/core/src/openpress/shared/index.ts +0 -4
  115. package/template/core/src/openpress/shared/numberUtils.ts +0 -3
  116. package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
  117. package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
  118. package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
  119. package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
  120. package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
  121. package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
  122. package/template/core/src/openpress/workbench/actions/index.ts +0 -5
  123. package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
  124. package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
  125. package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
  126. package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
  127. package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
  128. package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
  129. package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
  130. package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
  131. package/template/core/src/openpress/workbench/document/index.ts +0 -10
  132. package/template/core/src/openpress/workbench/index.ts +0 -2
  133. package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
  134. package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
  135. package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
  136. package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
  137. package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
  138. package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
  139. package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
  140. package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
  141. package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
  142. package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
  143. package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
  144. package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
  145. package/template/core/src/openpress/workbench/panels/index.ts +0 -3
  146. package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
  147. package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
  148. package/template/core/src/openpress/workbench/project/index.ts +0 -2
  149. package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
  150. package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
  151. package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
  152. package/template/core/src/openpress/workbench/shell/index.ts +0 -1
  153. package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
  154. package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
  155. package/template/core/src/styles/openpress/app-shell.css +0 -251
  156. package/template/core/src/styles/openpress/media-workspace.css +0 -230
  157. package/template/core/src/styles/openpress/print-route.css +0 -184
  158. package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
  159. package/template/core/src/styles/openpress/public-viewer.css +0 -688
  160. package/template/core/src/styles/openpress/reader-runtime.css +0 -980
  161. package/template/core/src/styles/openpress/responsive.css +0 -245
  162. package/template/core/src/styles/openpress/workbench-panels.css +0 -594
  163. package/template/core/src/styles/openpress/workbench.css +0 -1255
  164. package/template/core/src/styles/openpress.css +0 -14
  165. package/template/core/src/vite-env.d.ts +0 -9
  166. package/template/core/tsconfig.json +0 -40
  167. package/template/core/vite.config.ts +0 -584
  168. package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
  169. package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
  170. package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
  171. package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
  172. package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
  173. package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
  174. package/template/packs/academic-paper/document/components/Page.tsx +0 -60
  175. package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
  176. package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
  177. package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
  178. package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
  179. package/template/packs/academic-paper/document/design.md +0 -279
  180. package/template/packs/academic-paper/document/index.tsx +0 -123
  181. package/template/packs/academic-paper/document/media/README.md +0 -13
  182. package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
  183. package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
  184. package/template/packs/academic-paper/document/theme/README.md +0 -11
  185. package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
  186. package/template/packs/academic-paper/document/theme/base/print.css +0 -93
  187. package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
  188. package/template/packs/academic-paper/document/theme/fonts.css +0 -3
  189. package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
  190. package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
  191. package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
  192. package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
  193. package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
  194. package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
  195. package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
  196. package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
  197. package/template/packs/academic-paper/document/theme/tokens.css +0 -80
  198. package/template/packs/academic-paper/openpress.config.mjs +0 -5
  199. package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
  200. package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
  201. package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
  202. package/template/packs/claude-document/document/components/Page.tsx +0 -37
  203. package/template/packs/claude-document/document/design.md +0 -142
  204. package/template/packs/claude-document/document/index.tsx +0 -94
  205. package/template/packs/claude-document/document/media/README.md +0 -13
  206. package/template/packs/claude-document/document/openpress.config.mjs +0 -26
  207. package/template/packs/claude-document/document/theme/README.md +0 -15
  208. package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
  209. package/template/packs/claude-document/document/theme/base/print.css +0 -93
  210. package/template/packs/claude-document/document/theme/base/typography.css +0 -612
  211. package/template/packs/claude-document/document/theme/fonts.css +0 -4
  212. package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
  213. package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
  214. package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
  215. package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
  216. package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
  217. package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
  218. package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
  219. package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
  220. package/template/packs/claude-document/document/theme/tokens.css +0 -89
  221. package/template/packs/claude-document/openpress.config.mjs +0 -5
  222. package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
  223. package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
  224. package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
  225. package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
  226. package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
  227. package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
  228. package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
  229. package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
  230. package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
  231. package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
  232. package/template/packs/editorial-monograph/document/design.md +0 -279
  233. package/template/packs/editorial-monograph/document/index.tsx +0 -97
  234. package/template/packs/editorial-monograph/document/media/README.md +0 -13
  235. package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
  236. package/template/packs/editorial-monograph/document/theme/README.md +0 -11
  237. package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
  238. package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
  239. package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
  240. package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
  241. package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
  242. package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
  243. package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
  244. package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
  245. package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
  246. package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
  247. package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
  248. package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
  249. package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
  250. package/template/packs/editorial-monograph/openpress.config.mjs +0 -5
@@ -1,160 +0,0 @@
1
- import type { CSSProperties } from "react";
2
- import type { ObjectSelection } from "./inspectorModel";
3
- import { clampNumber } from "../../shared";
4
- import type { InspectorInsertTargetView, InspectorLayerRect } from "../workbenchTypes";
5
-
6
- export const INSPECTOR_MARKER_RAIL_WIDTH = 36;
7
- const INSPECTOR_MARKER_MIN_HEIGHT = 32;
8
- const INSPECTOR_MARKER_VIEWPORT_PADDING = 8;
9
-
10
- export function collectInspectorBlockElements(root: HTMLElement) {
11
- return Array.from(root.querySelectorAll<HTMLElement>("[data-openpress-block-id]")).filter((element) => {
12
- if (!element.dataset.openpressBlockId) return false;
13
- if (element.parentElement?.closest("[data-openpress-block-id]")) return false;
14
- const rect = element.getBoundingClientRect();
15
- return rect.width > 0 && rect.height > 0;
16
- });
17
- }
18
-
19
- export function createInspectorInsertTargets(elements: HTMLElement[]): InspectorInsertTargetView[] {
20
- const targets: InspectorInsertTargetView[] = [];
21
- const seen = new Set<string>();
22
-
23
- for (let index = 1; index < elements.length; index += 1) {
24
- const previous = elements[index - 1];
25
- const current = elements[index];
26
- const blockId = current.dataset.openpressBlockId;
27
- if (!blockId || seen.has(blockId)) continue;
28
-
29
- const previousPage = previous.closest<HTMLElement>(".openpress-html-page");
30
- const currentPage = current.closest<HTMLElement>(".openpress-html-page");
31
- if (!previousPage || previousPage !== currentPage) continue;
32
-
33
- const previousRect = previous.getBoundingClientRect();
34
- const currentRect = current.getBoundingClientRect();
35
- const gap = currentRect.top - previousRect.bottom;
36
- if (gap < 10) continue;
37
-
38
- const pageRect = currentPage.getBoundingClientRect();
39
- const inset = Math.min(56, Math.max(20, pageRect.width * 0.07));
40
- const height = Math.min(28, Math.max(14, gap - 4));
41
- const rect = {
42
- top: previousRect.bottom + ((gap - height) / 2),
43
- left: pageRect.left + inset,
44
- width: Math.max(96, pageRect.width - (inset * 2)),
45
- height,
46
- };
47
- if (!isInspectorRectNearViewport(rect)) continue;
48
-
49
- targets.push({ blockId, rect });
50
- seen.add(blockId);
51
- }
52
-
53
- return targets;
54
- }
55
-
56
- export function resolveInspectorSelectionRect(
57
- root: HTMLElement,
58
- target: ObjectSelection | null,
59
- insertTargets: InspectorInsertTargetView[],
60
- ): InspectorLayerRect | null {
61
- if (!target) return null;
62
- if (target.placement === "before" && target.blockId) {
63
- const insertTarget = insertTargets.find((item) => item.blockId === target.blockId);
64
- if (insertTarget) return insertTarget.rect;
65
- const block = findInspectorBlockElement(root, target.blockId);
66
- if (!block) return null;
67
- const rect = block.getBoundingClientRect();
68
- return {
69
- top: rect.top - 22,
70
- left: rect.left,
71
- width: rect.width,
72
- height: 22,
73
- };
74
- }
75
-
76
- const selector = target.objectId
77
- ? `[data-openpress-object-id="${cssEscape(target.objectId)}"]`
78
- : target.blockId
79
- ? `[data-openpress-block-id="${cssEscape(target.blockId)}"]`
80
- : "";
81
- const element = selector ? root.querySelector<HTMLElement>(selector) : null;
82
- if (!element) return null;
83
- const rect = element.getBoundingClientRect();
84
- return {
85
- top: rect.top,
86
- left: rect.left,
87
- width: rect.width,
88
- height: rect.height,
89
- };
90
- }
91
-
92
- export function findInspectorBlockElement(root: HTMLElement, blockId: string) {
93
- return collectInspectorBlockElements(root).find((element) => element.dataset.openpressBlockId === blockId) ?? null;
94
- }
95
-
96
- export function syncInspectorSelectedBlock(root: HTMLElement, target: ObjectSelection | null) {
97
- root.querySelectorAll<HTMLElement>('[data-openpress-inspector-selected="true"]').forEach((element) => {
98
- delete element.dataset.openpressInspectorSelected;
99
- });
100
- if (!target || target.placement !== "block") return;
101
- const selected = target.objectId
102
- ? root.querySelector<HTMLElement>(`[data-openpress-object-id="${cssEscape(target.objectId)}"]`)
103
- : target.blockId
104
- ? findInspectorBlockElement(root, target.blockId)
105
- : null;
106
- if (selected) selected.dataset.openpressInspectorSelected = "true";
107
- }
108
-
109
- export function rectToFixedStyle(rect: InspectorLayerRect): CSSProperties {
110
- return {
111
- top: `${rect.top}px`,
112
- left: `${rect.left}px`,
113
- width: `${rect.width}px`,
114
- height: `${rect.height}px`,
115
- };
116
- }
117
-
118
- export function createInspectorComposerStyle(rect: InspectorLayerRect, expanded: boolean): CSSProperties {
119
- if (typeof window === "undefined") return {};
120
- const targetWidth = expanded ? 460 : 292;
121
- const width = Math.min(targetWidth, Math.max(240, window.innerWidth - 32));
122
- const preferredLeft = rect.left + (rect.width / 2) - (width / 2);
123
- const left = clampNumber(preferredLeft, 16, Math.max(16, window.innerWidth - width - 16));
124
- const topAbove = rect.top - 66;
125
- const top = topAbove > 12 ? topAbove : rect.top + rect.height + 14;
126
- return {
127
- top: `${top}px`,
128
- left: `${left}px`,
129
- width: `${width}px`,
130
- };
131
- }
132
-
133
- export function createInspectorMarkerStyle(rect: InspectorLayerRect): CSSProperties {
134
- if (typeof window === "undefined") return {};
135
- const height = Math.max(INSPECTOR_MARKER_MIN_HEIGHT, rect.height);
136
- const maxTop = Math.max(INSPECTOR_MARKER_VIEWPORT_PADDING, window.innerHeight - height - INSPECTOR_MARKER_VIEWPORT_PADDING);
137
- const maxLeft = Math.max(
138
- INSPECTOR_MARKER_VIEWPORT_PADDING,
139
- window.innerWidth - INSPECTOR_MARKER_RAIL_WIDTH - INSPECTOR_MARKER_VIEWPORT_PADDING,
140
- );
141
-
142
- return {
143
- top: `${clampNumber(rect.top, INSPECTOR_MARKER_VIEWPORT_PADDING, maxTop)}px`,
144
- left: `${clampNumber(rect.left - INSPECTOR_MARKER_RAIL_WIDTH, INSPECTOR_MARKER_VIEWPORT_PADDING, maxLeft)}px`,
145
- width: `${INSPECTOR_MARKER_RAIL_WIDTH}px`,
146
- height: `${height}px`,
147
- };
148
- }
149
-
150
- function isInspectorRectNearViewport(rect: InspectorLayerRect, margin = 240) {
151
- if (typeof window === "undefined") return true;
152
- return rect.top + rect.height >= -margin
153
- && rect.top <= window.innerHeight + margin
154
- && rect.left + rect.width >= -margin
155
- && rect.left <= window.innerWidth + margin;
156
- }
157
-
158
- function cssEscape(value: string) {
159
- return globalThis.CSS?.escape ? globalThis.CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
160
- }
@@ -1,408 +0,0 @@
1
- import { useCallback, useEffect, useMemo, useState, type MouseEvent as ReactMouseEvent } from "react";
2
- import { getObjectEntityMap, getSourceBlockMap } from "../../document-model";
3
- import type {
4
- EditableSourceRef,
5
- ObjectEntity,
6
- ObjectEntityRef,
7
- ReaderDocument,
8
- SourceBlock,
9
- } from "../../document-model";
10
-
11
- const DEFAULT_INSPECTOR_STORAGE_KEY = "openpress:inspector-mode";
12
-
13
- export type InspectorPlacement = "block" | "before";
14
-
15
- export interface ObjectSelection {
16
- objectId?: string;
17
- entityRef?: ObjectEntityRef;
18
- blockId?: string;
19
- placement: InspectorPlacement;
20
- objectEntity?: ObjectEntity;
21
- }
22
-
23
- export type InspectorTarget = ObjectSelection;
24
-
25
- export interface CommentDraft {
26
- entityRef: ObjectEntityRef;
27
- label?: string;
28
- blockId?: string;
29
- targetObjectId?: string;
30
- placement: InspectorPlacement;
31
- source: EditableSourceRef;
32
- note: string;
33
- }
34
-
35
- export interface InspectorState {
36
- enabled: boolean;
37
- inspectorMode: boolean;
38
- selectedBlockId: string | null;
39
- selectedBlock: SourceBlock | null;
40
- selectedObjectEntity: ObjectEntity | null;
41
- selectedSelection: ObjectSelection | null;
42
- selectedTarget: ObjectSelection | null;
43
- setInspectorMode: (enabled: boolean) => void;
44
- toggleInspectorMode: () => void;
45
- selectSelection: (target: ObjectSelection | null) => SourceBlock | null;
46
- inspectSelection: (target: EventTarget | null) => SourceBlock | null;
47
- selectTarget: (target: ObjectSelection | null) => SourceBlock | null;
48
- inspectTarget: (target: EventTarget | null) => SourceBlock | null;
49
- handleClick: (event: ReactMouseEvent) => boolean;
50
- }
51
-
52
- export interface InspectorCommentResult {
53
- ok: boolean;
54
- comment?: {
55
- id?: string;
56
- timestamp?: string;
57
- path?: string;
58
- line?: number;
59
- note?: string;
60
- hint?: string;
61
- };
62
- message?: string;
63
- }
64
-
65
- export interface PendingComment {
66
- id: string;
67
- timestamp?: string;
68
- path: string;
69
- absolutePath?: string;
70
- line: number;
71
- marker?: string;
72
- note: string;
73
- hint?: string;
74
- }
75
-
76
- export interface CommentListResult {
77
- ok: boolean;
78
- comments?: PendingComment[];
79
- message?: string;
80
- }
81
-
82
- export interface CommentClearResult {
83
- ok: boolean;
84
- removedCount: number;
85
- comments?: PendingComment[];
86
- message?: string;
87
- }
88
-
89
- async function requestInspectorJson<T extends { message?: string }>({
90
- endpoint,
91
- fetchImpl,
92
- method,
93
- body,
94
- errorPrefix,
95
- }: {
96
- endpoint: string;
97
- fetchImpl?: typeof fetch;
98
- method: "GET" | "POST" | "PATCH" | "DELETE";
99
- body?: unknown;
100
- errorPrefix: string;
101
- }): Promise<T | null> {
102
- if (typeof fetchImpl !== "function") throw new Error("OpenPress inspector comment endpoint is unavailable.");
103
- const response = await fetchImpl(endpoint, {
104
- method,
105
- ...(body === undefined
106
- ? {}
107
- : {
108
- headers: { "Content-Type": "application/json" },
109
- body: JSON.stringify(body),
110
- }),
111
- });
112
- const result = await response.json().catch(() => null) as T | null;
113
- if (!response.ok) {
114
- throw new Error(result?.message ?? `${errorPrefix} with status ${response.status}`);
115
- }
116
- return result;
117
- }
118
-
119
- export async function submitInspectorComment({
120
- draft,
121
- endpoint = "/__openpress/comment",
122
- fetchImpl = globalThis.fetch?.bind(globalThis),
123
- }: {
124
- draft: CommentDraft;
125
- endpoint?: string;
126
- fetchImpl?: typeof fetch;
127
- }): Promise<InspectorCommentResult> {
128
- const result = await requestInspectorJson<InspectorCommentResult>({
129
- endpoint,
130
- fetchImpl,
131
- method: "POST",
132
- errorPrefix: "OpenPress inspector comment failed",
133
- body: {
134
- target: {
135
- objectId: draft.entityRef.id,
136
- targetObjectId: draft.targetObjectId,
137
- kind: draft.entityRef.kind,
138
- label: draft.label,
139
- blockId: draft.blockId,
140
- path: draft.source.path,
141
- source: draft.source.source,
142
- },
143
- note: draft.note,
144
- hint: formatInspectorHint({ placement: draft.placement, targetObjectId: draft.targetObjectId }),
145
- },
146
- });
147
- return result ?? { ok: true };
148
- }
149
-
150
- export function createInspectorCommentDraft({
151
- block,
152
- entity,
153
- note,
154
- placement,
155
- target,
156
- }: {
157
- block: SourceBlock | null;
158
- entity: ObjectEntity | null;
159
- note: string;
160
- placement: InspectorPlacement;
161
- target?: ObjectSelection | null;
162
- }): CommentDraft {
163
- const normalizedNote = note.trim();
164
- if (!block) throw new Error("OpenPress inspector comment requires a selected object.");
165
- if (!normalizedNote) throw new Error("OpenPress inspector comment note must not be empty.");
166
- if (!block.path || !block.source?.line) throw new Error("OpenPress inspector selected object has no editable source location.");
167
-
168
- return {
169
- entityRef: entity ? { id: entity.id, kind: entity.kind } : { id: block.id, kind: "mdx-block" },
170
- label: entity?.label ?? block.name ?? block.id,
171
- blockId: block.id,
172
- targetObjectId: target?.objectId && target.objectId !== entity?.id ? target.objectId : undefined,
173
- placement,
174
- source: {
175
- path: block.path,
176
- source: block.source,
177
- line: block.source.line,
178
- column: block.source.column,
179
- },
180
- note: normalizedNote,
181
- };
182
- }
183
-
184
- export async function fetchInspectorComments({
185
- endpoint = "/__openpress/comment",
186
- fetchImpl = globalThis.fetch?.bind(globalThis),
187
- }: {
188
- endpoint?: string;
189
- fetchImpl?: typeof fetch;
190
- } = {}): Promise<PendingComment[]> {
191
- const result = await requestInspectorJson<CommentListResult>({
192
- endpoint,
193
- fetchImpl,
194
- method: "GET",
195
- errorPrefix: "OpenPress inspector comment list failed",
196
- });
197
- return Array.isArray(result?.comments) ? result.comments : [];
198
- }
199
-
200
- export async function clearInspectorComment({
201
- id,
202
- all = false,
203
- endpoint = "/__openpress/comment",
204
- fetchImpl = globalThis.fetch?.bind(globalThis),
205
- }: {
206
- id?: string;
207
- all?: boolean;
208
- endpoint?: string;
209
- fetchImpl?: typeof fetch;
210
- } = {}): Promise<CommentClearResult> {
211
- if (!all && !id) throw new Error("OpenPress inspector comment clear requires an id or all=true.");
212
-
213
- const result = await requestInspectorJson<CommentClearResult>({
214
- endpoint,
215
- fetchImpl,
216
- method: "DELETE",
217
- errorPrefix: "OpenPress inspector comment clear failed",
218
- body: all ? { all: true } : { id },
219
- });
220
- return result ?? { ok: true, removedCount: 0 };
221
- }
222
-
223
- export async function updateInspectorComment({
224
- id,
225
- note,
226
- placement,
227
- endpoint = "/__openpress/comment",
228
- fetchImpl = globalThis.fetch?.bind(globalThis),
229
- }: {
230
- id: string;
231
- note: string;
232
- placement?: InspectorPlacement;
233
- endpoint?: string;
234
- fetchImpl?: typeof fetch;
235
- }): Promise<InspectorCommentResult> {
236
- const normalizedNote = note.trim();
237
- if (!id.trim()) throw new Error("OpenPress inspector comment update requires an id.");
238
- if (!normalizedNote) throw new Error("OpenPress inspector comment note must not be empty.");
239
-
240
- const result = await requestInspectorJson<InspectorCommentResult>({
241
- endpoint,
242
- fetchImpl,
243
- method: "PATCH",
244
- errorPrefix: "OpenPress inspector comment update failed",
245
- body: {
246
- id,
247
- note: normalizedNote,
248
- hint: formatInspectorHint({ placement }),
249
- },
250
- });
251
- return result ?? { ok: true };
252
- }
253
-
254
- export function useInspector(
255
- document: ReaderDocument,
256
- {
257
- enabled = false,
258
- storageKey = DEFAULT_INSPECTOR_STORAGE_KEY,
259
- }: {
260
- enabled?: boolean;
261
- storageKey?: string;
262
- } = {},
263
- ): InspectorState {
264
- const blockMap = useMemo(() => getSourceBlockMap(document), [document]);
265
- const objectEntityMap = useMemo(() => getObjectEntityMap(document), [document]);
266
- const [inspectorMode, setInspectorModeState] = useState(() => {
267
- if (!enabled || typeof window === "undefined") return false;
268
- return window.localStorage.getItem(storageKey) === "on";
269
- });
270
- const [selectedSelection, setSelectedSelection] = useState<ObjectSelection | null>(null);
271
-
272
- useEffect(() => {
273
- if (!enabled && inspectorMode) setInspectorModeState(false);
274
- }, [enabled, inspectorMode]);
275
-
276
- const setInspectorMode = useCallback((nextEnabled: boolean) => {
277
- setInspectorModeState(nextEnabled);
278
- if (typeof window !== "undefined") {
279
- window.localStorage.setItem(storageKey, nextEnabled ? "on" : "off");
280
- }
281
- if (!nextEnabled) setSelectedSelection(null);
282
- }, [storageKey]);
283
-
284
- const resolveSourceBlock = useCallback((target: ObjectSelection | null): SourceBlock | null => {
285
- if (!target) return null;
286
- if (target.blockId && blockMap[target.blockId]) return blockMap[target.blockId] ?? null;
287
- const entity = target.objectEntity;
288
- const source = entity?.source;
289
- if (!entity || !source?.path) return null;
290
- return {
291
- id: entity.blockId ?? entity.id,
292
- kind: entity.kind,
293
- name: entity.label,
294
- path: source.path,
295
- frameKey: entity.frameKey,
296
- chainId: entity.chainId,
297
- source: source.source ?? (source.line ? { line: source.line, column: source.column ?? 1 } : undefined),
298
- };
299
- }, [blockMap]);
300
-
301
- const selectSelection = useCallback((target: ObjectSelection | null) => {
302
- const resolvedTarget = target?.objectId && !target.objectEntity
303
- ? { ...target, objectEntity: objectEntityMap[target.objectId] }
304
- : target;
305
- const withRef = resolvedTarget?.objectEntity && !resolvedTarget.entityRef
306
- ? {
307
- ...resolvedTarget,
308
- entityRef: {
309
- id: resolvedTarget.objectEntity.id,
310
- kind: resolvedTarget.objectEntity.kind,
311
- },
312
- }
313
- : resolvedTarget;
314
-
315
- setSelectedSelection(withRef ?? null);
316
- return resolveSourceBlock(withRef ?? null);
317
- }, [objectEntityMap, resolveSourceBlock]);
318
-
319
- const inspectSelection = useCallback((target: EventTarget | null) => {
320
- const objectSelection = findObjectSelection(target, objectEntityMap);
321
- return selectSelection(objectSelection);
322
- }, [objectEntityMap, selectSelection]);
323
-
324
- const handleClick = useCallback((event: ReactMouseEvent) => {
325
- if (!enabled || !inspectorMode) return false;
326
- const objectSelection = findObjectSelection(event.target, objectEntityMap);
327
- if (!objectSelection) return false;
328
- selectSelection(objectSelection);
329
- event.preventDefault();
330
- event.stopPropagation();
331
- return true;
332
- }, [enabled, inspectorMode, objectEntityMap, selectSelection]);
333
-
334
- const selectedObjectEntity = selectedSelection?.objectEntity ?? null;
335
- const selectedBlock = resolveSourceBlock(selectedSelection);
336
- const selectedBlockId = selectedBlock?.id ?? selectedSelection?.blockId ?? null;
337
-
338
- return {
339
- enabled,
340
- inspectorMode: enabled && inspectorMode,
341
- selectedBlockId,
342
- selectedBlock,
343
- selectedObjectEntity,
344
- selectedSelection,
345
- selectedTarget: selectedSelection,
346
- setInspectorMode,
347
- toggleInspectorMode: () => setInspectorMode(!inspectorMode),
348
- selectSelection,
349
- inspectSelection,
350
- selectTarget: selectSelection,
351
- inspectTarget: inspectSelection,
352
- handleClick,
353
- };
354
- }
355
-
356
- export function findObjectSelection(
357
- target: EventTarget | null,
358
- objectEntities: Record<string, ObjectEntity> = {},
359
- ): ObjectSelection | null {
360
- if (typeof Element === "undefined") return null;
361
- if (!(target instanceof Element)) return null;
362
- const insertTarget = target.closest<HTMLElement>("[data-openpress-insert-before-block-id]");
363
- const insertBeforeBlockId = insertTarget?.dataset.openpressInsertBeforeBlockId;
364
- if (insertBeforeBlockId) {
365
- const objectId = insertTarget?.dataset.openpressObjectId;
366
- const objectEntity = objectId ? objectEntities[objectId] : undefined;
367
- const selection: ObjectSelection = { blockId: insertBeforeBlockId, placement: "before" };
368
- if (objectId) selection.objectId = objectId;
369
- if (objectEntity) {
370
- selection.objectEntity = objectEntity;
371
- selection.entityRef = { id: objectEntity.id, kind: objectEntity.kind };
372
- }
373
- return selection;
374
- }
375
-
376
- const renderedObject = target.closest<HTMLElement>("[data-openpress-object-id]");
377
- const objectId = renderedObject?.dataset.openpressObjectId;
378
- if (objectId) {
379
- const objectEntity = objectEntities[objectId];
380
- const blockId = renderedObject?.dataset.openpressBlockId || objectEntity?.blockId;
381
- const selection: ObjectSelection = { objectId, placement: "block" };
382
- if (blockId) selection.blockId = blockId;
383
- if (objectEntity) {
384
- selection.objectEntity = objectEntity;
385
- selection.entityRef = { id: objectEntity.id, kind: objectEntity.kind };
386
- }
387
- return selection;
388
- }
389
-
390
- const element = target.closest<HTMLElement>("[data-openpress-block-id]");
391
- const blockId = element?.dataset.openpressBlockId;
392
- return blockId ? { blockId, placement: "block" } : null;
393
- }
394
-
395
- export const findInspectorTarget = findObjectSelection;
396
-
397
- export function formatInspectorHint({
398
- placement,
399
- targetObjectId,
400
- }: {
401
- placement?: InspectorPlacement;
402
- targetObjectId?: string;
403
- } = {}) {
404
- const parts = ["openpress-react-inspector"];
405
- if (placement) parts.push(`placement=${placement}`);
406
- if (targetObjectId?.trim()) parts.push(`target=${encodeURIComponent(targetObjectId.trim())}`);
407
- return parts.join(" ");
408
- }