@alpaca-editor/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +3 -0
- package/eslint.config.mjs +4 -0
- package/images/bg-shape-black.webp +0 -0
- package/package.json +52 -0
- package/src/client-components/api.ts +6 -0
- package/src/client-components/index.ts +19 -0
- package/src/components/ActionButton.tsx +43 -0
- package/src/components/Error.tsx +57 -0
- package/src/config/config.tsx +737 -0
- package/src/config/types.ts +263 -0
- package/src/editor/ComponentInfo.tsx +77 -0
- package/src/editor/ConfirmationDialog.tsx +103 -0
- package/src/editor/ContentTree.tsx +654 -0
- package/src/editor/ContextMenu.tsx +155 -0
- package/src/editor/Editor.tsx +91 -0
- package/src/editor/EditorWarning.tsx +34 -0
- package/src/editor/EditorWarnings.tsx +33 -0
- package/src/editor/FieldEditorPopup.tsx +65 -0
- package/src/editor/FieldHistory.tsx +74 -0
- package/src/editor/FieldList.tsx +190 -0
- package/src/editor/FieldListField.tsx +387 -0
- package/src/editor/FieldListFieldWithFallbacks.tsx +211 -0
- package/src/editor/FloatingToolbar.tsx +163 -0
- package/src/editor/ImageEditor.tsx +129 -0
- package/src/editor/InsertMenu.tsx +332 -0
- package/src/editor/ItemInfo.tsx +90 -0
- package/src/editor/LinkEditorDialog.tsx +192 -0
- package/src/editor/MainLayout.tsx +94 -0
- package/src/editor/NewEditorClient.tsx +11 -0
- package/src/editor/PictureCropper.tsx +505 -0
- package/src/editor/PictureEditor.tsx +206 -0
- package/src/editor/PictureEditorDialog.tsx +381 -0
- package/src/editor/PublishDialog.ignore +74 -0
- package/src/editor/ScrollingContentTree.tsx +47 -0
- package/src/editor/Terminal.tsx +215 -0
- package/src/editor/Titlebar.tsx +23 -0
- package/src/editor/ai/AiPopup.tsx +59 -0
- package/src/editor/ai/AiResponseMessage.tsx +82 -0
- package/src/editor/ai/AiTerminal.tsx +450 -0
- package/src/editor/ai/AiToolCall.tsx +46 -0
- package/src/editor/ai/EditorAiTerminal.tsx +20 -0
- package/src/editor/ai/editorAiContext.ts +18 -0
- package/src/editor/client/DialogContext.tsx +49 -0
- package/src/editor/client/EditorClient.tsx +1831 -0
- package/src/editor/client/GenericDialog.tsx +50 -0
- package/src/editor/client/editContext.ts +330 -0
- package/src/editor/client/helpers.ts +44 -0
- package/src/editor/client/itemsRepository.ts +391 -0
- package/src/editor/client/operations.ts +610 -0
- package/src/editor/client/pageModelBuilder.ts +182 -0
- package/src/editor/commands/commands.ts +23 -0
- package/src/editor/commands/componentCommands.tsx +408 -0
- package/src/editor/commands/createVersionCommand.ts +33 -0
- package/src/editor/commands/deleteVersionCommand.ts +71 -0
- package/src/editor/commands/itemCommands.tsx +186 -0
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -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 +183 -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 +114 -0
- package/src/editor/control-center/ControlCenterMenu.tsx +71 -0
- package/src/editor/control-center/IndexOverview.tsx +50 -0
- package/src/editor/control-center/IndexSettings.tsx +266 -0
- package/src/editor/control-center/Status.tsx +7 -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 +15 -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 +75 -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 +112 -0
- package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
- package/src/editor/field-types/MultiLineText.tsx +63 -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 +108 -0
- package/src/editor/field-types/SingleLineText.tsx +150 -0
- package/src/editor/field-types/TreeListEditor.tsx +261 -0
- package/src/editor/fieldTypes.ts +140 -0
- package/src/editor/media-selector/AiImageSearch.tsx +186 -0
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +95 -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/menubar/ActionsMenu.tsx +47 -0
- package/src/editor/menubar/ActiveUsers.tsx +17 -0
- package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
- package/src/editor/menubar/BrowseHistory.tsx +37 -0
- package/src/editor/menubar/ItemLanguageVersion.tsx +52 -0
- package/src/editor/menubar/LanguageSelector.tsx +152 -0
- package/src/editor/menubar/Menu.tsx +83 -0
- package/src/editor/menubar/NavButtons.tsx +74 -0
- package/src/editor/menubar/PageSelector.tsx +139 -0
- package/src/editor/menubar/PageViewerControls.tsx +99 -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 +143 -0
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +287 -0
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +44 -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 +263 -0
- package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
- package/src/editor/page-editor-chrome/InlineEditor.tsx +147 -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 +119 -0
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +154 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +171 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +233 -0
- package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
- package/src/editor/page-viewer/EditorForm.tsx +247 -0
- package/src/editor/page-viewer/MiniMap.tsx +351 -0
- package/src/editor/page-viewer/PageViewer.tsx +127 -0
- package/src/editor/page-viewer/PageViewerFrame.tsx +1030 -0
- package/src/editor/page-viewer/pageViewContext.ts +186 -0
- package/src/editor/pageModel.ts +191 -0
- package/src/editor/picture-shared.tsx +53 -0
- package/src/editor/reviews/Comment.tsx +265 -0
- package/src/editor/reviews/Comments.tsx +50 -0
- package/src/editor/reviews/PreviewInfo.tsx +35 -0
- package/src/editor/reviews/Reviews.tsx +280 -0
- package/src/editor/reviews/reviewCommands.tsx +47 -0
- package/src/editor/reviews/useReviews.tsx +70 -0
- package/src/editor/services/aiService.ts +155 -0
- package/src/editor/services/componentDesignerService.ts +151 -0
- package/src/editor/services/contentService.ts +159 -0
- package/src/editor/services/editService.ts +462 -0
- package/src/editor/services/indexService.ts +24 -0
- package/src/editor/services/reviewsService.ts +45 -0
- package/src/editor/services/serviceHelper.ts +95 -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 +146 -0
- package/src/editor/sidebar/ComponentTree.tsx +512 -0
- package/src/editor/sidebar/ComponentTree2.tsxx +490 -0
- package/src/editor/sidebar/Debug.tsx +105 -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 +95 -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 +150 -0
- package/src/editor/sidebar/Translations.tsx +276 -0
- package/src/editor/sidebar/Validation.tsx +102 -0
- package/src/editor/sidebar/ViewSelector.tsx +49 -0
- package/src/editor/sidebar/Workbox.tsx +209 -0
- package/src/editor/ui/CenteredMessage.tsx +7 -0
- package/src/editor/ui/CopyToClipboardButton.tsx +23 -0
- package/src/editor/ui/DialogButtons.tsx +11 -0
- package/src/editor/ui/Icons.tsx +585 -0
- package/src/editor/ui/ItemNameDialog.tsx +94 -0
- package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
- package/src/editor/ui/ItemSearch.tsx +173 -0
- package/src/editor/ui/PerfectTree.tsx +550 -0
- package/src/editor/ui/Section.tsx +35 -0
- package/src/editor/ui/SimpleIconButton.tsx +43 -0
- package/src/editor/ui/SimpleMenu.tsx +48 -0
- package/src/editor/ui/SimpleTable.tsx +63 -0
- package/src/editor/ui/SimpleTabs.tsx +55 -0
- package/src/editor/ui/SimpleToolbar.tsx +7 -0
- package/src/editor/ui/Spinner.tsx +7 -0
- package/src/editor/ui/Splitter.tsx +247 -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 +435 -0
- package/src/editor/views/CompareView.tsx +256 -0
- package/src/editor/views/EditView.tsx +27 -0
- package/src/editor/views/ItemEditor.tsx +58 -0
- package/src/editor/views/SingleEditView.tsx +44 -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/index.ts +7 -0
- package/src/page-wizard/PageWizard.tsx +163 -0
- package/src/page-wizard/SelectWizard.tsx +109 -0
- package/src/page-wizard/WizardSteps.tsx +207 -0
- package/src/page-wizard/service.ts +35 -0
- package/src/page-wizard/startPageWizardCommand.ts +27 -0
- package/src/page-wizard/steps/BuildPageStep.tsx +266 -0
- package/src/page-wizard/steps/CollectStep.tsx +233 -0
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +443 -0
- package/src/page-wizard/steps/Components.tsx +193 -0
- package/src/page-wizard/steps/CreatePage.tsx +285 -0
- package/src/page-wizard/steps/CreatePageAndLayoutStep.tsx +384 -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 +32 -0
- package/src/page-wizard/steps/ImagesStep.tsx +318 -0
- package/src/page-wizard/steps/LayoutStep.tsx +228 -0
- package/src/page-wizard/steps/SelectStep.tsx +256 -0
- package/src/page-wizard/steps/schema.ts +180 -0
- package/src/page-wizard/steps/usePageCreator.ts +279 -0
- package/src/splash-screen/NewPage.tsx +232 -0
- package/src/splash-screen/SectionHeadline.tsx +21 -0
- package/src/splash-screen/SplashScreen.tsx +156 -0
- package/src/tour/Tour.tsx +558 -0
- package/src/tour/default-tour.tsx +300 -0
- package/src/tour/preview-tour.tsx +127 -0
- package/src/types.ts +302 -0
- package/styles.css +476 -0
- package/tsconfig.build.json +21 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useEditContext,
|
|
3
|
+
useModifiedFieldsContext,
|
|
4
|
+
} from "../client/editContext";
|
|
5
|
+
import { findFieldElement } from "../utils";
|
|
6
|
+
import { Comment } from "../../types";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { useEffect } from "react";
|
|
9
|
+
import { classNames } from "primereact/utils";
|
|
10
|
+
import { CommentIcon } from "../ui/Icons";
|
|
11
|
+
|
|
12
|
+
export function CommentHighlighting({
|
|
13
|
+
comment,
|
|
14
|
+
scale,
|
|
15
|
+
iframe,
|
|
16
|
+
}: {
|
|
17
|
+
comment: Comment;
|
|
18
|
+
scale: number;
|
|
19
|
+
iframe: HTMLIFrameElement;
|
|
20
|
+
}) {
|
|
21
|
+
const editContext = useEditContext();
|
|
22
|
+
const modifiedFields = useModifiedFieldsContext();
|
|
23
|
+
|
|
24
|
+
const [range, setRange] = useState<number[]>([
|
|
25
|
+
comment.rangeStart || 0,
|
|
26
|
+
comment.rangeEnd || 0,
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const findRange = async () => {
|
|
31
|
+
if (!editContext) return;
|
|
32
|
+
if (
|
|
33
|
+
comment.fieldValue &&
|
|
34
|
+
comment.fieldId &&
|
|
35
|
+
comment.rangeStart !== undefined &&
|
|
36
|
+
comment.rangeEnd !== undefined
|
|
37
|
+
) {
|
|
38
|
+
const field = await editContext.itemsRepository.getField({
|
|
39
|
+
item: {
|
|
40
|
+
id: comment.itemId,
|
|
41
|
+
language: comment.language,
|
|
42
|
+
version: comment.version,
|
|
43
|
+
},
|
|
44
|
+
fieldId: comment.fieldId,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const modifiedField = modifiedFields?.modifiedFields.find(
|
|
48
|
+
(x) =>
|
|
49
|
+
x.fieldId === field?.id &&
|
|
50
|
+
x.item.id === comment.itemId &&
|
|
51
|
+
x.item.language === comment.language &&
|
|
52
|
+
x.item.version === comment.version
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const mapping = computeMapping(
|
|
56
|
+
modifiedField?.value || field?.rawValue || "",
|
|
57
|
+
comment.fieldValue
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const mappedRange = [
|
|
61
|
+
mapping[comment.rangeStart],
|
|
62
|
+
mapping[comment.rangeEnd],
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
if (mappedRange[0] !== undefined && mappedRange[1] !== undefined) {
|
|
66
|
+
setRange(mappedRange as number[]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
findRange();
|
|
72
|
+
}, [comment.fieldValue, modifiedFields?.modifiedFields]);
|
|
73
|
+
|
|
74
|
+
if (!editContext) return null;
|
|
75
|
+
|
|
76
|
+
if (!comment.fieldId) return null;
|
|
77
|
+
|
|
78
|
+
const fieldElement = findFieldElement(iframe, {
|
|
79
|
+
item: {
|
|
80
|
+
id: comment.itemId,
|
|
81
|
+
|
|
82
|
+
language: comment.language,
|
|
83
|
+
version: comment.version,
|
|
84
|
+
},
|
|
85
|
+
fieldId: comment.fieldId,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (!fieldElement) return null;
|
|
89
|
+
|
|
90
|
+
let rects: DOMRectList | null = null;
|
|
91
|
+
|
|
92
|
+
if (range[0] !== undefined && range[1] !== undefined) {
|
|
93
|
+
const startData = getTextNodeAtOffset(fieldElement, range[0]);
|
|
94
|
+
const endData = getTextNodeAtOffset(fieldElement, range[1]);
|
|
95
|
+
|
|
96
|
+
if (startData && endData) {
|
|
97
|
+
const textRange = document.createRange();
|
|
98
|
+
textRange.setStart(startData.node, startData.offset);
|
|
99
|
+
textRange.setEnd(endData.node, endData.offset);
|
|
100
|
+
rects = textRange.getClientRects();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!rects || rects.length === 0) {
|
|
105
|
+
const fallbackRect = fieldElement.getBoundingClientRect();
|
|
106
|
+
rects = {
|
|
107
|
+
length: 1,
|
|
108
|
+
0: fallbackRect,
|
|
109
|
+
item: (index: number) => (index === 0 ? fallbackRect : null),
|
|
110
|
+
[Symbol.iterator]: function* () {
|
|
111
|
+
yield fallbackRect;
|
|
112
|
+
},
|
|
113
|
+
} as DOMRectList;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const iframeRect = iframe.getBoundingClientRect();
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<>
|
|
120
|
+
{Array.from(rects).map((rect, index) => (
|
|
121
|
+
<div
|
|
122
|
+
key={index}
|
|
123
|
+
style={{
|
|
124
|
+
position: "absolute",
|
|
125
|
+
top: rect.top * scale,
|
|
126
|
+
left: rect.left * scale,
|
|
127
|
+
width: rect.width * scale,
|
|
128
|
+
height: rect.height * scale,
|
|
129
|
+
pointerEvents: "none",
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
{index === 0 && (
|
|
133
|
+
<div
|
|
134
|
+
className={classNames(
|
|
135
|
+
"absolute w-5 h-5 cursor-pointer pointer-events-auto ",
|
|
136
|
+
rect.top * scale < 18 ? "top-0" : "top-[-18px]",
|
|
137
|
+
(rect.left + rect.width) * scale > iframeRect.width - 18
|
|
138
|
+
? "right-0"
|
|
139
|
+
: "right-[-18px]"
|
|
140
|
+
)}
|
|
141
|
+
onClick={() => {
|
|
142
|
+
editContext.switchView("reviews");
|
|
143
|
+
editContext?.select([comment.itemId]);
|
|
144
|
+
editContext?.setSelectedComment(comment);
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
<CommentIcon className="text-blue-500 hover:text-blue-600 " />
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
<div
|
|
151
|
+
className="opacity-45"
|
|
152
|
+
style={{
|
|
153
|
+
width: "100%",
|
|
154
|
+
height: "100%",
|
|
155
|
+
backgroundColor: comment.isResolved
|
|
156
|
+
? "rgba(0, 255, 0, 0.45)"
|
|
157
|
+
: "rgba(255, 0, 0, 0.45)",
|
|
158
|
+
}}
|
|
159
|
+
></div>
|
|
160
|
+
</div>
|
|
161
|
+
))}
|
|
162
|
+
</>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function getTextNodeAtOffset(
|
|
167
|
+
root: Node,
|
|
168
|
+
|
|
169
|
+
offset: number
|
|
170
|
+
): { node: Text; offset: number } | null {
|
|
171
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
|
|
172
|
+
let currentNode: Text | null;
|
|
173
|
+
while ((currentNode = walker.nextNode() as Text | null)) {
|
|
174
|
+
const nodeLength = currentNode.textContent?.length || 0;
|
|
175
|
+
if (offset <= nodeLength) {
|
|
176
|
+
return { node: currentNode, offset };
|
|
177
|
+
}
|
|
178
|
+
offset -= nodeLength;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Erzeugt ein Mapping von Positionen im modifizierten String s2 auf die entsprechenden Positionen in s1,
|
|
185
|
+
* basierend auf einer minimalen Edit-Sequenz (Levenshtein-Distance).
|
|
186
|
+
*
|
|
187
|
+
* @param s1 Originalstring
|
|
188
|
+
* @param s2 Modifizierter String
|
|
189
|
+
* @returns Ein Array, in dem mapping[j] die Position in s1 angibt, die erreicht wird, nachdem das j-te Zeichen in s2 erzeugt wurde.
|
|
190
|
+
*/
|
|
191
|
+
function computeMapping(s1: string, s2: string): number[] {
|
|
192
|
+
const n = s1.length;
|
|
193
|
+
const m = s2.length;
|
|
194
|
+
|
|
195
|
+
// 1. Aufbau der DP-Matrix und Backpointer-Matrix
|
|
196
|
+
// dp[i][j] enthält die minimale Anzahl von Operationen, um s1[0..i-1] in s2[0..j-1] zu überführen.
|
|
197
|
+
const dp: number[][] = Array.from({ length: n + 1 }, () =>
|
|
198
|
+
new Array(m + 1).fill(0)
|
|
199
|
+
);
|
|
200
|
+
const back: string[][] = Array.from({ length: n + 1 }, () =>
|
|
201
|
+
new Array(m + 1).fill("")
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
// Initialisierung: leere Präfixe
|
|
205
|
+
for (let i = 0; i <= n; i++) {
|
|
206
|
+
dp[i]![0] = i;
|
|
207
|
+
if (i > 0) {
|
|
208
|
+
back[i]![0] = "D"; // "Deletion": Zeichen aus s1 wird gelöscht.
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (let j = 0; j <= m; j++) {
|
|
212
|
+
dp[0]![j] = j;
|
|
213
|
+
if (j > 0) {
|
|
214
|
+
back[0]![j] = "I"; // "Insertion": Zeichen in s2 wurde eingefügt.
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Füllen der DP-Matrix (Wagner–Fischer-Algorithmus)
|
|
219
|
+
for (let i = 1; i <= n; i++) {
|
|
220
|
+
for (let j = 1; j <= m; j++) {
|
|
221
|
+
const cost = s1[i - 1] === s2[j - 1] ? 0 : 1;
|
|
222
|
+
|
|
223
|
+
// Drei Möglichkeiten:
|
|
224
|
+
const deletion = dp[i - 1]![j]! + 1;
|
|
225
|
+
const insertion = dp[i]![j - 1]! + 1;
|
|
226
|
+
const substitution = dp[i - 1]![j - 1]! + cost; // "M" (Match) wenn cost==0, sonst "S" (Substitution)
|
|
227
|
+
|
|
228
|
+
// Feste Tie-Breaking Reihenfolge: zuerst Deletion, dann Insertion, dann Substitution.
|
|
229
|
+
let bestVal = deletion;
|
|
230
|
+
let op = "D";
|
|
231
|
+
if (insertion < bestVal) {
|
|
232
|
+
bestVal = insertion;
|
|
233
|
+
op = "I";
|
|
234
|
+
}
|
|
235
|
+
if (substitution < bestVal) {
|
|
236
|
+
bestVal = substitution;
|
|
237
|
+
op = cost === 0 ? "M" : "S";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
dp[i]![j] = bestVal;
|
|
241
|
+
back[i]![j] = op;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 2. Rekonstruktion des Edit-Skripts per Backtracking
|
|
246
|
+
const ops: string[] = [];
|
|
247
|
+
let i = n;
|
|
248
|
+
let j = m;
|
|
249
|
+
while (i > 0 || j > 0) {
|
|
250
|
+
const op = back[i]![j]!;
|
|
251
|
+
ops.push(op);
|
|
252
|
+
if (op === "M" || op === "S") {
|
|
253
|
+
i--;
|
|
254
|
+
j--;
|
|
255
|
+
} else if (op === "D") {
|
|
256
|
+
i--;
|
|
257
|
+
} else if (op === "I") {
|
|
258
|
+
j--;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
ops.reverse(); // Jetzt liegen die Operationen in der Vorwärtsreihenfolge vor.
|
|
262
|
+
|
|
263
|
+
// 3. Simulation der Transformation von s1 zu s2 und Aufbau des Mappings.
|
|
264
|
+
// mapping[j] soll die Position in s1 angeben, nachdem das j-te Zeichen in s2 erzeugt wurde.
|
|
265
|
+
const mapping: number[] = new Array(m + 1);
|
|
266
|
+
let iPos = 0; // Aktuelle Position in s1
|
|
267
|
+
let jPos = 0; // Aktuelle Position in s2
|
|
268
|
+
mapping[jPos] = iPos; // Vor jeglicher Transformation
|
|
269
|
+
|
|
270
|
+
for (const op of ops) {
|
|
271
|
+
if (op === "M" || op === "S") {
|
|
272
|
+
// Bei Match oder Substitution wird in beiden Strings ein Zeichen verarbeitet.
|
|
273
|
+
iPos++;
|
|
274
|
+
jPos++;
|
|
275
|
+
mapping[jPos] = iPos;
|
|
276
|
+
} else if (op === "I") {
|
|
277
|
+
// Bei Insertion wird in s2 ein Zeichen eingefügt, s1 bleibt unverändert.
|
|
278
|
+
jPos++;
|
|
279
|
+
mapping[jPos] = iPos;
|
|
280
|
+
} else if (op === "D") {
|
|
281
|
+
// Bei Deletion wird in s1 ein Zeichen übersprungen.
|
|
282
|
+
iPos++;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return mapping;
|
|
287
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useEditContext } from "../client/editContext";
|
|
3
|
+
import { CommentHighlighting } from "./CommentHighlighting";
|
|
4
|
+
|
|
5
|
+
import { Comment } from "../../types";
|
|
6
|
+
|
|
7
|
+
export function CommentHighlightings({
|
|
8
|
+
scale,
|
|
9
|
+
iframe,
|
|
10
|
+
}: {
|
|
11
|
+
scale: number;
|
|
12
|
+
iframe: HTMLIFrameElement;
|
|
13
|
+
}) {
|
|
14
|
+
const editContext = useEditContext();
|
|
15
|
+
const [comments, setComments] = useState<Comment[]>([]);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setComments(editContext?.comments || []);
|
|
19
|
+
}, [editContext?.comments]);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<>
|
|
23
|
+
{comments
|
|
24
|
+
.filter((x) => !x.isResolved)
|
|
25
|
+
.map((comment) => (
|
|
26
|
+
<CommentHighlighting
|
|
27
|
+
iframe={iframe}
|
|
28
|
+
scale={scale}
|
|
29
|
+
key={comment.id}
|
|
30
|
+
comment={comment}
|
|
31
|
+
/>
|
|
32
|
+
))}
|
|
33
|
+
</>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FieldAction } from "../client/EditorClient";
|
|
2
|
+
import { useEditContext } from "../client/editContext";
|
|
3
|
+
|
|
4
|
+
export function FieldActionIndicator({ action }: { action: FieldAction }) {
|
|
5
|
+
const editContext = useEditContext();
|
|
6
|
+
if (!editContext) return null;
|
|
7
|
+
|
|
8
|
+
const pageViewContext = editContext.pageView;
|
|
9
|
+
const field = action.field;
|
|
10
|
+
const fieldElements =
|
|
11
|
+
pageViewContext.editorIframeRef.current?.contentWindow?.document.querySelectorAll(
|
|
12
|
+
`[data-fieldid="${field.fieldId}"][data-itemid="${field.item.id}"][data-language="${field.item.language}"]`
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
if (!fieldElements) return null;
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
{[...fieldElements].map((element, index) => (
|
|
19
|
+
<SingleIndicator
|
|
20
|
+
element={element}
|
|
21
|
+
key={action.field.fieldId + action.field + index}
|
|
22
|
+
/>
|
|
23
|
+
))}
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function SingleIndicator({ element }: { element: Element }) {
|
|
29
|
+
const rect = element.getBoundingClientRect();
|
|
30
|
+
|
|
31
|
+
const indicatorRect = rect;
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
className={`pointer-events-none absolute focus-shadow executing-action`}
|
|
35
|
+
style={{
|
|
36
|
+
left: indicatorRect.x,
|
|
37
|
+
top: indicatorRect.y,
|
|
38
|
+
width: indicatorRect.width,
|
|
39
|
+
height: indicatorRect.height,
|
|
40
|
+
zIndex: 800,
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FieldActionIndicator } from "./FieldActionIndicator";
|
|
2
|
+
import { useEditContext } from "../client/editContext";
|
|
3
|
+
|
|
4
|
+
export function FieldActionsIndicators() {
|
|
5
|
+
const editContext = useEditContext();
|
|
6
|
+
|
|
7
|
+
if (!editContext) return null;
|
|
8
|
+
|
|
9
|
+
const actions = editContext.activeFieldActions;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
{actions
|
|
14
|
+
.filter((x) => x.state === "running")
|
|
15
|
+
.map((action) => (
|
|
16
|
+
<FieldActionIndicator
|
|
17
|
+
action={action}
|
|
18
|
+
key={action.field.fieldId + action.field.item.id}
|
|
19
|
+
/>
|
|
20
|
+
))}
|
|
21
|
+
</>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EditedField, useEditContext } from "../client/editContext";
|
|
2
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
3
|
+
|
|
4
|
+
export function FieldEditedIndicator({
|
|
5
|
+
field,
|
|
6
|
+
scale,
|
|
7
|
+
pageViewContext,
|
|
8
|
+
scroll,
|
|
9
|
+
}: {
|
|
10
|
+
field: EditedField;
|
|
11
|
+
scale?: number;
|
|
12
|
+
pageViewContext: PageViewContext;
|
|
13
|
+
scroll?: number;
|
|
14
|
+
}) {
|
|
15
|
+
const editContext = useEditContext();
|
|
16
|
+
if (!editContext) return null;
|
|
17
|
+
|
|
18
|
+
const fieldElements =
|
|
19
|
+
pageViewContext.editorIframeRef.current?.contentWindow?.document.querySelectorAll(
|
|
20
|
+
`[data-fieldid="${field.fieldId}"][data-itemid="${field.item.id}"][data-language="${field.item.language}"][data-version="${field.item.version}"]`
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (!fieldElements) return null;
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
{[...fieldElements]
|
|
27
|
+
.filter((x) => x != editContext.inlineEditingFieldElement)
|
|
28
|
+
.map((element) => (
|
|
29
|
+
<SingleFieldEditedIndicator
|
|
30
|
+
element={element}
|
|
31
|
+
key={field.fieldId + field.item.id}
|
|
32
|
+
scale={scale}
|
|
33
|
+
scroll={scroll}
|
|
34
|
+
/>
|
|
35
|
+
))}
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function SingleFieldEditedIndicator({
|
|
41
|
+
element,
|
|
42
|
+
scale,
|
|
43
|
+
scroll,
|
|
44
|
+
}: {
|
|
45
|
+
element: Element;
|
|
46
|
+
scale?: number;
|
|
47
|
+
scroll?: number;
|
|
48
|
+
}) {
|
|
49
|
+
const rect = element.getBoundingClientRect();
|
|
50
|
+
|
|
51
|
+
const indicatorRect = rect;
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
className={`pointer-events-none absolute focus-shadow edited-field`}
|
|
55
|
+
style={{
|
|
56
|
+
left: indicatorRect.x * (scale || 1),
|
|
57
|
+
top: (indicatorRect.y + (scroll || 0)) * (scale || 1),
|
|
58
|
+
width: indicatorRect.width * (scale || 1),
|
|
59
|
+
height: indicatorRect.height * (scale || 1),
|
|
60
|
+
zIndex: 800,
|
|
61
|
+
}}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
3
|
+
import { FieldEditedIndicator } from "./FieldEditedIndicator";
|
|
4
|
+
|
|
5
|
+
export function FieldEditedIndicators({
|
|
6
|
+
scale,
|
|
7
|
+
pageViewContext,
|
|
8
|
+
scroll,
|
|
9
|
+
}: {
|
|
10
|
+
scale?: number;
|
|
11
|
+
pageViewContext: PageViewContext;
|
|
12
|
+
scroll?: number;
|
|
13
|
+
}) {
|
|
14
|
+
const editContext = useEditContext();
|
|
15
|
+
|
|
16
|
+
if (!editContext) return null;
|
|
17
|
+
|
|
18
|
+
const fields = editContext.lastEditedFields;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
{fields
|
|
23
|
+
.filter((x) => x.timestamp > Date.now() - 10000 && x.user.ai)
|
|
24
|
+
.map((field) => (
|
|
25
|
+
<FieldEditedIndicator
|
|
26
|
+
field={field}
|
|
27
|
+
key={field.fieldId + field.item.id + field.timestamp}
|
|
28
|
+
scale={scale}
|
|
29
|
+
pageViewContext={pageViewContext}
|
|
30
|
+
scroll={scroll}
|
|
31
|
+
/>
|
|
32
|
+
))}
|
|
33
|
+
</>
|
|
34
|
+
);
|
|
35
|
+
}
|