@alpaca-editor/core 1.0.3939 → 1.0.3941
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/dist/components/ActionButton.d.ts +1 -0
- package/dist/components/ActionButton.js +2 -2
- package/dist/components/ActionButton.js.map +1 -1
- package/dist/editor/FieldActionsOverlay.d.ts +1 -0
- package/dist/editor/FieldActionsOverlay.js +2 -11
- package/dist/editor/FieldActionsOverlay.js.map +1 -1
- package/dist/editor/PictureCropper.js +65 -23
- package/dist/editor/PictureCropper.js.map +1 -1
- package/dist/editor/PictureEditor.js +16 -2
- package/dist/editor/PictureEditor.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 +21 -2
- package/dist/editor/ai/GhostWriter.js.map +1 -1
- package/dist/editor/commands/componentCommands.js +7 -3
- package/dist/editor/commands/componentCommands.js.map +1 -1
- package/dist/editor/media-selector/MediaFolderBrowser.d.ts +5 -0
- package/dist/editor/media-selector/MediaFolderBrowser.js +77 -0
- package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -0
- package/dist/editor/media-selector/MediaSelector.js +1 -1
- package/dist/editor/media-selector/MediaSelector.js.map +1 -1
- package/dist/editor/media-selector/Thumbnails.js +2 -2
- package/dist/editor/media-selector/index.d.ts +8 -0
- package/dist/editor/media-selector/index.js +9 -0
- package/dist/editor/media-selector/index.js.map +1 -0
- package/dist/editor/menubar/BrowseHistory.js +1 -1
- package/dist/editor/menubar/PageSelector.js +39 -15
- package/dist/editor/menubar/PageSelector.js.map +1 -1
- package/dist/editor/page-editor-chrome/useInlineAICompletion.js +37 -11
- package/dist/editor/page-editor-chrome/useInlineAICompletion.js.map +1 -1
- package/dist/editor/reviews/Comment.js +1 -1
- package/dist/editor/reviews/Comment.js.map +1 -1
- package/dist/editor/services/aiService.js +0 -1
- package/dist/editor/services/aiService.js.map +1 -1
- package/dist/editor/sidebar/ComponentTree.js +3 -4
- package/dist/editor/sidebar/ComponentTree.js.map +1 -1
- package/dist/editor/ui/SimpleTabs.d.ts +1 -0
- package/dist/editor/ui/SimpleTabs.js +3 -3
- package/dist/editor/ui/SimpleTabs.js.map +1 -1
- package/dist/editor/ui/Splitter.js +61 -6
- package/dist/editor/ui/Splitter.js.map +1 -1
- package/dist/editor/views/MediaFolderEditView.d.ts +4 -0
- package/dist/editor/views/MediaFolderEditView.js +40 -0
- package/dist/editor/views/MediaFolderEditView.js.map +1 -0
- package/dist/editor/views/SingleEditView.js +9 -1
- package/dist/editor/views/SingleEditView.js.map +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +61 -5
- package/package.json +8 -2
- package/.prettierrc +0 -3
- package/build.css +0 -3
- package/components.json +0 -21
- package/eslint.config.mjs +0 -4
- 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/src/client-components/api.ts +0 -6
- package/src/client-components/index.ts +0 -19
- package/src/components/ActionButton.tsx +0 -41
- package/src/components/Error.tsx +0 -57
- package/src/components/ui/CardConnector.tsx +0 -56
- package/src/components/ui/button.tsx +0 -62
- package/src/components/ui/card.tsx +0 -372
- package/src/components/ui/context-menu.tsx +0 -250
- package/src/config/config.tsx +0 -917
- package/src/config/types.ts +0 -286
- package/src/editor/ComponentInfo.tsx +0 -90
- package/src/editor/ConfirmationDialog.tsx +0 -103
- package/src/editor/ContentTree.tsx +0 -730
- package/src/editor/ContextMenu.tsx +0 -230
- package/src/editor/Editor.tsx +0 -90
- package/src/editor/EditorWarning.tsx +0 -34
- package/src/editor/EditorWarnings.tsx +0 -33
- package/src/editor/FieldActionsOverlay.tsx +0 -307
- package/src/editor/FieldEditorPopup.tsx +0 -65
- package/src/editor/FieldHistory.tsx +0 -75
- package/src/editor/FieldList.tsx +0 -190
- package/src/editor/FieldListField.tsx +0 -391
- package/src/editor/FieldListFieldWithFallbacks.tsx +0 -217
- package/src/editor/FloatingToolbar.tsx +0 -163
- package/src/editor/ImageEditor.tsx +0 -128
- package/src/editor/ItemInfo.tsx +0 -90
- package/src/editor/LinkEditorDialog.tsx +0 -196
- package/src/editor/MainLayout.tsx +0 -95
- package/src/editor/MobileLayout.tsx +0 -68
- package/src/editor/NewEditorClient.tsx +0 -11
- package/src/editor/PictureCropper.tsx +0 -503
- package/src/editor/PictureEditor.tsx +0 -277
- package/src/editor/PictureEditorDialog.tsx +0 -381
- package/src/editor/PublishDialog.ignore +0 -74
- package/src/editor/ScrollingContentTree.tsx +0 -67
- package/src/editor/Terminal.tsx +0 -227
- package/src/editor/Titlebar.tsx +0 -104
- package/src/editor/ai/AiPopup.tsx +0 -59
- package/src/editor/ai/AiResponseMessage.tsx +0 -106
- package/src/editor/ai/AiTerminal.tsx +0 -503
- package/src/editor/ai/AiToolCall.tsx +0 -61
- package/src/editor/ai/EditorAiTerminal.tsx +0 -20
- package/src/editor/ai/GhostWriter.tsx +0 -432
- package/src/editor/ai/aiPageModel.ts +0 -108
- package/src/editor/ai/editorAiContext.ts +0 -18
- package/src/editor/client/AboutDialog.tsx +0 -44
- package/src/editor/client/EditorClient.tsx +0 -2241
- package/src/editor/client/GenericDialog.tsx +0 -50
- package/src/editor/client/editContext.ts +0 -416
- package/src/editor/client/helpers.ts +0 -44
- package/src/editor/client/itemsRepository.ts +0 -574
- package/src/editor/client/operations.ts +0 -768
- package/src/editor/client/pageModelBuilder.ts +0 -219
- package/src/editor/commands/commands.ts +0 -22
- package/src/editor/commands/componentCommands.tsx +0 -424
- package/src/editor/commands/createVersionCommand.ts +0 -33
- package/src/editor/commands/deleteVersionCommand.ts +0 -71
- package/src/editor/commands/itemCommands.tsx +0 -351
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +0 -201
- package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +0 -27
- package/src/editor/commands/undo.ts +0 -39
- package/src/editor/component-designer/ComponentDesigner.tsx +0 -70
- package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +0 -11
- package/src/editor/component-designer/ComponentDesignerMenu.tsx +0 -91
- package/src/editor/component-designer/ComponentEditor.tsx +0 -97
- package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +0 -31
- package/src/editor/component-designer/ComponentRenderingEditor.tsx +0 -104
- package/src/editor/component-designer/ComponentsDropdown.tsx +0 -39
- package/src/editor/component-designer/PlaceholdersEditor.tsx +0 -179
- package/src/editor/component-designer/RenderingsDropdown.tsx +0 -36
- package/src/editor/component-designer/TemplateEditor.tsx +0 -236
- package/src/editor/component-designer/aiContext.ts +0 -23
- package/src/editor/componentTreeHelper.tsx +0 -116
- package/src/editor/context-menu/CopyMoveMenu.tsx +0 -103
- package/src/editor/context-menu/InsertMenu.tsx +0 -347
- package/src/editor/control-center/About.tsx +0 -342
- package/src/editor/control-center/ControlCenterMenu.tsx +0 -76
- package/src/editor/control-center/IndexOverview.tsx +0 -50
- package/src/editor/control-center/IndexSettings.tsx +0 -266
- package/src/editor/control-center/Info.tsx +0 -104
- package/src/editor/control-center/QuotaInfo.tsx +0 -301
- package/src/editor/control-center/Status.tsx +0 -113
- package/src/editor/control-center/WebSocketMessages.tsx +0 -155
- package/src/editor/editor-warnings/ItemLocked.tsx +0 -63
- package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +0 -22
- package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +0 -23
- package/src/editor/editor-warnings/NoWriteAccess.tsx +0 -16
- package/src/editor/editor-warnings/ValidationErrors.tsx +0 -54
- package/src/editor/field-types/AttachmentEditor.tsx +0 -9
- package/src/editor/field-types/CheckboxEditor.tsx +0 -47
- package/src/editor/field-types/DropLinkEditor.tsx +0 -80
- package/src/editor/field-types/DropListEditor.tsx +0 -84
- package/src/editor/field-types/ImageFieldEditor.tsx +0 -65
- package/src/editor/field-types/InternalLinkFieldEditor.tsx +0 -117
- package/src/editor/field-types/LinkFieldEditor.tsx +0 -85
- package/src/editor/field-types/MultiLineText.tsx +0 -82
- package/src/editor/field-types/PictureFieldEditor.tsx +0 -121
- package/src/editor/field-types/RawEditor.tsx +0 -53
- package/src/editor/field-types/ReactQuill.tsx +0 -580
- package/src/editor/field-types/RichTextEditor.tsx +0 -22
- package/src/editor/field-types/RichTextEditorComponent.tsx +0 -127
- package/src/editor/field-types/SingleLineText.tsx +0 -174
- package/src/editor/field-types/TreeListEditor.tsx +0 -261
- package/src/editor/fieldTypes.ts +0 -140
- package/src/editor/media-selector/AiImageSearch.tsx +0 -185
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +0 -94
- package/src/editor/media-selector/MediaSelector.tsx +0 -42
- package/src/editor/media-selector/Preview.tsx +0 -14
- package/src/editor/media-selector/Thumbnails.tsx +0 -48
- package/src/editor/media-selector/TreeSelector.tsx +0 -292
- package/src/editor/media-selector/UploadZone.tsx +0 -137
- package/src/editor/menubar/ActionsMenu.tsx +0 -94
- package/src/editor/menubar/ActiveUsers.tsx +0 -17
- package/src/editor/menubar/ApproveAndPublish.tsx +0 -18
- package/src/editor/menubar/BrowseHistory.tsx +0 -28
- package/src/editor/menubar/ItemLanguageVersion.tsx +0 -76
- package/src/editor/menubar/LanguageSelector.tsx +0 -226
- package/src/editor/menubar/Menu.tsx +0 -83
- package/src/editor/menubar/NavButtons.tsx +0 -74
- package/src/editor/menubar/PageSelector.tsx +0 -166
- package/src/editor/menubar/PageViewerControls.tsx +0 -120
- package/src/editor/menubar/PreviewSecondaryControls.tsx +0 -18
- package/src/editor/menubar/SecondaryControls.tsx +0 -45
- package/src/editor/menubar/Separator.tsx +0 -12
- package/src/editor/menubar/SiteInfo.tsx +0 -53
- package/src/editor/menubar/User.tsx +0 -27
- package/src/editor/menubar/VersionSelector.tsx +0 -142
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +0 -307
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +0 -35
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +0 -59
- package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +0 -23
- package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +0 -64
- package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +0 -35
- package/src/editor/page-editor-chrome/FrameMenu.tsx +0 -338
- package/src/editor/page-editor-chrome/FrameMenus.tsx +0 -48
- package/src/editor/page-editor-chrome/InlineEditor.tsx +0 -765
- package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +0 -61
- package/src/editor/page-editor-chrome/NoLayout.tsx +0 -36
- package/src/editor/page-editor-chrome/PageEditorChrome.tsx +0 -122
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +0 -161
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +0 -169
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +0 -315
- package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +0 -300
- package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +0 -40
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +0 -791
- package/src/editor/page-viewer/DeviceToolbar.tsx +0 -70
- package/src/editor/page-viewer/EditorForm.tsx +0 -258
- package/src/editor/page-viewer/MiniMap.tsx +0 -362
- package/src/editor/page-viewer/PageViewer.tsx +0 -169
- package/src/editor/page-viewer/PageViewerFrame.tsx +0 -1022
- package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +0 -412
- package/src/editor/page-viewer/pageViewContext.ts +0 -186
- package/src/editor/pageModel.ts +0 -220
- package/src/editor/picture-shared.tsx +0 -53
- package/src/editor/reviews/Comment.tsx +0 -307
- package/src/editor/reviews/Comments.tsx +0 -125
- package/src/editor/reviews/DiffView.tsx +0 -109
- package/src/editor/reviews/PreviewInfo.tsx +0 -35
- package/src/editor/reviews/Reviews.tsx +0 -280
- package/src/editor/reviews/SuggestedEdit.tsx +0 -316
- package/src/editor/reviews/reviewCommands.tsx +0 -47
- package/src/editor/reviews/useReviews.tsx +0 -70
- package/src/editor/services/aiService.ts +0 -174
- package/src/editor/services/componentDesignerService.ts +0 -151
- package/src/editor/services/contentService.ts +0 -180
- package/src/editor/services/editService.ts +0 -488
- package/src/editor/services/indexService.ts +0 -24
- package/src/editor/services/reviewsService.ts +0 -53
- package/src/editor/services/serviceHelper.ts +0 -95
- package/src/editor/services/suggestedEditsService.ts +0 -39
- package/src/editor/services/systemService.ts +0 -5
- package/src/editor/services/translationService.ts +0 -21
- package/src/editor/services-server/api.ts +0 -150
- package/src/editor/services-server/graphQL.ts +0 -106
- package/src/editor/sidebar/ComponentPalette.tsx +0 -161
- package/src/editor/sidebar/ComponentTree.tsx +0 -548
- package/src/editor/sidebar/ComponentTree2.tsxx +0 -490
- package/src/editor/sidebar/Debug.tsx +0 -111
- package/src/editor/sidebar/DictionaryEditor.tsx +0 -261
- package/src/editor/sidebar/EditHistory.tsx +0 -134
- package/src/editor/sidebar/GraphQL.tsx +0 -164
- package/src/editor/sidebar/Insert.tsx +0 -35
- package/src/editor/sidebar/MainContentTree.tsx +0 -102
- package/src/editor/sidebar/Performance.tsx +0 -53
- package/src/editor/sidebar/Sessions.tsx +0 -35
- package/src/editor/sidebar/Sidebar.tsx +0 -20
- package/src/editor/sidebar/SidebarView.tsx +0 -152
- package/src/editor/sidebar/Translations.tsx +0 -295
- package/src/editor/sidebar/Validation.tsx +0 -102
- package/src/editor/sidebar/ViewSelector.tsx +0 -60
- package/src/editor/sidebar/Workbox.tsx +0 -209
- package/src/editor/ui/CenteredMessage.tsx +0 -7
- package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +0 -81
- package/src/editor/ui/CopyToClipboardButton.tsx +0 -24
- package/src/editor/ui/DialogButtons.tsx +0 -11
- package/src/editor/ui/Icons.tsx +0 -709
- package/src/editor/ui/ItemList.tsx +0 -76
- package/src/editor/ui/ItemNameDialogNew.tsx +0 -118
- package/src/editor/ui/ItemSearch.tsx +0 -153
- package/src/editor/ui/PerfectTree.tsx +0 -571
- package/src/editor/ui/Section.tsx +0 -35
- package/src/editor/ui/SimpleIconButton.tsx +0 -54
- package/src/editor/ui/SimpleMenu.tsx +0 -40
- package/src/editor/ui/SimpleTable.tsx +0 -60
- package/src/editor/ui/SimpleTabs.tsx +0 -55
- package/src/editor/ui/SimpleToolbar.tsx +0 -7
- package/src/editor/ui/Spinner.tsx +0 -9
- package/src/editor/ui/Splitter.tsx +0 -314
- package/src/editor/ui/StackedPanels.tsx +0 -134
- package/src/editor/ui/Toolbar.tsx +0 -7
- package/src/editor/utils/id-helper.ts +0 -3
- package/src/editor/utils/insertOptions.ts +0 -69
- package/src/editor/utils/itemutils.ts +0 -29
- package/src/editor/utils/useMemoDebug.ts +0 -28
- package/src/editor/utils.ts +0 -486
- package/src/editor/views/CompareView.tsx +0 -245
- package/src/editor/views/EditView.tsx +0 -27
- package/src/editor/views/ItemEditor.tsx +0 -58
- package/src/editor/views/SingleEditView.tsx +0 -46
- 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 +0 -10
- package/src/index.ts +0 -23
- package/src/lib/safelist.tsx +0 -16
- package/src/lib/utils.ts +0 -6
- package/src/page-wizard/PageWizard.tsx +0 -139
- package/src/page-wizard/WizardBox.tsx +0 -4
- package/src/page-wizard/WizardBoxConnector.tsx +0 -56
- package/src/page-wizard/WizardSteps.tsx +0 -458
- package/src/page-wizard/service.ts +0 -35
- package/src/page-wizard/startPageWizardCommand.ts +0 -26
- package/src/page-wizard/steps/BuildPageStep.tsx +0 -259
- package/src/page-wizard/steps/CollectStep.tsx +0 -296
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +0 -454
- package/src/page-wizard/steps/Components.tsx +0 -193
- package/src/page-wizard/steps/ContentStep.tsx +0 -890
- package/src/page-wizard/steps/EditButton.tsx +0 -34
- package/src/page-wizard/steps/FieldEditor.tsx +0 -102
- package/src/page-wizard/steps/Generate.tsx +0 -60
- package/src/page-wizard/steps/ImagesStep.tsx +0 -382
- package/src/page-wizard/steps/LayoutStep.tsx +0 -227
- package/src/page-wizard/steps/MetaDataStep.tsx +0 -173
- package/src/page-wizard/steps/SelectStep.tsx +0 -281
- package/src/page-wizard/steps/schema.ts +0 -180
- package/src/page-wizard/steps/usePageCreator.ts +0 -325
- package/src/page-wizard/usePageWizard.ts +0 -79
- package/src/revision.ts +0 -2
- package/src/splash-screen/NewPage.tsx +0 -294
- package/src/splash-screen/OpenPage.tsx +0 -113
- package/src/splash-screen/RecentPages.tsx +0 -123
- package/src/splash-screen/SectionHeadline.tsx +0 -21
- package/src/splash-screen/SplashScreen.tsx +0 -195
- package/src/tour/Tour.tsx +0 -566
- package/src/tour/default-tour.tsx +0 -301
- package/src/tour/preview-tour.tsx +0 -128
- package/src/types.ts +0 -335
- package/styles.css +0 -765
- package/tsconfig.build.json +0 -31
- package/tsconfig.json +0 -14
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { useEditContext } from "../client/editContext";
|
|
3
|
-
|
|
4
|
-
import { getAllPlaceholders } from "../componentTreeHelper";
|
|
5
|
-
import { findComponentRect } from "../utils";
|
|
6
|
-
import { PlaceholderDropZone } from "./PlaceholderDropZone";
|
|
7
|
-
import { Placeholder, Component } from "../pageModel";
|
|
8
|
-
|
|
9
|
-
export function PlaceholderDropZones({
|
|
10
|
-
scale,
|
|
11
|
-
iframe,
|
|
12
|
-
size,
|
|
13
|
-
}: {
|
|
14
|
-
scale?: number;
|
|
15
|
-
iframe?: HTMLIFrameElement | null;
|
|
16
|
-
size: "large" | "small";
|
|
17
|
-
}) {
|
|
18
|
-
const [placeholders, setPlaceholders] = useState<Placeholder[]>([]);
|
|
19
|
-
const editContext = useEditContext();
|
|
20
|
-
const pageViewContext = editContext?.pageView;
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (!pageViewContext?.page) return;
|
|
24
|
-
setPlaceholders(getAllPlaceholders(pageViewContext.page!));
|
|
25
|
-
}, [pageViewContext?.page]);
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
!pageViewContext ||
|
|
29
|
-
(!editContext?.dragObject && !editContext.selectedForInsertion) ||
|
|
30
|
-
!placeholders
|
|
31
|
-
)
|
|
32
|
-
return null;
|
|
33
|
-
|
|
34
|
-
const matchingPlaceholders = placeholders.filter(
|
|
35
|
-
(x) =>
|
|
36
|
-
x.parentComponent?.id === editContext.selectedForInsertion ||
|
|
37
|
-
x.insertOptions?.find(
|
|
38
|
-
(y) =>
|
|
39
|
-
y.typeId === editContext.selectedForInsertion ||
|
|
40
|
-
y.typeId === editContext.dragObject?.typeId ||
|
|
41
|
-
y.typeId === editContext.dragObject?.templateId ||
|
|
42
|
-
y.compatibleTypeIds?.find(
|
|
43
|
-
(z) => z == editContext.dragObject?.typeId,
|
|
44
|
-
) !== undefined ||
|
|
45
|
-
y.typeId === editContext.dragObject?.templateId ||
|
|
46
|
-
y.compatibleTypeIds?.find(
|
|
47
|
-
(z) => z == editContext.dragObject?.templateId,
|
|
48
|
-
) !== undefined,
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
if (!iframe) return;
|
|
53
|
-
|
|
54
|
-
const zones: {
|
|
55
|
-
placeholder: Placeholder;
|
|
56
|
-
position: { x: number; y: number };
|
|
57
|
-
index: number;
|
|
58
|
-
element: Element;
|
|
59
|
-
anchor: "top" | "bottom" | "left" | "right";
|
|
60
|
-
description?: string | null;
|
|
61
|
-
}[] = [];
|
|
62
|
-
|
|
63
|
-
const scrollHeight =
|
|
64
|
-
editContext.pageView.editorIframeRef?.current?.contentWindow?.document
|
|
65
|
-
.documentElement.scrollHeight || 0;
|
|
66
|
-
|
|
67
|
-
matchingPlaceholders.forEach((placeholder) => {
|
|
68
|
-
let placeholderElement = iframe!.contentWindow?.document.body.querySelector(
|
|
69
|
-
"[data-placeholder-start='" + placeholder.key + "']",
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (!placeholderElement && placeholder.components.length > 0) {
|
|
73
|
-
placeholderElement = placeholder.components[0]?.firstDOMElement;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!placeholderElement) return;
|
|
77
|
-
|
|
78
|
-
const prev = getPreviousElement(placeholderElement);
|
|
79
|
-
|
|
80
|
-
const nextOrParent =
|
|
81
|
-
getNextElement(placeholderElement) || placeholderElement.parentElement;
|
|
82
|
-
|
|
83
|
-
let orientation = placeholderElement?.getAttribute("data-orientation");
|
|
84
|
-
|
|
85
|
-
if (!orientation)
|
|
86
|
-
orientation = detectOrientation(
|
|
87
|
-
placeholderElement,
|
|
88
|
-
placeholder.components,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const rect = (prev ?? nextOrParent)!.getBoundingClientRect();
|
|
92
|
-
const zoom = pageViewContext.zoom;
|
|
93
|
-
|
|
94
|
-
const position =
|
|
95
|
-
orientation === "horizontal"
|
|
96
|
-
? {
|
|
97
|
-
x: (prev ? rect.x + rect.width : rect.x) * zoom,
|
|
98
|
-
y: (rect.y + rect.height / 2) * zoom,
|
|
99
|
-
}
|
|
100
|
-
: {
|
|
101
|
-
x: (rect.x + rect.width / 2) * zoom,
|
|
102
|
-
y: (prev ? rect.y + rect.height : rect.y) * zoom,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
let index = 0;
|
|
106
|
-
|
|
107
|
-
const description = placeholderElement.getAttribute("data-description");
|
|
108
|
-
|
|
109
|
-
let anchor: "top" | "bottom" | "left" | "right" = "top";
|
|
110
|
-
|
|
111
|
-
if (prev && orientation === "horizontal") {
|
|
112
|
-
anchor = "right";
|
|
113
|
-
}
|
|
114
|
-
if (prev && orientation !== "horizontal") {
|
|
115
|
-
anchor = "bottom";
|
|
116
|
-
}
|
|
117
|
-
if (!prev && orientation === "horizontal") {
|
|
118
|
-
anchor = "left";
|
|
119
|
-
}
|
|
120
|
-
if (!prev && orientation !== "horizontal") {
|
|
121
|
-
anchor = "top";
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
zones.push({
|
|
125
|
-
placeholder,
|
|
126
|
-
position,
|
|
127
|
-
index,
|
|
128
|
-
element: prev ?? nextOrParent!,
|
|
129
|
-
anchor,
|
|
130
|
-
description,
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
placeholder.components.forEach((component) => {
|
|
134
|
-
const componentRect = findComponentRect(iframe, component);
|
|
135
|
-
if (!componentRect) return;
|
|
136
|
-
|
|
137
|
-
const position = getPositionFromRect(
|
|
138
|
-
componentRect.rect,
|
|
139
|
-
pageViewContext.zoom,
|
|
140
|
-
orientation,
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
index++;
|
|
144
|
-
|
|
145
|
-
zones.push({
|
|
146
|
-
placeholder,
|
|
147
|
-
position,
|
|
148
|
-
index,
|
|
149
|
-
anchor: orientation === "horizontal" ? "right" : "bottom",
|
|
150
|
-
element: componentRect.elements[componentRect.elements.length - 1]!,
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// let nextElement = placeholderElement?.nextElementSibling;
|
|
155
|
-
// while (nextElement) {
|
|
156
|
-
// nextElement = nextElement?.nextElementSibling;
|
|
157
|
-
// if (nextElement) {
|
|
158
|
-
// if (
|
|
159
|
-
// nextElement.getAttribute("data-placeholder-end") === placeholder.key
|
|
160
|
-
// ) {
|
|
161
|
-
// break;
|
|
162
|
-
// }
|
|
163
|
-
|
|
164
|
-
// if (nextElement.getAttribute("data-component-end")) {
|
|
165
|
-
// const componentRect = findComponentRect(
|
|
166
|
-
// iframe,
|
|
167
|
-
// (nextElement.getAttribute("data-component-end") ||
|
|
168
|
-
// nextElement.getAttribute("data-dropzone"))!,
|
|
169
|
-
// );
|
|
170
|
-
// if (!componentRect) continue;
|
|
171
|
-
// const position = getPositionFromRect(
|
|
172
|
-
// componentRect.rect,
|
|
173
|
-
// pageViewContext.zoom,
|
|
174
|
-
// orientation,
|
|
175
|
-
// );
|
|
176
|
-
// index++;
|
|
177
|
-
// zones.push({
|
|
178
|
-
// placeholder,
|
|
179
|
-
// position,
|
|
180
|
-
// index,
|
|
181
|
-
// anchor: orientation === "horizontal" ? "right" : "bottom",
|
|
182
|
-
// element: componentRect.elements[componentRect.elements.length - 1]!,
|
|
183
|
-
// });
|
|
184
|
-
// } else if (nextElement.getAttribute("data-dropzone")) {
|
|
185
|
-
// const rect = nextElement.getBoundingClientRect();
|
|
186
|
-
// const position = getPositionFromRect(rect, pageViewContext.zoom);
|
|
187
|
-
// index++;
|
|
188
|
-
// zones.push({
|
|
189
|
-
// placeholder,
|
|
190
|
-
// position,
|
|
191
|
-
// index,
|
|
192
|
-
// anchor: orientation === "horizontal" ? "left" : "top",
|
|
193
|
-
// element: nextElement,
|
|
194
|
-
// });
|
|
195
|
-
// }
|
|
196
|
-
// }
|
|
197
|
-
// }
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
return zones.map((zone, index) => {
|
|
201
|
-
const x = Math.min(
|
|
202
|
-
pageViewContext.viewport.width - 20,
|
|
203
|
-
Math.max(20, zone.position.x * (scale || 1)),
|
|
204
|
-
);
|
|
205
|
-
const y = Math.min(
|
|
206
|
-
scrollHeight - 20,
|
|
207
|
-
Math.max(20 - pageViewContext.scroll, zone.position.y * (scale || 1)),
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
return (
|
|
211
|
-
<PlaceholderDropZone
|
|
212
|
-
key={index}
|
|
213
|
-
placeholder={zone.placeholder}
|
|
214
|
-
spotPosition={{
|
|
215
|
-
x,
|
|
216
|
-
y,
|
|
217
|
-
}}
|
|
218
|
-
index={zone.index}
|
|
219
|
-
size={size}
|
|
220
|
-
spotPositionElement={zone.element}
|
|
221
|
-
spotPositionAnchor={zone.anchor}
|
|
222
|
-
parentName={zone.placeholder.parentComponent?.name}
|
|
223
|
-
description={zone.description || undefined}
|
|
224
|
-
/>
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function getPreviousElement(element: Element): Element | null {
|
|
230
|
-
let prev = element.previousElementSibling;
|
|
231
|
-
while (prev && prev.tagName === "SCRIPT") {
|
|
232
|
-
prev = prev.previousElementSibling;
|
|
233
|
-
}
|
|
234
|
-
return prev;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function getNextElement(element: Element): Element | null {
|
|
238
|
-
let next = element.nextElementSibling;
|
|
239
|
-
|
|
240
|
-
while (next && next.tagName === "SCRIPT") {
|
|
241
|
-
next = next.nextElementSibling;
|
|
242
|
-
}
|
|
243
|
-
return next;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function getPositionFromRect(
|
|
247
|
-
rect: { x: number; y: number; width: number; height: number },
|
|
248
|
-
zoom: number,
|
|
249
|
-
orientation?: string | null,
|
|
250
|
-
) {
|
|
251
|
-
const position =
|
|
252
|
-
orientation === "horizontal"
|
|
253
|
-
? {
|
|
254
|
-
x: rect.x + rect.width * zoom,
|
|
255
|
-
y: (rect.y + rect.height / 2) * zoom,
|
|
256
|
-
}
|
|
257
|
-
: {
|
|
258
|
-
x: (rect.x + rect.width / 2) * zoom,
|
|
259
|
-
y: rect.y + rect.height * zoom,
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
return position;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function detectOrientation(
|
|
266
|
-
placeholderElement: Element,
|
|
267
|
-
components: Component[],
|
|
268
|
-
): "horizontal" | "vertical" {
|
|
269
|
-
// Check parent element for flex/grid direction
|
|
270
|
-
const parentElement = placeholderElement.parentElement;
|
|
271
|
-
if (parentElement) {
|
|
272
|
-
const parentStyle = window.getComputedStyle(parentElement);
|
|
273
|
-
const display = parentStyle.getPropertyValue("display");
|
|
274
|
-
|
|
275
|
-
// Check for flex direction
|
|
276
|
-
if (display === "flex" || display === "inline-flex") {
|
|
277
|
-
const flexDirection = parentStyle.getPropertyValue("flex-direction");
|
|
278
|
-
if (flexDirection === "row" || "row-reverse") {
|
|
279
|
-
return "horizontal";
|
|
280
|
-
}
|
|
281
|
-
if (flexDirection === "column" || "column-reverse") {
|
|
282
|
-
return "vertical";
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Check for grid layout
|
|
287
|
-
if (display === "grid" || display === "inline-grid") {
|
|
288
|
-
const gridAutoFlow = parentStyle.getPropertyValue("grid-auto-flow");
|
|
289
|
-
if (gridAutoFlow.includes("column")) {
|
|
290
|
-
return "horizontal";
|
|
291
|
-
}
|
|
292
|
-
if (gridAutoFlow.includes("row")) {
|
|
293
|
-
return "vertical";
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Analyze sibling positions if available
|
|
299
|
-
if (components.length > 1) {
|
|
300
|
-
const prevRect = components[0]?.firstDOMElement?.getBoundingClientRect();
|
|
301
|
-
const nextRect = components[1]?.firstDOMElement?.getBoundingClientRect();
|
|
302
|
-
|
|
303
|
-
if (!prevRect || !nextRect) return "horizontal";
|
|
304
|
-
|
|
305
|
-
// Compare the position differences
|
|
306
|
-
const horizontalDiff = Math.abs(nextRect.x - prevRect.x);
|
|
307
|
-
const verticalDiff = Math.abs(nextRect.y - prevRect.y);
|
|
308
|
-
|
|
309
|
-
// If horizontal difference is greater, it's likely a horizontal layout
|
|
310
|
-
return horizontalDiff > verticalDiff ? "horizontal" : "vertical";
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Default to vertical if we can't determine
|
|
314
|
-
return "vertical";
|
|
315
|
-
}
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useEditContext,
|
|
3
|
-
useModifiedFieldsContext,
|
|
4
|
-
} from "../client/editContext";
|
|
5
|
-
import { findFieldElement } from "../utils";
|
|
6
|
-
import { SuggestedEdit } from "../../types";
|
|
7
|
-
import { useState } from "react";
|
|
8
|
-
import { useEffect } from "react";
|
|
9
|
-
import { classNames } from "primereact/utils";
|
|
10
|
-
import { UserRoundPen } from "lucide-react";
|
|
11
|
-
import * as DiffLib from "diff";
|
|
12
|
-
|
|
13
|
-
export function SuggestionHighlighting({
|
|
14
|
-
suggestion,
|
|
15
|
-
scale,
|
|
16
|
-
iframe,
|
|
17
|
-
}: {
|
|
18
|
-
suggestion: SuggestedEdit;
|
|
19
|
-
scale: number;
|
|
20
|
-
iframe: HTMLIFrameElement;
|
|
21
|
-
}) {
|
|
22
|
-
const editContext = useEditContext();
|
|
23
|
-
const modifiedFields = useModifiedFieldsContext();
|
|
24
|
-
const [ranges, setRanges] = useState<Array<[number, number]>>([]);
|
|
25
|
-
const [textContent, setTextContent] = useState<string>("");
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
const findRanges = async () => {
|
|
29
|
-
if (!editContext) return;
|
|
30
|
-
|
|
31
|
-
const field = await editContext.itemsRepository.getField({
|
|
32
|
-
item: {
|
|
33
|
-
id: suggestion.itemId,
|
|
34
|
-
language: suggestion.mainItemLanguage,
|
|
35
|
-
version: suggestion.mainItemVersion,
|
|
36
|
-
},
|
|
37
|
-
fieldId: suggestion.fieldId,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const modifiedField = modifiedFields?.modifiedFields.find(
|
|
41
|
-
(x) =>
|
|
42
|
-
x.fieldId === field?.id &&
|
|
43
|
-
x.item.id === suggestion.itemId &&
|
|
44
|
-
x.item.language === suggestion.mainItemLanguage &&
|
|
45
|
-
x.item.version === suggestion.mainItemVersion,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// Calculate the actual differences between oldValue and newValue
|
|
49
|
-
const oldValue = suggestion.oldValue || field?.rawValue || "";
|
|
50
|
-
const newValue = modifiedField?.value || suggestion.newValue || "";
|
|
51
|
-
|
|
52
|
-
// If values are identical, no need to highlight
|
|
53
|
-
if (oldValue === newValue) {
|
|
54
|
-
setRanges([]);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Save oldValue for use in the component
|
|
59
|
-
setTextContent(oldValue);
|
|
60
|
-
|
|
61
|
-
// Use the diff library to find the changed parts - using diffChars for more precise matching
|
|
62
|
-
const diffResult = DiffLib.diffChars(oldValue, newValue);
|
|
63
|
-
|
|
64
|
-
const changeRanges: Array<[number, number]> = [];
|
|
65
|
-
let positionInOld = 0;
|
|
66
|
-
|
|
67
|
-
// Process the diff result to find all change ranges
|
|
68
|
-
for (const part of diffResult) {
|
|
69
|
-
if (part.removed) {
|
|
70
|
-
// If a part is removed, highlight it in the original text
|
|
71
|
-
changeRanges.push([positionInOld, positionInOld + part.value.length]);
|
|
72
|
-
positionInOld += part.value.length;
|
|
73
|
-
} else if (part.added) {
|
|
74
|
-
// For added parts, mark the insertion point
|
|
75
|
-
if (changeRanges.length > 0) {
|
|
76
|
-
const lastRange = changeRanges[changeRanges.length - 1];
|
|
77
|
-
if (lastRange && lastRange[1] === positionInOld) {
|
|
78
|
-
// If this addition comes right after a removal, the previous range already covers the position
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// Mark the insertion point for new content
|
|
83
|
-
changeRanges.push([positionInOld, positionInOld]);
|
|
84
|
-
} else {
|
|
85
|
-
// Unchanged part, just advance the position
|
|
86
|
-
positionInOld += part.value.length;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Merge adjacent or overlapping ranges
|
|
91
|
-
const mergedRanges: Array<[number, number]> = [];
|
|
92
|
-
|
|
93
|
-
if (changeRanges.length > 0) {
|
|
94
|
-
changeRanges.sort((a, b) => a[0] - b[0]);
|
|
95
|
-
|
|
96
|
-
// Start with the first range
|
|
97
|
-
const firstRange = changeRanges[0];
|
|
98
|
-
if (!firstRange) {
|
|
99
|
-
setRanges([]);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
let currentRange: [number, number] = [...firstRange];
|
|
104
|
-
|
|
105
|
-
// Process the rest of the ranges
|
|
106
|
-
for (let i = 1; i < changeRanges.length; i++) {
|
|
107
|
-
const nextRange = changeRanges[i];
|
|
108
|
-
|
|
109
|
-
// Skip undefined ranges
|
|
110
|
-
if (!nextRange) continue;
|
|
111
|
-
|
|
112
|
-
// If the next range starts very close to the end of the current range, merge them
|
|
113
|
-
if (nextRange[0] <= currentRange[1] + 3) {
|
|
114
|
-
// Allow slightly larger gaps (3 chars) for better highlighting
|
|
115
|
-
// Extend the current range
|
|
116
|
-
currentRange[1] = Math.max(currentRange[1], nextRange[1]);
|
|
117
|
-
} else {
|
|
118
|
-
// Save the current range and start a new one
|
|
119
|
-
mergedRanges.push([currentRange[0], currentRange[1]]);
|
|
120
|
-
currentRange = [...nextRange];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Add the last range
|
|
125
|
-
mergedRanges.push([currentRange[0], currentRange[1]]);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Set ranges to highlight the changed parts
|
|
129
|
-
setRanges(mergedRanges);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
findRanges();
|
|
133
|
-
}, [editContext, modifiedFields?.modifiedFields, suggestion]);
|
|
134
|
-
|
|
135
|
-
if (!editContext) return null;
|
|
136
|
-
|
|
137
|
-
if (!suggestion.fieldId) return null;
|
|
138
|
-
|
|
139
|
-
const fieldElement = findFieldElement(iframe, {
|
|
140
|
-
item: {
|
|
141
|
-
id: suggestion.itemId,
|
|
142
|
-
language: suggestion.mainItemLanguage,
|
|
143
|
-
version: suggestion.mainItemVersion,
|
|
144
|
-
},
|
|
145
|
-
fieldId: suggestion.fieldId,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
if (!fieldElement) return null;
|
|
149
|
-
|
|
150
|
-
// Process each range and collect all DOM rectangles
|
|
151
|
-
const allRects: Array<DOMRect> = [];
|
|
152
|
-
|
|
153
|
-
ranges.forEach((range) => {
|
|
154
|
-
if (range[0] !== undefined && range[1] !== undefined) {
|
|
155
|
-
// For insertion points (zero-length ranges), expand to include at least one character
|
|
156
|
-
// to make it visible
|
|
157
|
-
const start = range[0];
|
|
158
|
-
const end =
|
|
159
|
-
range[0] === range[1]
|
|
160
|
-
? Math.min(range[0] + 1, textContent.length)
|
|
161
|
-
: range[1];
|
|
162
|
-
|
|
163
|
-
if (start < end) {
|
|
164
|
-
const startData = getTextNodeAtPosition(fieldElement, start);
|
|
165
|
-
const endData = getTextNodeAtPosition(fieldElement, end);
|
|
166
|
-
|
|
167
|
-
if (startData && endData) {
|
|
168
|
-
try {
|
|
169
|
-
const textRange = document.createRange();
|
|
170
|
-
textRange.setStart(startData.node, startData.offset);
|
|
171
|
-
textRange.setEnd(endData.node, endData.offset);
|
|
172
|
-
|
|
173
|
-
const rangeRects = textRange.getClientRects();
|
|
174
|
-
// Convert DOMRectList to Array
|
|
175
|
-
for (let i = 0; i < rangeRects.length; i++) {
|
|
176
|
-
const rect = rangeRects[i];
|
|
177
|
-
if (rect) {
|
|
178
|
-
allRects.push(rect);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
} catch (e) {
|
|
182
|
-
console.error("Error creating range", e);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// If no rects were found, fall back to highlighting the entire field
|
|
190
|
-
if (allRects.length === 0 && ranges.length > 0) {
|
|
191
|
-
const fallbackRect = fieldElement.getBoundingClientRect();
|
|
192
|
-
allRects.push(fallbackRect);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const iframeRect = iframe.getBoundingClientRect();
|
|
196
|
-
|
|
197
|
-
return (
|
|
198
|
-
<>
|
|
199
|
-
{allRects.map((rect, index) => (
|
|
200
|
-
<div
|
|
201
|
-
key={index}
|
|
202
|
-
style={{
|
|
203
|
-
position: "absolute",
|
|
204
|
-
top: rect.top * scale,
|
|
205
|
-
left: rect.left * scale,
|
|
206
|
-
width: rect.width * scale,
|
|
207
|
-
height: rect.height * scale,
|
|
208
|
-
pointerEvents: "none",
|
|
209
|
-
}}
|
|
210
|
-
>
|
|
211
|
-
{index === 0 && (
|
|
212
|
-
<div
|
|
213
|
-
className={classNames(
|
|
214
|
-
"pointer-events-auto absolute h-5 w-5 cursor-pointer",
|
|
215
|
-
rect.top * scale < 18 ? "top-0" : "top-[-18px]",
|
|
216
|
-
(rect.left + rect.width) * scale > iframeRect.width - 18
|
|
217
|
-
? "right-0"
|
|
218
|
-
: "right-[-18px]",
|
|
219
|
-
)}
|
|
220
|
-
onClick={() => {
|
|
221
|
-
editContext.select([suggestion.itemId]);
|
|
222
|
-
editContext.setFocusedField(
|
|
223
|
-
{
|
|
224
|
-
item: {
|
|
225
|
-
id: suggestion.itemId,
|
|
226
|
-
language: suggestion.mainItemLanguage,
|
|
227
|
-
version: suggestion.mainItemVersion,
|
|
228
|
-
},
|
|
229
|
-
fieldId: suggestion.fieldId,
|
|
230
|
-
},
|
|
231
|
-
true,
|
|
232
|
-
);
|
|
233
|
-
}}
|
|
234
|
-
>
|
|
235
|
-
<UserRoundPen
|
|
236
|
-
className="rounded-full bg-emerald-400/70 p-1 text-white"
|
|
237
|
-
size={20}
|
|
238
|
-
/>
|
|
239
|
-
</div>
|
|
240
|
-
)}
|
|
241
|
-
{/* <div
|
|
242
|
-
className="bg-emerald-400/30"
|
|
243
|
-
style={{
|
|
244
|
-
width: "100%",
|
|
245
|
-
height: "100%",
|
|
246
|
-
}}
|
|
247
|
-
></div> */}
|
|
248
|
-
</div>
|
|
249
|
-
))}
|
|
250
|
-
</>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Improved function to find text node at a given character position
|
|
255
|
-
function getTextNodeAtPosition(
|
|
256
|
-
root: Node,
|
|
257
|
-
targetOffset: number,
|
|
258
|
-
): { node: Text; offset: number } | null {
|
|
259
|
-
// Handle edge cases
|
|
260
|
-
if (targetOffset < 0) return null;
|
|
261
|
-
|
|
262
|
-
// Get all text nodes in order
|
|
263
|
-
const textNodes: Text[] = [];
|
|
264
|
-
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
|
|
265
|
-
|
|
266
|
-
let node: Text | null;
|
|
267
|
-
while ((node = walker.nextNode() as Text | null)) {
|
|
268
|
-
if (node) textNodes.push(node);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
let currentOffset = 0;
|
|
272
|
-
// Walk through all text nodes to find the one containing our target position
|
|
273
|
-
for (const node of textNodes) {
|
|
274
|
-
const nodeLength = node.textContent?.length || 0;
|
|
275
|
-
|
|
276
|
-
// If this node contains our target position
|
|
277
|
-
if (currentOffset + nodeLength >= targetOffset) {
|
|
278
|
-
return {
|
|
279
|
-
node: node,
|
|
280
|
-
offset: targetOffset - currentOffset,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
currentOffset += nodeLength;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// If we've gone through all nodes and haven't found the position
|
|
288
|
-
// Return the last position in the last text node
|
|
289
|
-
if (textNodes.length > 0) {
|
|
290
|
-
const lastNode = textNodes[textNodes.length - 1];
|
|
291
|
-
if (lastNode) {
|
|
292
|
-
return {
|
|
293
|
-
node: lastNode,
|
|
294
|
-
offset: lastNode.textContent?.length || 0,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { useEditContext } from "../client/editContext";
|
|
3
|
-
|
|
4
|
-
import { SuggestionHighlighting } from "./SuggestionHighlighting";
|
|
5
|
-
|
|
6
|
-
import { SuggestedEdit } from "../../types";
|
|
7
|
-
|
|
8
|
-
export function SuggestionHighlightings({
|
|
9
|
-
scale,
|
|
10
|
-
iframe,
|
|
11
|
-
}: {
|
|
12
|
-
scale: number;
|
|
13
|
-
iframe: HTMLIFrameElement;
|
|
14
|
-
}) {
|
|
15
|
-
const editContext = useEditContext();
|
|
16
|
-
|
|
17
|
-
const [suggestions, setSuggestions] = useState<SuggestedEdit[]>([]);
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
setSuggestions(
|
|
21
|
-
editContext?.suggestedEdits.filter((x) => x.status === "Pending") || [],
|
|
22
|
-
);
|
|
23
|
-
}, [editContext?.comments, editContext?.suggestedEdits]);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<>
|
|
27
|
-
{editContext?.showSuggestedEdits &&
|
|
28
|
-
suggestions
|
|
29
|
-
.filter((x) => x.status !== "approved" && x.status !== "rejected")
|
|
30
|
-
.map((suggestion) => (
|
|
31
|
-
<SuggestionHighlighting
|
|
32
|
-
iframe={iframe}
|
|
33
|
-
scale={scale}
|
|
34
|
-
key={suggestion.id}
|
|
35
|
-
suggestion={suggestion}
|
|
36
|
-
/>
|
|
37
|
-
))}
|
|
38
|
-
</>
|
|
39
|
-
);
|
|
40
|
-
}
|