@alpaca-editor/core 1.0.3942 → 1.0.3943
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/.prettierrc +3 -0
- package/build.css +3 -0
- package/components.json +21 -0
- package/dist/editor/ContentTree.d.ts +2 -1
- package/dist/editor/ContentTree.js +23 -21
- package/dist/editor/ContentTree.js.map +1 -1
- package/dist/editor/FieldActionsOverlay.js +0 -2
- package/dist/editor/FieldActionsOverlay.js.map +1 -1
- package/dist/editor/ScrollingContentTree.js +1 -1
- package/dist/editor/ScrollingContentTree.js.map +1 -1
- package/dist/editor/Titlebar.js +1 -1
- package/dist/editor/Titlebar.js.map +1 -1
- package/dist/editor/ai/GhostWriter.js +24 -3
- package/dist/editor/ai/GhostWriter.js.map +1 -1
- package/dist/editor/client/EditorClient.js +7 -7
- package/dist/editor/client/EditorClient.js.map +1 -1
- package/dist/editor/field-types/InternalLinkFieldEditor.js +60 -10
- package/dist/editor/field-types/InternalLinkFieldEditor.js.map +1 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js +48 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -1
- package/dist/editor/menubar/PageSelector.js +116 -65
- package/dist/editor/menubar/PageSelector.js.map +1 -1
- package/dist/editor/page-viewer/EditorForm.js +5 -2
- package/dist/editor/page-viewer/EditorForm.js.map +1 -1
- package/dist/editor/ui/ItemSearch.js +14 -8
- package/dist/editor/ui/ItemSearch.js.map +1 -1
- package/dist/editor/ui/PerfectTree.d.ts +4 -2
- package/dist/editor/ui/PerfectTree.js +78 -4
- package/dist/editor/ui/PerfectTree.js.map +1 -1
- package/dist/editor/ui/Splitter.js +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +8 -2
- package/eslint.config.mjs +4 -0
- package/images/bg-shape-black.webp +0 -0
- package/images/wizard-bg.png +0 -0
- package/images/wizard-tour.png +0 -0
- package/images/wizard.png +0 -0
- package/package.json +2 -8
- package/src/client-components/api.ts +6 -0
- package/src/client-components/index.ts +19 -0
- package/src/components/ActionButton.tsx +50 -0
- package/src/components/Error.tsx +57 -0
- package/src/components/ui/CardConnector.tsx +56 -0
- package/src/components/ui/button.tsx +62 -0
- package/src/components/ui/card.tsx +372 -0
- package/src/components/ui/context-menu.tsx +250 -0
- package/src/config/config.tsx +917 -0
- package/src/config/types.ts +286 -0
- package/src/editor/ComponentInfo.tsx +90 -0
- package/src/editor/ConfirmationDialog.tsx +103 -0
- package/src/editor/ContentTree.tsx +733 -0
- package/src/editor/ContextMenu.tsx +230 -0
- package/src/editor/Editor.tsx +90 -0
- package/src/editor/EditorWarning.tsx +34 -0
- package/src/editor/EditorWarnings.tsx +33 -0
- package/src/editor/FieldActionsOverlay.tsx +296 -0
- package/src/editor/FieldEditorPopup.tsx +65 -0
- package/src/editor/FieldHistory.tsx +75 -0
- package/src/editor/FieldList.tsx +190 -0
- package/src/editor/FieldListField.tsx +391 -0
- package/src/editor/FieldListFieldWithFallbacks.tsx +217 -0
- package/src/editor/FloatingToolbar.tsx +163 -0
- package/src/editor/ImageEditor.tsx +128 -0
- package/src/editor/ItemInfo.tsx +90 -0
- package/src/editor/LinkEditorDialog.tsx +196 -0
- package/src/editor/MainLayout.tsx +95 -0
- package/src/editor/MobileLayout.tsx +68 -0
- package/src/editor/NewEditorClient.tsx +11 -0
- package/src/editor/PictureCropper.tsx +568 -0
- package/src/editor/PictureEditor.tsx +301 -0
- package/src/editor/PictureEditorDialog.tsx +381 -0
- package/src/editor/PublishDialog.ignore +74 -0
- package/src/editor/ScrollingContentTree.tsx +68 -0
- package/src/editor/Terminal.tsx +227 -0
- package/src/editor/Titlebar.tsx +104 -0
- package/src/editor/ai/AiPopup.tsx +59 -0
- package/src/editor/ai/AiResponseMessage.tsx +106 -0
- package/src/editor/ai/AiTerminal.tsx +503 -0
- package/src/editor/ai/AiToolCall.tsx +61 -0
- package/src/editor/ai/EditorAiTerminal.tsx +20 -0
- package/src/editor/ai/GhostWriter.tsx +480 -0
- package/src/editor/ai/aiPageModel.ts +108 -0
- package/src/editor/ai/editorAiContext.ts +18 -0
- package/src/editor/client/AboutDialog.tsx +44 -0
- package/src/editor/client/EditorClient.tsx +2241 -0
- package/src/editor/client/GenericDialog.tsx +50 -0
- package/src/editor/client/editContext.ts +416 -0
- package/src/editor/client/helpers.ts +44 -0
- package/src/editor/client/itemsRepository.ts +574 -0
- package/src/editor/client/operations.ts +768 -0
- package/src/editor/client/pageModelBuilder.ts +219 -0
- package/src/editor/commands/commands.ts +22 -0
- package/src/editor/commands/componentCommands.tsx +431 -0
- package/src/editor/commands/createVersionCommand.ts +33 -0
- package/src/editor/commands/deleteVersionCommand.ts +71 -0
- package/src/editor/commands/itemCommands.tsx +351 -0
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
- package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +27 -0
- package/src/editor/commands/undo.ts +39 -0
- package/src/editor/component-designer/ComponentDesigner.tsx +70 -0
- package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +11 -0
- package/src/editor/component-designer/ComponentDesignerMenu.tsx +91 -0
- package/src/editor/component-designer/ComponentEditor.tsx +97 -0
- package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +31 -0
- package/src/editor/component-designer/ComponentRenderingEditor.tsx +104 -0
- package/src/editor/component-designer/ComponentsDropdown.tsx +39 -0
- package/src/editor/component-designer/PlaceholdersEditor.tsx +179 -0
- package/src/editor/component-designer/RenderingsDropdown.tsx +36 -0
- package/src/editor/component-designer/TemplateEditor.tsx +236 -0
- package/src/editor/component-designer/aiContext.ts +23 -0
- package/src/editor/componentTreeHelper.tsx +116 -0
- package/src/editor/context-menu/CopyMoveMenu.tsx +103 -0
- package/src/editor/context-menu/InsertMenu.tsx +347 -0
- package/src/editor/control-center/About.tsx +342 -0
- package/src/editor/control-center/ControlCenterMenu.tsx +76 -0
- package/src/editor/control-center/IndexOverview.tsx +50 -0
- package/src/editor/control-center/IndexSettings.tsx +266 -0
- package/src/editor/control-center/Info.tsx +104 -0
- package/src/editor/control-center/QuotaInfo.tsx +301 -0
- package/src/editor/control-center/Status.tsx +113 -0
- package/src/editor/control-center/WebSocketMessages.tsx +155 -0
- package/src/editor/editor-warnings/ItemLocked.tsx +63 -0
- package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +22 -0
- package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +23 -0
- package/src/editor/editor-warnings/NoWriteAccess.tsx +16 -0
- package/src/editor/editor-warnings/ValidationErrors.tsx +54 -0
- package/src/editor/field-types/AttachmentEditor.tsx +9 -0
- package/src/editor/field-types/CheckboxEditor.tsx +47 -0
- package/src/editor/field-types/DropLinkEditor.tsx +80 -0
- package/src/editor/field-types/DropListEditor.tsx +84 -0
- package/src/editor/field-types/ImageFieldEditor.tsx +65 -0
- package/src/editor/field-types/InternalLinkFieldEditor.tsx +188 -0
- package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
- package/src/editor/field-types/MultiLineText.tsx +82 -0
- package/src/editor/field-types/PictureFieldEditor.tsx +121 -0
- package/src/editor/field-types/RawEditor.tsx +53 -0
- package/src/editor/field-types/ReactQuill.tsx +580 -0
- package/src/editor/field-types/RichTextEditor.tsx +22 -0
- package/src/editor/field-types/RichTextEditorComponent.tsx +127 -0
- package/src/editor/field-types/SingleLineText.tsx +174 -0
- package/src/editor/field-types/TreeListEditor.tsx +261 -0
- package/src/editor/fieldTypes.ts +140 -0
- package/src/editor/media-selector/AiImageSearch.tsx +185 -0
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +94 -0
- package/src/editor/media-selector/MediaFolderBrowser.tsx +321 -0
- package/src/editor/media-selector/MediaSelector.tsx +42 -0
- package/src/editor/media-selector/Preview.tsx +14 -0
- package/src/editor/media-selector/Thumbnails.tsx +48 -0
- package/src/editor/media-selector/TreeSelector.tsx +292 -0
- package/src/editor/media-selector/UploadZone.tsx +137 -0
- package/src/editor/media-selector/index.ts +8 -0
- package/src/editor/menubar/ActionsMenu.tsx +94 -0
- package/src/editor/menubar/ActiveUsers.tsx +17 -0
- package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
- package/src/editor/menubar/BrowseHistory.tsx +28 -0
- package/src/editor/menubar/ItemLanguageVersion.tsx +76 -0
- package/src/editor/menubar/LanguageSelector.tsx +226 -0
- package/src/editor/menubar/Menu.tsx +83 -0
- package/src/editor/menubar/NavButtons.tsx +74 -0
- package/src/editor/menubar/PageSelector.tsx +278 -0
- package/src/editor/menubar/PageViewerControls.tsx +120 -0
- package/src/editor/menubar/PreviewSecondaryControls.tsx +18 -0
- package/src/editor/menubar/SecondaryControls.tsx +45 -0
- package/src/editor/menubar/Separator.tsx +12 -0
- package/src/editor/menubar/SiteInfo.tsx +53 -0
- package/src/editor/menubar/User.tsx +27 -0
- package/src/editor/menubar/VersionSelector.tsx +142 -0
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +307 -0
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +59 -0
- package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +23 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +64 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +35 -0
- package/src/editor/page-editor-chrome/FrameMenu.tsx +338 -0
- package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
- package/src/editor/page-editor-chrome/InlineEditor.tsx +765 -0
- package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +61 -0
- package/src/editor/page-editor-chrome/NoLayout.tsx +36 -0
- package/src/editor/page-editor-chrome/PageEditorChrome.tsx +122 -0
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +161 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +169 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +315 -0
- package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +300 -0
- package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +40 -0
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +828 -0
- package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
- package/src/editor/page-viewer/EditorForm.tsx +262 -0
- package/src/editor/page-viewer/MiniMap.tsx +362 -0
- package/src/editor/page-viewer/PageViewer.tsx +169 -0
- package/src/editor/page-viewer/PageViewerFrame.tsx +1022 -0
- package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +412 -0
- package/src/editor/page-viewer/pageViewContext.ts +186 -0
- package/src/editor/pageModel.ts +220 -0
- package/src/editor/picture-shared.tsx +53 -0
- package/src/editor/reviews/Comment.tsx +308 -0
- package/src/editor/reviews/Comments.tsx +125 -0
- package/src/editor/reviews/DiffView.tsx +109 -0
- package/src/editor/reviews/PreviewInfo.tsx +35 -0
- package/src/editor/reviews/Reviews.tsx +280 -0
- package/src/editor/reviews/SuggestedEdit.tsx +316 -0
- package/src/editor/reviews/reviewCommands.tsx +47 -0
- package/src/editor/reviews/useReviews.tsx +70 -0
- package/src/editor/services/aiService.ts +173 -0
- package/src/editor/services/componentDesignerService.ts +151 -0
- package/src/editor/services/contentService.ts +180 -0
- package/src/editor/services/editService.ts +488 -0
- package/src/editor/services/indexService.ts +24 -0
- package/src/editor/services/reviewsService.ts +53 -0
- package/src/editor/services/serviceHelper.ts +95 -0
- package/src/editor/services/suggestedEditsService.ts +39 -0
- package/src/editor/services/systemService.ts +5 -0
- package/src/editor/services/translationService.ts +21 -0
- package/src/editor/services-server/api.ts +150 -0
- package/src/editor/services-server/graphQL.ts +106 -0
- package/src/editor/sidebar/ComponentPalette.tsx +161 -0
- package/src/editor/sidebar/ComponentTree.tsx +549 -0
- package/src/editor/sidebar/Debug.tsx +111 -0
- package/src/editor/sidebar/DictionaryEditor.tsx +261 -0
- package/src/editor/sidebar/EditHistory.tsx +134 -0
- package/src/editor/sidebar/GraphQL.tsx +164 -0
- package/src/editor/sidebar/Insert.tsx +35 -0
- package/src/editor/sidebar/MainContentTree.tsx +102 -0
- package/src/editor/sidebar/Performance.tsx +53 -0
- package/src/editor/sidebar/Sessions.tsx +35 -0
- package/src/editor/sidebar/Sidebar.tsx +20 -0
- package/src/editor/sidebar/SidebarView.tsx +152 -0
- package/src/editor/sidebar/Translations.tsx +295 -0
- package/src/editor/sidebar/Validation.tsx +102 -0
- package/src/editor/sidebar/ViewSelector.tsx +60 -0
- package/src/editor/sidebar/Workbox.tsx +209 -0
- package/src/editor/ui/CenteredMessage.tsx +7 -0
- package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +81 -0
- package/src/editor/ui/CopyToClipboardButton.tsx +24 -0
- package/src/editor/ui/DialogButtons.tsx +11 -0
- package/src/editor/ui/Icons.tsx +709 -0
- package/src/editor/ui/ItemList.tsx +76 -0
- package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
- package/src/editor/ui/ItemSearch.tsx +159 -0
- package/src/editor/ui/PerfectTree.tsx +676 -0
- package/src/editor/ui/Section.tsx +35 -0
- package/src/editor/ui/SimpleIconButton.tsx +54 -0
- package/src/editor/ui/SimpleMenu.tsx +40 -0
- package/src/editor/ui/SimpleTable.tsx +60 -0
- package/src/editor/ui/SimpleTabs.tsx +60 -0
- package/src/editor/ui/SimpleToolbar.tsx +7 -0
- package/src/editor/ui/Spinner.tsx +9 -0
- package/src/editor/ui/Splitter.tsx +420 -0
- package/src/editor/ui/StackedPanels.tsx +134 -0
- package/src/editor/ui/Toolbar.tsx +7 -0
- package/src/editor/utils/id-helper.ts +3 -0
- package/src/editor/utils/insertOptions.ts +69 -0
- package/src/editor/utils/itemutils.ts +29 -0
- package/src/editor/utils/useMemoDebug.ts +28 -0
- package/src/editor/utils.ts +486 -0
- package/src/editor/views/CompareView.tsx +245 -0
- package/src/editor/views/EditView.tsx +27 -0
- package/src/editor/views/ItemEditor.tsx +58 -0
- package/src/editor/views/MediaFolderEditView.tsx +66 -0
- package/src/editor/views/SingleEditView.tsx +57 -0
- package/src/fonts/Geist-Black.woff2 +0 -0
- package/src/fonts/Geist-Bold.woff2 +0 -0
- package/src/fonts/Geist-ExtraBold.woff2 +0 -0
- package/src/fonts/Geist-ExtraLight.woff2 +0 -0
- package/src/fonts/Geist-Light.woff2 +0 -0
- package/src/fonts/Geist-Medium.woff2 +0 -0
- package/src/fonts/Geist-Regular.woff2 +0 -0
- package/src/fonts/Geist-SemiBold.woff2 +0 -0
- package/src/fonts/Geist-Thin.woff2 +0 -0
- package/src/fonts/Geist[wght].woff2 +0 -0
- package/src/fonts/index.ts +10 -0
- package/src/index.ts +23 -0
- package/src/lib/safelist.tsx +16 -0
- package/src/lib/utils.ts +6 -0
- package/src/page-wizard/PageWizard.tsx +139 -0
- package/src/page-wizard/WizardBox.tsx +4 -0
- package/src/page-wizard/WizardBoxConnector.tsx +56 -0
- package/src/page-wizard/WizardSteps.tsx +458 -0
- package/src/page-wizard/service.ts +35 -0
- package/src/page-wizard/startPageWizardCommand.ts +26 -0
- package/src/page-wizard/steps/BuildPageStep.tsx +259 -0
- package/src/page-wizard/steps/CollectStep.tsx +296 -0
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +454 -0
- package/src/page-wizard/steps/Components.tsx +193 -0
- package/src/page-wizard/steps/ContentStep.tsx +890 -0
- package/src/page-wizard/steps/EditButton.tsx +34 -0
- package/src/page-wizard/steps/FieldEditor.tsx +102 -0
- package/src/page-wizard/steps/Generate.tsx +60 -0
- package/src/page-wizard/steps/ImagesStep.tsx +382 -0
- package/src/page-wizard/steps/LayoutStep.tsx +227 -0
- package/src/page-wizard/steps/MetaDataStep.tsx +173 -0
- package/src/page-wizard/steps/SelectStep.tsx +281 -0
- package/src/page-wizard/steps/schema.ts +180 -0
- package/src/page-wizard/steps/usePageCreator.ts +325 -0
- package/src/page-wizard/usePageWizard.ts +79 -0
- package/src/revision.ts +2 -0
- package/src/splash-screen/NewPage.tsx +294 -0
- package/src/splash-screen/OpenPage.tsx +113 -0
- package/src/splash-screen/RecentPages.tsx +123 -0
- package/src/splash-screen/SectionHeadline.tsx +21 -0
- package/src/splash-screen/SplashScreen.tsx +195 -0
- package/src/tour/Tour.tsx +566 -0
- package/src/tour/default-tour.tsx +301 -0
- package/src/tour/preview-tour.tsx +128 -0
- package/src/types.ts +335 -0
- package/styles.css +765 -0
- package/tsconfig.build.json +31 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Dropdown } from "primereact/dropdown";
|
|
2
|
+
import { InputNumber } from "primereact/inputnumber";
|
|
3
|
+
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
4
|
+
import { RotateDeviceIcon } from "../ui/Icons";
|
|
5
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
6
|
+
import { PageViewContext } from "./pageViewContext";
|
|
7
|
+
import { EditorConfiguration } from "../../config/types";
|
|
8
|
+
|
|
9
|
+
export function DeviceToolbar({
|
|
10
|
+
pageViewContext,
|
|
11
|
+
configuration,
|
|
12
|
+
}: {
|
|
13
|
+
pageViewContext: PageViewContext;
|
|
14
|
+
configuration: EditorConfiguration;
|
|
15
|
+
}) {
|
|
16
|
+
const debouncedSetDeviceWidth = useDebouncedCallback(
|
|
17
|
+
(width: number | undefined) => {
|
|
18
|
+
pageViewContext.setDeviceWidth(width);
|
|
19
|
+
},
|
|
20
|
+
400
|
|
21
|
+
);
|
|
22
|
+
const debouncedSetDeviceHeight = useDebouncedCallback(
|
|
23
|
+
(height: number | undefined) => {
|
|
24
|
+
pageViewContext.setDeviceHeight(height);
|
|
25
|
+
},
|
|
26
|
+
400
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex justify-center w-full items-center bg-gray-100 p-1 z-1000 text-sm gap-2 border-b">
|
|
31
|
+
<Dropdown
|
|
32
|
+
options={configuration.devices.map((x) => ({
|
|
33
|
+
label: x.name,
|
|
34
|
+
value: x.name,
|
|
35
|
+
}))}
|
|
36
|
+
value={pageViewContext.device}
|
|
37
|
+
onChange={(e) => pageViewContext.setDevice(e.value)}
|
|
38
|
+
/>
|
|
39
|
+
<InputNumber
|
|
40
|
+
size={4}
|
|
41
|
+
max={10000}
|
|
42
|
+
className="text-sm"
|
|
43
|
+
value={pageViewContext.deviceWidth}
|
|
44
|
+
onChange={(e) => debouncedSetDeviceWidth(e.value || undefined)}
|
|
45
|
+
/>
|
|
46
|
+
x
|
|
47
|
+
<InputNumber
|
|
48
|
+
size={4}
|
|
49
|
+
max={10000}
|
|
50
|
+
className="text-sm"
|
|
51
|
+
value={pageViewContext.deviceHeight}
|
|
52
|
+
onChange={(e) => debouncedSetDeviceHeight(e.value || undefined)}
|
|
53
|
+
/>
|
|
54
|
+
<SimpleIconButton
|
|
55
|
+
icon="pi pi-lock"
|
|
56
|
+
selected={pageViewContext.lockHeight || false}
|
|
57
|
+
onClick={() =>
|
|
58
|
+
pageViewContext.setLockHeight(!pageViewContext.lockHeight)
|
|
59
|
+
}
|
|
60
|
+
label="Lock Height"
|
|
61
|
+
/>
|
|
62
|
+
<SimpleIconButton
|
|
63
|
+
icon={<RotateDeviceIcon className="w-4 h-4" />}
|
|
64
|
+
selected={pageViewContext.rotate || false}
|
|
65
|
+
onClick={() => pageViewContext.setRotate(!pageViewContext.rotate)}
|
|
66
|
+
label="Rotate"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
import { getComponentById } from "../componentTreeHelper";
|
|
3
|
+
|
|
4
|
+
import { FieldList, ItemFields } from "../FieldList";
|
|
5
|
+
import { ItemInfo } from "../ItemInfo";
|
|
6
|
+
import { Insert } from "../sidebar/Insert";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
|
|
9
|
+
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
10
|
+
import { Component, Field, FullItem, RenderedItem } from "../pageModel";
|
|
11
|
+
import { Spinner } from "../ui/Spinner";
|
|
12
|
+
import { PageViewContext } from "./pageViewContext";
|
|
13
|
+
import { SimpleTabs, Tab } from "../ui/SimpleTabs";
|
|
14
|
+
|
|
15
|
+
export function EditorForm({
|
|
16
|
+
pageViewContext,
|
|
17
|
+
readonly,
|
|
18
|
+
compareView,
|
|
19
|
+
}: {
|
|
20
|
+
pageViewContext?: PageViewContext;
|
|
21
|
+
readonly?: boolean;
|
|
22
|
+
compareView: boolean;
|
|
23
|
+
}) {
|
|
24
|
+
const editContext = useEditContext()!;
|
|
25
|
+
if (!pageViewContext) pageViewContext = editContext.pageView;
|
|
26
|
+
|
|
27
|
+
const setInsertMode = editContext.setInsertMode;
|
|
28
|
+
const insertMode =
|
|
29
|
+
editContext.insertMode && editContext.mode === "edit" && !compareView;
|
|
30
|
+
const [activeTabKey, setActiveTabKey] = useState("content");
|
|
31
|
+
const [item, setItem] = useState<RenderedItem>();
|
|
32
|
+
const [component, setComponent] = useState<Component>();
|
|
33
|
+
const [fullItem, setFullItem] = useState<FullItem>();
|
|
34
|
+
|
|
35
|
+
const toggleInsertMode = () => {
|
|
36
|
+
if (insertMode) {
|
|
37
|
+
setInsertMode(false);
|
|
38
|
+
} else {
|
|
39
|
+
setInsertMode(true);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
async function loadFullItem() {
|
|
45
|
+
if (!item) return;
|
|
46
|
+
const fullItem = await editContext!.itemsRepository.getItem(item);
|
|
47
|
+
setFullItem(fullItem);
|
|
48
|
+
}
|
|
49
|
+
loadFullItem();
|
|
50
|
+
}, [item]);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (editContext.selectedForInsertion) setInsertMode(true);
|
|
54
|
+
}, [editContext.selectedForInsertion]);
|
|
55
|
+
|
|
56
|
+
let isShared = false;
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!pageViewContext.page) {
|
|
60
|
+
setComponent(undefined);
|
|
61
|
+
setItem(undefined);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let newSelectedItem;
|
|
65
|
+
|
|
66
|
+
if (editContext.selection.length === 1) {
|
|
67
|
+
const component = getComponentById(
|
|
68
|
+
editContext.selection[0]!,
|
|
69
|
+
pageViewContext.page,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
setComponent(component);
|
|
73
|
+
newSelectedItem = component?.datasourceItem;
|
|
74
|
+
if (
|
|
75
|
+
component?.datasourceItem &&
|
|
76
|
+
component?.datasourceItem?.id !== component?.id
|
|
77
|
+
)
|
|
78
|
+
isShared = true;
|
|
79
|
+
} else {
|
|
80
|
+
newSelectedItem = pageViewContext.page.rootComponent.datasourceItem;
|
|
81
|
+
setComponent(pageViewContext.page.rootComponent);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setItem(
|
|
85
|
+
newSelectedItem || pageViewContext.page.rootComponent.datasourceItem,
|
|
86
|
+
);
|
|
87
|
+
}, [
|
|
88
|
+
editContext.selection,
|
|
89
|
+
pageViewContext.page,
|
|
90
|
+
pageViewContext.pageItemDescriptor,
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
if (!fullItem || !item)
|
|
94
|
+
return (
|
|
95
|
+
<div className="grid h-full w-full items-center justify-center">
|
|
96
|
+
<Spinner />
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const validators =
|
|
101
|
+
editContext.validationResult?.find(
|
|
102
|
+
(x) =>
|
|
103
|
+
x.item.id === item?.id &&
|
|
104
|
+
x.item.language === item?.language &&
|
|
105
|
+
x.item.version === item?.version,
|
|
106
|
+
)?.results || [];
|
|
107
|
+
|
|
108
|
+
let designFields = Object.values(fullItem?.fields || []).filter(
|
|
109
|
+
(x) => x.section === "Design" || x.section === "Rendering",
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const editorFields = component?.editorFields;
|
|
113
|
+
|
|
114
|
+
if (editorFields && editorFields["Design"]) {
|
|
115
|
+
editorFields["Design"]?.addFields.forEach((fieldName) => {
|
|
116
|
+
const field = fullItem?.fields.find((x) => x.name === fieldName);
|
|
117
|
+
if (field) designFields.push(field);
|
|
118
|
+
});
|
|
119
|
+
editorFields["Design"]?.removeFields.forEach((fieldName) => {
|
|
120
|
+
designFields = designFields.filter((x) => x.name !== fieldName);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const itemFields: ItemFields[] = [];
|
|
125
|
+
|
|
126
|
+
const contentFields = Object.values(fullItem?.fields || []).filter(
|
|
127
|
+
(x) =>
|
|
128
|
+
((editorFields && editorFields["Content"]?.addFields.includes(x.name!)) ||
|
|
129
|
+
item.renderedFieldIds.indexOf(x.id) >= 0) &&
|
|
130
|
+
!(
|
|
131
|
+
editorFields && editorFields["Content"]?.removeFields.includes(x.name!)
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
if (contentFields.length > 0) itemFields.push({ fields: contentFields });
|
|
135
|
+
|
|
136
|
+
component?.items
|
|
137
|
+
.filter((x) => x.id !== item.id)
|
|
138
|
+
.forEach((i) => {
|
|
139
|
+
const fields: Field[] = [];
|
|
140
|
+
i.renderedFieldIds.forEach((id) => {
|
|
141
|
+
const field = Object.values(fullItem?.fields || []).find(
|
|
142
|
+
(x) => x.id === id,
|
|
143
|
+
);
|
|
144
|
+
if (field) fields.push(field);
|
|
145
|
+
});
|
|
146
|
+
if (fields.length > 0) itemFields.push({ headline: i.name, fields });
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const getFieldsTab = (fields: ItemFields[], headline: string, id: string) => {
|
|
150
|
+
return {
|
|
151
|
+
label: headline,
|
|
152
|
+
content: (
|
|
153
|
+
<div className="relative h-full">
|
|
154
|
+
<div className="absolute inset-0 overflow-auto">
|
|
155
|
+
<FieldList
|
|
156
|
+
fields={fields}
|
|
157
|
+
validators={validators}
|
|
158
|
+
simplified={true}
|
|
159
|
+
readonly={readonly}
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
),
|
|
164
|
+
id,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const tabPanels: Tab[] = [];
|
|
169
|
+
if (itemFields.length > 0)
|
|
170
|
+
tabPanels.push(getFieldsTab(itemFields, "Content", "content"));
|
|
171
|
+
|
|
172
|
+
//TODO: generalize thisdata-field-id
|
|
173
|
+
if (editorFields) {
|
|
174
|
+
Object.keys(editorFields).forEach((key) => {
|
|
175
|
+
if (key !== "Content" && key !== "Design") {
|
|
176
|
+
const fields = fullItem?.fields.filter((x) =>
|
|
177
|
+
editorFields[key]?.addFields.includes(x.name!),
|
|
178
|
+
);
|
|
179
|
+
if (fields?.length)
|
|
180
|
+
tabPanels.push(getFieldsTab([{ fields }], key, key));
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (designFields?.length)
|
|
186
|
+
tabPanels.push(
|
|
187
|
+
getFieldsTab([{ fields: designFields }], "Design", "design"),
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
tabPanels.push({
|
|
191
|
+
label: "Advanced",
|
|
192
|
+
content: (
|
|
193
|
+
<div className="relative h-full">
|
|
194
|
+
<div className="absolute inset-0 overflow-auto">
|
|
195
|
+
<ItemInfo item={fullItem} />
|
|
196
|
+
<FieldList
|
|
197
|
+
fields={[{ fields: fullItem?.fields || [] }]}
|
|
198
|
+
validators={validators}
|
|
199
|
+
showStandardFieldsEnabled={true}
|
|
200
|
+
readonly={readonly}
|
|
201
|
+
/>
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
),
|
|
205
|
+
id: "advanced",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<div
|
|
210
|
+
className="flex h-full flex-col bg-gray-50"
|
|
211
|
+
data-testid="editor-sidepanel"
|
|
212
|
+
>
|
|
213
|
+
<h1 className="flex h-12 items-center justify-center border-b border-gray-200 p-2">
|
|
214
|
+
{component && component !== pageViewContext.page?.rootComponent && (
|
|
215
|
+
<SimpleIconButton
|
|
216
|
+
icon="pi pi-angle-left"
|
|
217
|
+
onClick={() => editContext.select([])}
|
|
218
|
+
label="Back to page"
|
|
219
|
+
size="large"
|
|
220
|
+
/>
|
|
221
|
+
)}
|
|
222
|
+
{editContext.selection.length === 0 && <div className="w-12" />}
|
|
223
|
+
<div
|
|
224
|
+
className="flex-1 text-center text-gray-800"
|
|
225
|
+
id="item-name"
|
|
226
|
+
data-testid="component-name"
|
|
227
|
+
>
|
|
228
|
+
{item?.name}
|
|
229
|
+
{isShared && (
|
|
230
|
+
<span className="ml-2 rounded-md bg-orange-400 p-2 text-sm text-black">
|
|
231
|
+
Shared
|
|
232
|
+
</span>
|
|
233
|
+
)}
|
|
234
|
+
</div>
|
|
235
|
+
<SimpleIconButton
|
|
236
|
+
id="insert-component-button"
|
|
237
|
+
icon={insertMode ? "pi pi-pencil" : "pi pi-plus"}
|
|
238
|
+
onClick={() => toggleInsertMode()}
|
|
239
|
+
label={insertMode ? "Continue editing" : "Insert component"}
|
|
240
|
+
size="large"
|
|
241
|
+
disabled={
|
|
242
|
+
!editContext.page?.item.canWriteItem ||
|
|
243
|
+
!fullItem?.canWriteItem ||
|
|
244
|
+
editContext.mode !== "edit" ||
|
|
245
|
+
compareView
|
|
246
|
+
}
|
|
247
|
+
/>
|
|
248
|
+
</h1>
|
|
249
|
+
|
|
250
|
+
{insertMode && <Insert />}
|
|
251
|
+
{!insertMode && (
|
|
252
|
+
<SimpleTabs
|
|
253
|
+
key="editor-tabs"
|
|
254
|
+
tabs={tabPanels}
|
|
255
|
+
className="flex flex-1 items-center justify-center border-b border-gray-200 bg-gray-50 py-2.5 text-sm"
|
|
256
|
+
activeTab={tabPanels.findIndex((x) => x.id === activeTabKey) || 0}
|
|
257
|
+
setActiveTab={(index) => setActiveTabKey(tabPanels[index]?.id!)}
|
|
258
|
+
></SimpleTabs>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { useEditContext, EditorMode } from "../client/editContext";
|
|
3
|
+
import { PlaceholderDropZones } from "../page-editor-chrome/PlaceholderDropZones";
|
|
4
|
+
import { FieldEditedIndicators } from "../page-editor-chrome/FieldEditedIndicators";
|
|
5
|
+
import { PageViewContext } from "./pageViewContext";
|
|
6
|
+
import { CommentHighlightings } from "../page-editor-chrome/CommentHighlightings";
|
|
7
|
+
import { SuggestionHighlightings } from "../page-editor-chrome/SuggestionHighlightings";
|
|
8
|
+
|
|
9
|
+
export function MiniMap({
|
|
10
|
+
deviceHeight,
|
|
11
|
+
scroll,
|
|
12
|
+
mainViewIframeRef,
|
|
13
|
+
compareView,
|
|
14
|
+
pageViewContext,
|
|
15
|
+
}: {
|
|
16
|
+
deviceHeight?: number;
|
|
17
|
+
scroll: number;
|
|
18
|
+
mainViewIframeRef: React.RefObject<HTMLIFrameElement | null>;
|
|
19
|
+
compareView: boolean;
|
|
20
|
+
pageViewContext: PageViewContext;
|
|
21
|
+
}) {
|
|
22
|
+
const editContext = useEditContext();
|
|
23
|
+
|
|
24
|
+
const [scale, setScale] = React.useState(1);
|
|
25
|
+
const minimapRef = useRef<HTMLDivElement>(null);
|
|
26
|
+
const scaleContainerRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
|
|
28
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
29
|
+
const [minimapReady, setMinimapReady] = React.useState(false);
|
|
30
|
+
const [refreshScale, setRefreshScale] = React.useState(0);
|
|
31
|
+
|
|
32
|
+
const observerRef = useRef<MutationObserver | null>(null);
|
|
33
|
+
|
|
34
|
+
const editorIframeRef = mainViewIframeRef;
|
|
35
|
+
const minimapContainerRef = useRef<HTMLDivElement>(null);
|
|
36
|
+
|
|
37
|
+
if (!mainViewIframeRef.current) return;
|
|
38
|
+
|
|
39
|
+
const scrollContainer =
|
|
40
|
+
editorIframeRef.current?.contentWindow?.document.scrollingElement ||
|
|
41
|
+
editorIframeRef.current?.contentWindow?.document.body;
|
|
42
|
+
|
|
43
|
+
const calcAndUpdateScale = () => {
|
|
44
|
+
const viewport = pageViewContext.viewport;
|
|
45
|
+
const minimapHeight = minimapContainerRef.current?.clientHeight;
|
|
46
|
+
if (!viewport || !scrollContainer) return;
|
|
47
|
+
const width = viewport.width;
|
|
48
|
+
const scaleX = (editContext?.configuration.outline.width || 100) / width;
|
|
49
|
+
const scaleY =
|
|
50
|
+
Math.max(deviceHeight || 0, minimapHeight || viewport.height) /
|
|
51
|
+
scrollContainer.scrollHeight!;
|
|
52
|
+
|
|
53
|
+
const newScale = Math.min(scaleX, scaleY, 1);
|
|
54
|
+
updateScale(newScale);
|
|
55
|
+
setScale(newScale);
|
|
56
|
+
return newScale;
|
|
57
|
+
};
|
|
58
|
+
// Prevent scale/width feedback loop by tracking previous values
|
|
59
|
+
const prevScaleRef = useRef(scale);
|
|
60
|
+
const prevWidthRef = useRef(0);
|
|
61
|
+
|
|
62
|
+
const miniMapWidth = useMemo(() => {
|
|
63
|
+
const currentWidth = Math.max(
|
|
64
|
+
30,
|
|
65
|
+
scale * (pageViewContext.viewport.width || 0),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Only update if change is significant (>1px) to avoid minor oscillations
|
|
69
|
+
if (
|
|
70
|
+
prevWidthRef.current < currentWidth ||
|
|
71
|
+
(Math.abs(currentWidth - prevWidthRef.current) > 1 &&
|
|
72
|
+
Math.abs(scale - prevScaleRef.current) > 0.01)
|
|
73
|
+
) {
|
|
74
|
+
prevWidthRef.current = currentWidth;
|
|
75
|
+
prevScaleRef.current = scale;
|
|
76
|
+
return currentWidth;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return prevWidthRef.current;
|
|
80
|
+
}, [scale, scrollContainer?.clientWidth, pageViewContext.viewport]);
|
|
81
|
+
|
|
82
|
+
function updateCorrespondingNode(node: HTMLElement) {
|
|
83
|
+
const path = [];
|
|
84
|
+
let current: Node | null = node;
|
|
85
|
+
|
|
86
|
+
if (node?.tagName === "HTML") return;
|
|
87
|
+
|
|
88
|
+
while (
|
|
89
|
+
current &&
|
|
90
|
+
current !== current.ownerDocument?.documentElement &&
|
|
91
|
+
current.parentNode
|
|
92
|
+
) {
|
|
93
|
+
const index = Array.prototype.indexOf.call(
|
|
94
|
+
current.parentNode.childNodes,
|
|
95
|
+
current,
|
|
96
|
+
);
|
|
97
|
+
path.unshift(index);
|
|
98
|
+
current = current.parentNode;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const minimapDoc = iframeRef.current?.contentDocument;
|
|
102
|
+
|
|
103
|
+
if (!minimapDoc) return;
|
|
104
|
+
let correspondingNode: HTMLElement | null = minimapDoc.documentElement;
|
|
105
|
+
let originalNode: HTMLElement | null | undefined =
|
|
106
|
+
mainViewIframeRef.current?.contentWindow?.document.documentElement;
|
|
107
|
+
for (const index of path) {
|
|
108
|
+
if (originalNode && correspondingNode) {
|
|
109
|
+
if (
|
|
110
|
+
originalNode.childNodes.length !== correspondingNode.childNodes.length
|
|
111
|
+
) {
|
|
112
|
+
correspondingNode.innerHTML = originalNode.innerHTML;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (originalNode) {
|
|
118
|
+
originalNode = originalNode.childNodes[index] as HTMLElement;
|
|
119
|
+
}
|
|
120
|
+
if (correspondingNode) {
|
|
121
|
+
correspondingNode = correspondingNode.childNodes[index] as HTMLElement;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (correspondingNode && originalNode) {
|
|
126
|
+
if (originalNode.tagName === "HEAD")
|
|
127
|
+
correspondingNode.innerHTML = originalNode.innerHTML;
|
|
128
|
+
else {
|
|
129
|
+
correspondingNode.outerHTML = originalNode.outerHTML;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const handleLoad = () => {
|
|
135
|
+
if (!mainViewIframeRef?.current?.contentWindow?.document) return;
|
|
136
|
+
|
|
137
|
+
mirrorIframeContent(editorIframeRef.current!, iframeRef.current!);
|
|
138
|
+
|
|
139
|
+
const observer = new MutationObserver((mutationsList) => {
|
|
140
|
+
const minimapDoc = iframeRef.current?.contentDocument;
|
|
141
|
+
if (!minimapDoc) return;
|
|
142
|
+
|
|
143
|
+
// get distinct list of target nodes
|
|
144
|
+
const targetNodes = mutationsList
|
|
145
|
+
.filter((x) => x.type === "childList" && x.target.parentElement)
|
|
146
|
+
.map((m) => m.target)
|
|
147
|
+
.concat(
|
|
148
|
+
mutationsList
|
|
149
|
+
.filter(
|
|
150
|
+
(x) =>
|
|
151
|
+
x.type === "characterData" ||
|
|
152
|
+
(x.type === "attributes" && x.target.parentElement),
|
|
153
|
+
)
|
|
154
|
+
.map((m) => m.target.parentElement!),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const distinctTargetNodes = Array.from(new Set(targetNodes));
|
|
158
|
+
|
|
159
|
+
const nodesToRemove = new Set<Node>();
|
|
160
|
+
|
|
161
|
+
for (let i = 0; i < distinctTargetNodes.length; i++) {
|
|
162
|
+
for (let j = 0; j < distinctTargetNodes.length; j++) {
|
|
163
|
+
if (i !== j) {
|
|
164
|
+
if (
|
|
165
|
+
distinctTargetNodes[i]?.contains(distinctTargetNodes[j] as Node)
|
|
166
|
+
) {
|
|
167
|
+
nodesToRemove.add(distinctTargetNodes[j] as Node);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const filteredNodes = distinctTargetNodes.filter(
|
|
174
|
+
(node) => !nodesToRemove.has(node),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
filteredNodes.forEach((targetNode) => {
|
|
178
|
+
updateCorrespondingNode(targetNode as HTMLElement);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
setRefreshScale((x) => x + 1);
|
|
182
|
+
});
|
|
183
|
+
observer.observe(mainViewIframeRef.current.contentWindow!.document!, {
|
|
184
|
+
childList: true, // observe direct children changes
|
|
185
|
+
subtree: true, // observe all descendants changes
|
|
186
|
+
characterData: true, // observe text changes
|
|
187
|
+
attributes: true, // observe attribute changes (like style or class)
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
setMinimapReady(true);
|
|
191
|
+
observerRef.current = observer;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (editorIframeRef?.current) {
|
|
196
|
+
editorIframeRef?.current.addEventListener("load", handleLoad);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
handleLoad();
|
|
200
|
+
|
|
201
|
+
// Cleanup function
|
|
202
|
+
return () => {
|
|
203
|
+
editorIframeRef?.current?.removeEventListener("load", handleLoad);
|
|
204
|
+
};
|
|
205
|
+
}, [mainViewIframeRef.current, iframeRef.current]);
|
|
206
|
+
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
calcAndUpdateScale();
|
|
209
|
+
}, [
|
|
210
|
+
refreshScale,
|
|
211
|
+
editorIframeRef,
|
|
212
|
+
//pageViewContext?.windowSize,
|
|
213
|
+
pageViewContext?.zoom,
|
|
214
|
+
pageViewContext.viewport,
|
|
215
|
+
pageViewContext.deviceHeight,
|
|
216
|
+
pageViewContext.deviceWidth,
|
|
217
|
+
]);
|
|
218
|
+
|
|
219
|
+
if (!editContext) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const scrollDocumentTo = (y: number) => {
|
|
224
|
+
if (!editorIframeRef?.current) return;
|
|
225
|
+
|
|
226
|
+
if (!scrollContainer) return;
|
|
227
|
+
|
|
228
|
+
scrollContainer.scrollTo({
|
|
229
|
+
top: y,
|
|
230
|
+
behavior: "smooth",
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const scrollHeight = scrollContainer?.scrollHeight;
|
|
235
|
+
const scrollTop = scroll;
|
|
236
|
+
|
|
237
|
+
const viewport = pageViewContext.viewport;
|
|
238
|
+
|
|
239
|
+
function mirrorIframeContent(
|
|
240
|
+
sourceIframe: HTMLIFrameElement,
|
|
241
|
+
targetIframe: HTMLIFrameElement,
|
|
242
|
+
) {
|
|
243
|
+
if (sourceIframe.contentDocument && targetIframe.contentDocument) {
|
|
244
|
+
const sourceHtml = sourceIframe.contentDocument.documentElement.innerHTML;
|
|
245
|
+
targetIframe.contentDocument.documentElement.innerHTML = sourceHtml;
|
|
246
|
+
targetIframe.contentDocument.documentElement.style.overflow = "hidden";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
setRefreshScale((x) => x + 1);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const updateScale = (scale: number) => {
|
|
253
|
+
if (!iframeRef.current || !scaleContainerRef.current) return;
|
|
254
|
+
|
|
255
|
+
// console.log(
|
|
256
|
+
// "Update Scale: ScrollHeight: ",
|
|
257
|
+
// scrollContainer?.scrollHeight,
|
|
258
|
+
// " scrollcontainer: ",
|
|
259
|
+
// scrollContainer,
|
|
260
|
+
// );
|
|
261
|
+
|
|
262
|
+
scaleContainerRef.current.style.transform = `scale(${scale})`;
|
|
263
|
+
scaleContainerRef.current.style.transformOrigin = "0 0";
|
|
264
|
+
|
|
265
|
+
iframeRef.current.style.width = `${scrollContainer?.clientWidth}px`;
|
|
266
|
+
iframeRef.current.style.height = `${scrollContainer?.scrollHeight}px`;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const handleClick = (e: React.MouseEvent) => {
|
|
270
|
+
if (!scrollContainer) return;
|
|
271
|
+
const iframeRect = iframeRef.current!.getBoundingClientRect();
|
|
272
|
+
const absY = e.clientY - iframeRect.top;
|
|
273
|
+
const relY = (absY / iframeRect.height) * scrollContainer.scrollHeight;
|
|
274
|
+
|
|
275
|
+
e.stopPropagation();
|
|
276
|
+
scrollDocumentTo(relY - viewport.height / 2);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const handleScroll = useCallback(
|
|
280
|
+
(e: React.WheelEvent) => {
|
|
281
|
+
if (!scrollContainer) return;
|
|
282
|
+
scrollContainer.scrollBy({
|
|
283
|
+
behavior: "instant",
|
|
284
|
+
left: 0,
|
|
285
|
+
top: e.deltaY,
|
|
286
|
+
});
|
|
287
|
+
editorIframeRef.current?.contentWindow?.document.documentElement?.scrollBy(
|
|
288
|
+
{
|
|
289
|
+
behavior: "instant",
|
|
290
|
+
left: 0,
|
|
291
|
+
top: e.deltaY,
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
e.stopPropagation();
|
|
295
|
+
},
|
|
296
|
+
[editorIframeRef],
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<div
|
|
301
|
+
className="relative overflow-hidden bg-white"
|
|
302
|
+
ref={minimapContainerRef}
|
|
303
|
+
style={{
|
|
304
|
+
height: "100%",
|
|
305
|
+
width: miniMapWidth + "px",
|
|
306
|
+
boxShadow: "5px 0 5px -5px #333",
|
|
307
|
+
}}
|
|
308
|
+
>
|
|
309
|
+
<div
|
|
310
|
+
className="bg-opacity-50 absolute inset-0 overflow-hidden select-none"
|
|
311
|
+
style={{
|
|
312
|
+
boxShadow: "rgb(200, 200, 200) -10px 1px 13px -10px",
|
|
313
|
+
}}
|
|
314
|
+
>
|
|
315
|
+
<div
|
|
316
|
+
ref={minimapRef}
|
|
317
|
+
onClickCapture={handleClick}
|
|
318
|
+
onDragOverCapture={handleClick}
|
|
319
|
+
onWheelCapture={handleScroll}
|
|
320
|
+
className="h-full w-full cursor-pointer"
|
|
321
|
+
>
|
|
322
|
+
<div ref={scaleContainerRef}>
|
|
323
|
+
<iframe
|
|
324
|
+
className="pointer-events-none"
|
|
325
|
+
ref={iframeRef}
|
|
326
|
+
style={{ visibility: minimapReady ? "visible" : "hidden" }}
|
|
327
|
+
/>
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
</div>
|
|
331
|
+
{scrollTop !== undefined &&
|
|
332
|
+
scrollHeight !== undefined &&
|
|
333
|
+
minimapReady && (
|
|
334
|
+
<div
|
|
335
|
+
className="pointer-events-none absolute w-full bg-gray-300 opacity-60 hover:opacity-65"
|
|
336
|
+
style={{
|
|
337
|
+
top: scrollTop * scale + "px",
|
|
338
|
+
height: viewport.height * scale + "px",
|
|
339
|
+
}}
|
|
340
|
+
></div>
|
|
341
|
+
)}
|
|
342
|
+
{editContext.mode === "edit" && (
|
|
343
|
+
<PlaceholderDropZones
|
|
344
|
+
scale={scale}
|
|
345
|
+
iframe={iframeRef.current}
|
|
346
|
+
size="small"
|
|
347
|
+
/>
|
|
348
|
+
)}
|
|
349
|
+
<FieldEditedIndicators
|
|
350
|
+
scale={scale}
|
|
351
|
+
pageViewContext={pageViewContext}
|
|
352
|
+
scroll={scroll}
|
|
353
|
+
/>
|
|
354
|
+
{editContext.showComments && (
|
|
355
|
+
<CommentHighlightings iframe={iframeRef.current!} scale={scale} />
|
|
356
|
+
)}
|
|
357
|
+
{editContext.showSuggestedEdits && (
|
|
358
|
+
<SuggestionHighlightings iframe={iframeRef.current!} scale={scale} />
|
|
359
|
+
)}
|
|
360
|
+
</div>
|
|
361
|
+
);
|
|
362
|
+
}
|