@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.
- package/README.md +33 -23
- package/dist/cli.js +320 -252
- package/package.json +9 -8
- package/template/core/AGENTS.md +0 -126
- package/template/core/CHANGELOG.md +0 -215
- package/template/core/README.md +0 -40
- package/template/core/engine/cli.mjs +0 -96
- package/template/core/engine/commands/_shared.mjs +0 -177
- package/template/core/engine/commands/deploy.mjs +0 -31
- package/template/core/engine/commands/dev.mjs +0 -49
- package/template/core/engine/commands/doctor.mjs +0 -229
- package/template/core/engine/commands/export.mjs +0 -8
- package/template/core/engine/commands/init.mjs +0 -24
- package/template/core/engine/commands/inspect.mjs +0 -35
- package/template/core/engine/commands/pdf.mjs +0 -26
- package/template/core/engine/commands/preview.mjs +0 -26
- package/template/core/engine/commands/render.mjs +0 -17
- package/template/core/engine/commands/replace.mjs +0 -41
- package/template/core/engine/commands/search.mjs +0 -33
- package/template/core/engine/commands/typecheck.mjs +0 -5
- package/template/core/engine/commands/upgrade.mjs +0 -159
- package/template/core/engine/commands/validate.mjs +0 -17
- package/template/core/engine/document-export.mjs +0 -15
- package/template/core/engine/init.mjs +0 -90
- package/template/core/engine/output/chrome-pdf.d.mts +0 -34
- package/template/core/engine/output/chrome-pdf.mjs +0 -358
- package/template/core/engine/output/deploy-sync.mjs +0 -15
- package/template/core/engine/output/fonts.mjs +0 -62
- package/template/core/engine/output/katex-assets.mjs +0 -45
- package/template/core/engine/output/page-block.mjs +0 -30
- package/template/core/engine/output/pdf-media.mjs +0 -45
- package/template/core/engine/output/public-assets.mjs +0 -19
- package/template/core/engine/output/static-server.mjs +0 -532
- package/template/core/engine/react/caption-numbering.mjs +0 -73
- package/template/core/engine/react/comment-endpoint.d.mts +0 -11
- package/template/core/engine/react/comment-endpoint.mjs +0 -102
- package/template/core/engine/react/comment-marker.mjs +0 -374
- package/template/core/engine/react/document-entry.mjs +0 -324
- package/template/core/engine/react/document-export.mjs +0 -373
- package/template/core/engine/react/http-json.mjs +0 -24
- package/template/core/engine/react/mdx-compile.mjs +0 -599
- package/template/core/engine/react/measurement-css.mjs +0 -136
- package/template/core/engine/react/object-entities.mjs +0 -119
- package/template/core/engine/react/pagination/allocator.mjs +0 -122
- package/template/core/engine/react/pagination/regions.mjs +0 -81
- package/template/core/engine/react/pagination-constants.mjs +0 -3
- package/template/core/engine/react/pagination.mjs +0 -9
- package/template/core/engine/react/pipeline/allocate.mjs +0 -251
- package/template/core/engine/react/pipeline/final-render.mjs +0 -94
- package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
- package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
- package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
- package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
- package/template/core/engine/react/section-css.mjs +0 -56
- package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
- package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
- package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
- package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
- package/template/core/engine/react/style-discovery.mjs +0 -142
- package/template/core/engine/runtime/config.d.mts +0 -40
- package/template/core/engine/runtime/config.mjs +0 -175
- package/template/core/engine/runtime/file-utils.mjs +0 -106
- package/template/core/engine/runtime/file-walk.mjs +0 -22
- package/template/core/engine/runtime/inspection.mjs +0 -328
- package/template/core/engine/runtime/issue-report.mjs +0 -44
- package/template/core/engine/runtime/path-utils.mjs +0 -20
- package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
- package/template/core/engine/runtime/source-text-tools.mjs +0 -832
- package/template/core/engine/runtime/source-workspace.mjs +0 -159
- package/template/core/engine/runtime/validation.mjs +0 -174
- package/template/core/index.html +0 -13
- package/template/core/openpress.config.mjs +0 -12
- package/template/core/package.json +0 -91
- package/template/core/src/main.tsx +0 -16
- package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
- package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
- package/template/core/src/openpress/app/index.ts +0 -2
- package/template/core/src/openpress/core/Frame.tsx +0 -78
- package/template/core/src/openpress/core/FrameContext.tsx +0 -24
- package/template/core/src/openpress/core/MdxArea.tsx +0 -34
- package/template/core/src/openpress/core/Press.tsx +0 -34
- package/template/core/src/openpress/core/cn.ts +0 -4
- package/template/core/src/openpress/core/index.tsx +0 -40
- package/template/core/src/openpress/core/primitives.tsx +0 -44
- package/template/core/src/openpress/core/types.ts +0 -191
- package/template/core/src/openpress/core/useSource.ts +0 -28
- package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
- package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
- package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
- package/template/core/src/openpress/document-model/index.ts +0 -6
- package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
- package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
- package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
- package/template/core/src/openpress/manuscript/index.tsx +0 -238
- package/template/core/src/openpress/mdx/index.ts +0 -88
- package/template/core/src/openpress/numbering/index.ts +0 -294
- package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
- package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
- package/template/core/src/openpress/reader/index.ts +0 -10
- package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
- package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
- package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
- package/template/core/src/openpress/reader/readerScroll.ts +0 -92
- package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
- package/template/core/src/openpress/reader/readerTypes.ts +0 -4
- package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
- package/template/core/src/openpress/reader/usePanelState.ts +0 -56
- package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
- package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
- package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
- package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
- package/template/core/src/openpress/shared/Panel.tsx +0 -77
- package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
- package/template/core/src/openpress/shared/index.ts +0 -4
- package/template/core/src/openpress/shared/numberUtils.ts +0 -3
- package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
- package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
- package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
- package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
- package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
- package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
- package/template/core/src/openpress/workbench/actions/index.ts +0 -5
- package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
- package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
- package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
- package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
- package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
- package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
- package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
- package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
- package/template/core/src/openpress/workbench/document/index.ts +0 -10
- package/template/core/src/openpress/workbench/index.ts +0 -2
- package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
- package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
- package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
- package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
- package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
- package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
- package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
- package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
- package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
- package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
- package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
- package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
- package/template/core/src/openpress/workbench/panels/index.ts +0 -3
- package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
- package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
- package/template/core/src/openpress/workbench/project/index.ts +0 -2
- package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
- package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
- package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
- package/template/core/src/openpress/workbench/shell/index.ts +0 -1
- package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
- package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
- package/template/core/src/styles/openpress/app-shell.css +0 -251
- package/template/core/src/styles/openpress/media-workspace.css +0 -230
- package/template/core/src/styles/openpress/print-route.css +0 -184
- package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
- package/template/core/src/styles/openpress/public-viewer.css +0 -688
- package/template/core/src/styles/openpress/reader-runtime.css +0 -980
- package/template/core/src/styles/openpress/responsive.css +0 -245
- package/template/core/src/styles/openpress/workbench-panels.css +0 -594
- package/template/core/src/styles/openpress/workbench.css +0 -1255
- package/template/core/src/styles/openpress.css +0 -14
- package/template/core/src/vite-env.d.ts +0 -9
- package/template/core/tsconfig.json +0 -40
- package/template/core/vite.config.ts +0 -584
- package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
- package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
- package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
- package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
- package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
- package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/academic-paper/document/components/Page.tsx +0 -60
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/academic-paper/document/design.md +0 -279
- package/template/packs/academic-paper/document/index.tsx +0 -123
- package/template/packs/academic-paper/document/media/README.md +0 -13
- package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
- package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
- package/template/packs/academic-paper/document/theme/README.md +0 -11
- package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
- package/template/packs/academic-paper/document/theme/base/print.css +0 -93
- package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
- package/template/packs/academic-paper/document/theme/fonts.css +0 -3
- package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
- package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/academic-paper/document/theme/tokens.css +0 -80
- package/template/packs/academic-paper/openpress.config.mjs +0 -5
- package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
- package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
- package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
- package/template/packs/claude-document/document/components/Page.tsx +0 -37
- package/template/packs/claude-document/document/design.md +0 -142
- package/template/packs/claude-document/document/index.tsx +0 -94
- package/template/packs/claude-document/document/media/README.md +0 -13
- package/template/packs/claude-document/document/openpress.config.mjs +0 -26
- package/template/packs/claude-document/document/theme/README.md +0 -15
- package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
- package/template/packs/claude-document/document/theme/base/print.css +0 -93
- package/template/packs/claude-document/document/theme/base/typography.css +0 -612
- package/template/packs/claude-document/document/theme/fonts.css +0 -4
- package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
- package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
- package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
- package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
- package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
- package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
- package/template/packs/claude-document/document/theme/tokens.css +0 -89
- package/template/packs/claude-document/openpress.config.mjs +0 -5
- package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
- package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
- package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
- package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
- package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/editorial-monograph/document/design.md +0 -279
- package/template/packs/editorial-monograph/document/index.tsx +0 -97
- package/template/packs/editorial-monograph/document/media/README.md +0 -13
- package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
- package/template/packs/editorial-monograph/document/theme/README.md +0 -11
- package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
- package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
- package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
- package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
- package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
- package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
- 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
|
-
}
|