@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,263 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { EditButton, useEditContext } from "../client/editContext";
|
|
4
|
+
import { Rect, findComponentRect } from "../utils";
|
|
5
|
+
import { useThrottledCallback } from "use-debounce";
|
|
6
|
+
import { Component } from "../pageModel";
|
|
7
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
8
|
+
|
|
9
|
+
export function FrameMenu({
|
|
10
|
+
component,
|
|
11
|
+
mode,
|
|
12
|
+
pageViewContext,
|
|
13
|
+
}: {
|
|
14
|
+
component: Component;
|
|
15
|
+
mode: "edit" | "compare" | "view";
|
|
16
|
+
pageViewContext: PageViewContext;
|
|
17
|
+
}) {
|
|
18
|
+
const editContext = useEditContext();
|
|
19
|
+
const resizeObserverRef = useRef<ResizeObserver | null>(null);
|
|
20
|
+
const mutationObserverRef = useRef<MutationObserver | null>(null);
|
|
21
|
+
|
|
22
|
+
const [componentRect, setComponentRect] = useState<Rect>();
|
|
23
|
+
|
|
24
|
+
const updatePosition = () => {
|
|
25
|
+
if (!component || !editContext || !pageViewContext) return;
|
|
26
|
+
|
|
27
|
+
const iframe = pageViewContext.editorIframeRef.current;
|
|
28
|
+
|
|
29
|
+
if (!iframe) return;
|
|
30
|
+
|
|
31
|
+
const resetSelection = () => {
|
|
32
|
+
setComponentRect(undefined);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const componentRect = findComponentRect(iframe, component.id)?.rect;
|
|
36
|
+
|
|
37
|
+
if (!componentRect) {
|
|
38
|
+
resetSelection();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setComponentRect(componentRect);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const updatePositionThrottled = useThrottledCallback(updatePosition, 30);
|
|
46
|
+
|
|
47
|
+
// Effect to handle changes in the observed element
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (component) {
|
|
50
|
+
const iframe = pageViewContext!.editorIframeRef.current;
|
|
51
|
+
if (!iframe) return;
|
|
52
|
+
|
|
53
|
+
mutationObserverRef.current = new MutationObserver(() => {
|
|
54
|
+
updatePosition();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (!iframe.contentDocument) return;
|
|
58
|
+
|
|
59
|
+
mutationObserverRef.current.observe(iframe.contentDocument, {
|
|
60
|
+
childList: true, // observe direct children changes
|
|
61
|
+
subtree: true, // observe all descendants changes
|
|
62
|
+
characterData: true, // observe text changes
|
|
63
|
+
//attributes: true, // observe attribute changes (like style or class)
|
|
64
|
+
});
|
|
65
|
+
// Create a new ResizeObserver instance
|
|
66
|
+
resizeObserverRef.current = new ResizeObserver(() => {
|
|
67
|
+
updatePosition();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const scrollContainer =
|
|
71
|
+
iframe.contentWindow?.document.scrollingElement ||
|
|
72
|
+
iframe.contentWindow?.document.body;
|
|
73
|
+
|
|
74
|
+
scrollContainer?.addEventListener("scroll", updatePositionThrottled);
|
|
75
|
+
iframe.contentWindow?.addEventListener("scroll", updatePositionThrottled);
|
|
76
|
+
|
|
77
|
+
const componentRect = findComponentRect(iframe, component.id);
|
|
78
|
+
|
|
79
|
+
if (!componentRect) {
|
|
80
|
+
updatePosition();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
componentRect.elements.forEach((componentElement) => {
|
|
85
|
+
resizeObserverRef.current!.observe(componentElement);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
if (mutationObserverRef.current) {
|
|
91
|
+
mutationObserverRef.current.disconnect();
|
|
92
|
+
mutationObserverRef.current = null;
|
|
93
|
+
}
|
|
94
|
+
if (resizeObserverRef.current) {
|
|
95
|
+
resizeObserverRef.current.disconnect();
|
|
96
|
+
resizeObserverRef.current = null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}, [component]);
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
updatePosition();
|
|
104
|
+
}, 100);
|
|
105
|
+
}, [
|
|
106
|
+
pageViewContext?.scroll,
|
|
107
|
+
pageViewContext?.viewport,
|
|
108
|
+
pageViewContext?.device,
|
|
109
|
+
pageViewContext?.fullscreen,
|
|
110
|
+
pageViewContext?.zoom,
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
if (!component || !editContext) return null;
|
|
114
|
+
|
|
115
|
+
const commands = editContext.getComponentCommands([component]);
|
|
116
|
+
const isDraggable =
|
|
117
|
+
mode === "edit" &&
|
|
118
|
+
!component.layoutId &&
|
|
119
|
+
pageViewContext.page?.item.canWriteItem;
|
|
120
|
+
false;
|
|
121
|
+
|
|
122
|
+
const commandButtons = commands
|
|
123
|
+
.filter(
|
|
124
|
+
(x) =>
|
|
125
|
+
!editContext.isCommandDisabled({ command: x }) &&
|
|
126
|
+
x.visibilityScopes.indexOf("editFrame") >= 0,
|
|
127
|
+
)
|
|
128
|
+
.map((x) => ({
|
|
129
|
+
id: x.id + "_button",
|
|
130
|
+
icon: x.icon,
|
|
131
|
+
label: x.label,
|
|
132
|
+
onClick: (ev: any) => {
|
|
133
|
+
ev.stopPropagation();
|
|
134
|
+
ev.preventDefault();
|
|
135
|
+
editContext.executeCommand({
|
|
136
|
+
command: x,
|
|
137
|
+
event: ev,
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
const customButtons: EditButton[] = []; // TODO
|
|
143
|
+
let buttons = [...customButtons];
|
|
144
|
+
|
|
145
|
+
buttons = [...buttons, ...commandButtons];
|
|
146
|
+
|
|
147
|
+
function handleDragStart(event: React.DragEvent<HTMLDivElement>): void {
|
|
148
|
+
if (!component?.datasourceItem) return;
|
|
149
|
+
event.dataTransfer.setData("componentId", component.id);
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
if (!component?.datasourceItem) return;
|
|
152
|
+
editContext!.dragStart({
|
|
153
|
+
type: "component",
|
|
154
|
+
typeId: component.typeId,
|
|
155
|
+
templateId: component.datasourceItem?.templateId,
|
|
156
|
+
name: component.name,
|
|
157
|
+
component: {
|
|
158
|
+
id: component.id,
|
|
159
|
+
language: pageViewContext.page!.item.language,
|
|
160
|
+
version: pageViewContext.page!.item.version,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
}, 50);
|
|
164
|
+
|
|
165
|
+
event.stopPropagation();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function handleDragEnd(): void {
|
|
169
|
+
editContext!.dragEnd();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const isShared = component.datasourceItem?.id !== component.id;
|
|
173
|
+
const isReadonly = mode === "compare" || mode === "view";
|
|
174
|
+
const isLayout = component.layoutId;
|
|
175
|
+
|
|
176
|
+
const color = isReadonly
|
|
177
|
+
? "readonly"
|
|
178
|
+
: isShared
|
|
179
|
+
? "shared"
|
|
180
|
+
: isLayout
|
|
181
|
+
? "layout"
|
|
182
|
+
: "default";
|
|
183
|
+
|
|
184
|
+
const colorVariants = {
|
|
185
|
+
shared: "border-orange-400",
|
|
186
|
+
readonly: "border-purple-400",
|
|
187
|
+
layout: "border-purple-400",
|
|
188
|
+
default: "border-sky-400",
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const bgColorVariants = {
|
|
192
|
+
shared: "bg-orange-400",
|
|
193
|
+
readonly: "bg-purple-400",
|
|
194
|
+
layout: "bg-purple-400",
|
|
195
|
+
default: "bg-sky-400",
|
|
196
|
+
};
|
|
197
|
+
if (!componentRect) return null;
|
|
198
|
+
|
|
199
|
+
const isMultiSelected = editContext.selection.length > 1;
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<>
|
|
203
|
+
<div
|
|
204
|
+
className={`pointer-events-none absolute inset-0 border-2 ${colorVariants[color]} tour-frame-menu opacity-50 hover:opacity-100`}
|
|
205
|
+
style={{
|
|
206
|
+
left: componentRect.x,
|
|
207
|
+
top: componentRect.y,
|
|
208
|
+
width: componentRect.width,
|
|
209
|
+
height: componentRect.height,
|
|
210
|
+
zIndex: 8,
|
|
211
|
+
}}
|
|
212
|
+
data-testid="frame-menu"
|
|
213
|
+
>
|
|
214
|
+
{!isMultiSelected && (
|
|
215
|
+
<div
|
|
216
|
+
className={
|
|
217
|
+
`editframe-menu pointer-events-auto absolute z-1000 flex items-center pr-4 text-base text-white ${bgColorVariants[color]} ` +
|
|
218
|
+
(componentRect.y - 36 < 0 ? "rounded-bl-lg" : "rounded-t-lg")
|
|
219
|
+
}
|
|
220
|
+
style={{
|
|
221
|
+
right: "-2px",
|
|
222
|
+
top: componentRect.y - 36 < 0 ? "0" : undefined,
|
|
223
|
+
bottom:
|
|
224
|
+
componentRect.y - 36 >= 0
|
|
225
|
+
? componentRect.height - 2
|
|
226
|
+
: undefined,
|
|
227
|
+
zIndex: 800,
|
|
228
|
+
height: "36px",
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
<div
|
|
232
|
+
draggable={isDraggable}
|
|
233
|
+
onDragStart={handleDragStart}
|
|
234
|
+
onDragEnd={handleDragEnd}
|
|
235
|
+
className={`px-4 ${
|
|
236
|
+
isDraggable ? "cursor-move" : "cursor-default"
|
|
237
|
+
} `}
|
|
238
|
+
>
|
|
239
|
+
{component.name}
|
|
240
|
+
</div>
|
|
241
|
+
{mode === "edit" && (
|
|
242
|
+
<div className="flex items-center gap-2">
|
|
243
|
+
{buttons.map((b, i) => (
|
|
244
|
+
<div className="cursor-pointer p-1" key={i}>
|
|
245
|
+
{typeof b.icon === "string" ? (
|
|
246
|
+
<i
|
|
247
|
+
className={b.icon + " cursor-pointer"}
|
|
248
|
+
onClick={b.onClick}
|
|
249
|
+
title={b.label}
|
|
250
|
+
/>
|
|
251
|
+
) : (
|
|
252
|
+
b.icon
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
))}
|
|
256
|
+
</div>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
</>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { findComponent } from "../componentTreeHelper";
|
|
3
|
+
import { useEditContext } from "../client/editContext";
|
|
4
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
5
|
+
import { FrameMenu } from "./FrameMenu";
|
|
6
|
+
import { Component } from "../pageModel";
|
|
7
|
+
export function FrameMenus({
|
|
8
|
+
mode,
|
|
9
|
+
pageViewContext,
|
|
10
|
+
}: {
|
|
11
|
+
mode: "edit" | "compare" | "view";
|
|
12
|
+
pageViewContext: PageViewContext;
|
|
13
|
+
}) {
|
|
14
|
+
const editContext = useEditContext();
|
|
15
|
+
const selection = editContext?.selection;
|
|
16
|
+
|
|
17
|
+
const [components, setComponents] = useState<Component[]>([]);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!pageViewContext.page) return;
|
|
21
|
+
|
|
22
|
+
const comps: Component[] = selection
|
|
23
|
+
? selection
|
|
24
|
+
.map((id) =>
|
|
25
|
+
findComponent(
|
|
26
|
+
id,
|
|
27
|
+
pageViewContext.page?.rootComponent.placeholders || []
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
.filter((c): c is NonNullable<typeof c> => c !== undefined)
|
|
31
|
+
: [];
|
|
32
|
+
|
|
33
|
+
setComponents(comps);
|
|
34
|
+
}, [selection, pageViewContext.page]);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
{components.map((c) => (
|
|
39
|
+
<FrameMenu
|
|
40
|
+
key={c.id}
|
|
41
|
+
component={c}
|
|
42
|
+
mode={mode}
|
|
43
|
+
pageViewContext={pageViewContext}
|
|
44
|
+
/>
|
|
45
|
+
))}{" "}
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
useEditContext,
|
|
4
|
+
useModifiedFieldsContext,
|
|
5
|
+
} from "../client/editContext";
|
|
6
|
+
import { useThrottledCallback } from "use-debounce";
|
|
7
|
+
import { getFieldDescriptorFromElement, hasFieldLock } from "../utils";
|
|
8
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
9
|
+
|
|
10
|
+
export function InlineEditor({
|
|
11
|
+
pageViewContext,
|
|
12
|
+
mode,
|
|
13
|
+
}: {
|
|
14
|
+
pageViewContext: PageViewContext;
|
|
15
|
+
mode: "edit" | "view";
|
|
16
|
+
}) {
|
|
17
|
+
const context = useEditContext();
|
|
18
|
+
const modifiedFieldsContext = useModifiedFieldsContext();
|
|
19
|
+
|
|
20
|
+
if (!context) return;
|
|
21
|
+
|
|
22
|
+
const mutationObserverRef = useRef<MutationObserver | null>(null);
|
|
23
|
+
|
|
24
|
+
const debouncedSetFieldvalue = useThrottledCallback(
|
|
25
|
+
(value, fieldId, fieldName, itemId, language, version) => {
|
|
26
|
+
var modifiedFieldValue = modifiedFieldsContext?.modifiedFields.find(
|
|
27
|
+
(x) =>
|
|
28
|
+
x.fieldId === fieldId &&
|
|
29
|
+
x.item.id === itemId &&
|
|
30
|
+
x.item.language === language &&
|
|
31
|
+
x.item.version === version
|
|
32
|
+
)?.value;
|
|
33
|
+
|
|
34
|
+
if (modifiedFieldValue === value) return;
|
|
35
|
+
|
|
36
|
+
context.operations.editField({
|
|
37
|
+
field: {
|
|
38
|
+
fieldId,
|
|
39
|
+
fieldName: fieldName ?? undefined,
|
|
40
|
+
item: {
|
|
41
|
+
id: itemId,
|
|
42
|
+
language,
|
|
43
|
+
version,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
refresh: "none",
|
|
47
|
+
value: value,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
context.configuration.debounceFieldEditsInterval
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!context || mode === "view") return;
|
|
55
|
+
const element = context.inlineEditingFieldElement;
|
|
56
|
+
|
|
57
|
+
const editableElements =
|
|
58
|
+
pageViewContext.editorIframeRef.current?.contentWindow?.document.querySelectorAll(
|
|
59
|
+
'[contenteditable="true"]'
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
editableElements?.forEach((element) => {
|
|
63
|
+
if (element !== context.inlineEditingFieldElement)
|
|
64
|
+
element.setAttribute("contenteditable", "false");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (element) {
|
|
68
|
+
const fieldId = element.getAttribute("data-fieldid");
|
|
69
|
+
const fieldName = element.getAttribute("data-fieldname");
|
|
70
|
+
const itemId = element.getAttribute("data-itemid");
|
|
71
|
+
const language = element.getAttribute("data-language");
|
|
72
|
+
const versionText = element.getAttribute("data-version");
|
|
73
|
+
const version = versionText ? parseInt(versionText) : undefined;
|
|
74
|
+
const isRichText = element.getAttribute("data-is-richtext") === "true";
|
|
75
|
+
|
|
76
|
+
if (!fieldId || !itemId || !language || !version) return;
|
|
77
|
+
|
|
78
|
+
const fieldDescriptor = getFieldDescriptorFromElement(element);
|
|
79
|
+
|
|
80
|
+
const hasFielLock = hasFieldLock(fieldDescriptor, context);
|
|
81
|
+
|
|
82
|
+
if (!hasFielLock) return;
|
|
83
|
+
|
|
84
|
+
element.setAttribute("contenteditable", "true");
|
|
85
|
+
|
|
86
|
+
mutationObserverRef.current = new MutationObserver(() => {
|
|
87
|
+
debouncedSetFieldvalue(
|
|
88
|
+
isRichText ? element.innerHTML : element.innerText,
|
|
89
|
+
fieldId,
|
|
90
|
+
fieldName,
|
|
91
|
+
itemId,
|
|
92
|
+
language,
|
|
93
|
+
version
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
element.focus();
|
|
98
|
+
|
|
99
|
+
mutationObserverRef.current.observe(element, {
|
|
100
|
+
childList: true, // observe direct children changes
|
|
101
|
+
subtree: true, // observe all descendants changes
|
|
102
|
+
characterData: true, // observe text changes
|
|
103
|
+
//attributes: true, // observe attribute changes (like style or class)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return () => {
|
|
107
|
+
if (mutationObserverRef.current) {
|
|
108
|
+
mutationObserverRef.current.disconnect();
|
|
109
|
+
mutationObserverRef.current = null;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}, [context?.inlineEditingFieldElement]);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const updateFields = async () => {
|
|
116
|
+
modifiedFieldsContext?.modifiedFields.forEach((field) => {
|
|
117
|
+
const elements =
|
|
118
|
+
pageViewContext.editorIframeRef.current!.contentWindow?.document.querySelectorAll(
|
|
119
|
+
`[data-fieldid="${field.fieldId}"][data-itemid="${field.item.id}"][data-language="${field.item.language}"][data-version="${field.item.version}"`
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
elements?.forEach(async (element) => {
|
|
123
|
+
if (element && element !== context?.inlineEditingFieldElement) {
|
|
124
|
+
const realField = await context.itemsRepository.getField(field);
|
|
125
|
+
const fieldType = realField?.type;
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
fieldType === "rich text" ||
|
|
129
|
+
fieldType === "single-line text" ||
|
|
130
|
+
fieldType === "multi-line text"
|
|
131
|
+
) {
|
|
132
|
+
element.innerHTML = field?.value ? (field.value as string) : "";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
updateFields();
|
|
140
|
+
}, [
|
|
141
|
+
modifiedFieldsContext?.modifiedFields,
|
|
142
|
+
context?.itemsRepository.revision,
|
|
143
|
+
context?.inlineEditingFieldElement,
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
import { findFieldElement } from "../utils";
|
|
3
|
+
import { EditSession } from "../../types";
|
|
4
|
+
|
|
5
|
+
export function LockedFieldIndicator() {
|
|
6
|
+
const editContext = useEditContext();
|
|
7
|
+
if (!editContext) return;
|
|
8
|
+
|
|
9
|
+
const sessionsWithFieldLock = editContext.activeSessions.filter(
|
|
10
|
+
(x) => x.fieldLock && x.sessionId !== editContext.sessionId
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{sessionsWithFieldLock.map((session) => {
|
|
16
|
+
if (!session.fieldLock) return;
|
|
17
|
+
const iframe = editContext.pageView.editorIframeRef.current;
|
|
18
|
+
if (!iframe) return;
|
|
19
|
+
const element = findFieldElement(iframe, session.fieldLock);
|
|
20
|
+
if (!element) return;
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<FieldLock
|
|
24
|
+
key={session.sessionId}
|
|
25
|
+
element={element}
|
|
26
|
+
iframe={iframe}
|
|
27
|
+
session={session}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
})}
|
|
31
|
+
</>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function FieldLock({
|
|
35
|
+
element,
|
|
36
|
+
iframe,
|
|
37
|
+
session,
|
|
38
|
+
}: {
|
|
39
|
+
session: EditSession;
|
|
40
|
+
element: Element;
|
|
41
|
+
iframe: HTMLIFrameElement;
|
|
42
|
+
}) {
|
|
43
|
+
const rect = element.getBoundingClientRect();
|
|
44
|
+
const editorRect = iframe.getBoundingClientRect();
|
|
45
|
+
|
|
46
|
+
if (rect && editorRect) {
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
className="absolute text-xs text-white p-0.5 rounded hover:opacity-100 opacity-90"
|
|
50
|
+
style={{
|
|
51
|
+
left: rect.left + "px",
|
|
52
|
+
top: rect.top + "px",
|
|
53
|
+
background: session.color,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{session.user.name}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { FullItem } from "../pageModel";
|
|
4
|
+
import { useEditContext } from "../client/editContext";
|
|
5
|
+
|
|
6
|
+
export function NoLayout() {
|
|
7
|
+
const [lastPageItem, setLastPageItem] = useState<FullItem | null>(null);
|
|
8
|
+
const editContext = useEditContext();
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const updateLastPage = async () => {
|
|
12
|
+
if (!editContext?.pageView.pageItemDescriptor) return;
|
|
13
|
+
|
|
14
|
+
const lastPage = await editContext.itemsRepository.getItem(
|
|
15
|
+
editContext.pageView.pageItemDescriptor
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (lastPage) setLastPageItem(lastPage);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
updateLastPage();
|
|
22
|
+
}, [editContext?.currentItemDescriptor]);
|
|
23
|
+
return (
|
|
24
|
+
<div className="h-full w-full flex flex-col items-center justify-center text-sm">
|
|
25
|
+
Item has no layout.
|
|
26
|
+
{lastPageItem && (
|
|
27
|
+
<div
|
|
28
|
+
className="cursor-pointer hover:underline p-2"
|
|
29
|
+
onClick={() => editContext?.loadItem(lastPageItem.descriptor)}
|
|
30
|
+
>
|
|
31
|
+
Load {lastPageItem?.name}?
|
|
32
|
+
</div>
|
|
33
|
+
)}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
3
|
+
import { InlineEditor } from "./InlineEditor";
|
|
4
|
+
import { FieldActionsIndicators } from "./FieldActionIndicators";
|
|
5
|
+
import { PlaceholderDropZones } from "./PlaceholderDropZones";
|
|
6
|
+
import { PictureEditorOverlay } from "./PictureEditorOverlay";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { LockedFieldIndicator } from "./LockedFieldIndicator";
|
|
9
|
+
import { FrameMenus } from "./FrameMenus";
|
|
10
|
+
import { FieldEditedIndicators } from "./FieldEditedIndicators";
|
|
11
|
+
import { CommentHighlightings } from "./CommentHighlightings";
|
|
12
|
+
|
|
13
|
+
export function PageEditorChrome({
|
|
14
|
+
iframe,
|
|
15
|
+
mode,
|
|
16
|
+
pageViewContext,
|
|
17
|
+
}: {
|
|
18
|
+
iframe: HTMLIFrameElement;
|
|
19
|
+
mode: "edit" | "compare" | "view";
|
|
20
|
+
pageViewContext: PageViewContext;
|
|
21
|
+
}) {
|
|
22
|
+
const editContext = useEditContext();
|
|
23
|
+
const [insertingStyle, setInsertingStyle] = useState<React.CSSProperties>();
|
|
24
|
+
|
|
25
|
+
if (!editContext?.pageView || !iframe?.contentDocument) return null;
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!editContext.inserting) setInsertingStyle(undefined);
|
|
29
|
+
let insertingPosition: { y: number; x: number } | undefined;
|
|
30
|
+
const insertingRect = editContext.inserting
|
|
31
|
+
? editContext.inserting.positionElement.getBoundingClientRect()
|
|
32
|
+
: null;
|
|
33
|
+
|
|
34
|
+
if (insertingRect) {
|
|
35
|
+
if (editContext.inserting?.positionAnchor === "top")
|
|
36
|
+
insertingPosition = {
|
|
37
|
+
y: insertingRect.y,
|
|
38
|
+
x: insertingRect.x + insertingRect.width / 2,
|
|
39
|
+
};
|
|
40
|
+
if (editContext.inserting?.positionAnchor === "bottom")
|
|
41
|
+
insertingPosition = {
|
|
42
|
+
y: insertingRect.y + insertingRect.height,
|
|
43
|
+
x: insertingRect.x + insertingRect.width / 2,
|
|
44
|
+
};
|
|
45
|
+
if (editContext.inserting?.positionAnchor === "left")
|
|
46
|
+
insertingPosition = {
|
|
47
|
+
y: insertingRect.y + insertingRect.height / 2,
|
|
48
|
+
x: insertingRect.x,
|
|
49
|
+
};
|
|
50
|
+
if (editContext.inserting?.positionAnchor === "right")
|
|
51
|
+
insertingPosition = {
|
|
52
|
+
y: insertingRect.y + insertingRect.height / 2,
|
|
53
|
+
x: insertingRect.x + insertingRect.width,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const getInsertingStyle = () => {
|
|
58
|
+
if (!insertingPosition) return;
|
|
59
|
+
const scale = pageViewContext.zoom;
|
|
60
|
+
const x = Math.min(
|
|
61
|
+
pageViewContext.viewport.width - 20,
|
|
62
|
+
Math.max(20, insertingPosition.x * (scale || 1))
|
|
63
|
+
);
|
|
64
|
+
const y = Math.min(
|
|
65
|
+
pageViewContext.viewport.height - 20,
|
|
66
|
+
Math.max(20, insertingPosition.y * (scale || 1))
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
top: y - 16 + "px",
|
|
71
|
+
left: x - 16 + "px",
|
|
72
|
+
zIndex: 1000,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const insertingStyle = getInsertingStyle();
|
|
77
|
+
setInsertingStyle(insertingStyle);
|
|
78
|
+
}, [editContext.inserting, pageViewContext.viewport]);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
<FrameMenus mode={mode} pageViewContext={pageViewContext} />
|
|
83
|
+
<InlineEditor
|
|
84
|
+
mode={mode === "edit" ? "edit" : "view"}
|
|
85
|
+
pageViewContext={pageViewContext}
|
|
86
|
+
/>
|
|
87
|
+
<LockedFieldIndicator />
|
|
88
|
+
<FieldActionsIndicators />
|
|
89
|
+
{editContext.showComments && (
|
|
90
|
+
<CommentHighlightings
|
|
91
|
+
iframe={pageViewContext?.editorIframeRef.current!}
|
|
92
|
+
scale={1}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
|
|
96
|
+
<FieldEditedIndicators pageViewContext={pageViewContext} />
|
|
97
|
+
|
|
98
|
+
{mode === "edit" && (
|
|
99
|
+
<>
|
|
100
|
+
<PlaceholderDropZones
|
|
101
|
+
iframe={pageViewContext?.editorIframeRef.current}
|
|
102
|
+
size="large"
|
|
103
|
+
/>
|
|
104
|
+
<PictureEditorOverlay />
|
|
105
|
+
|
|
106
|
+
{insertingStyle && (
|
|
107
|
+
<div
|
|
108
|
+
className="absolute flex h-8 w-8"
|
|
109
|
+
style={insertingStyle}
|
|
110
|
+
>
|
|
111
|
+
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-sky-400 opacity-75"></span>
|
|
112
|
+
<span className="relative inline-flex rounded-full h-8 w-8 bg-sky-500"></span>
|
|
113
|
+
</div>
|
|
114
|
+
)}
|
|
115
|
+
</>
|
|
116
|
+
)}
|
|
117
|
+
</>
|
|
118
|
+
);
|
|
119
|
+
}
|