@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,50 @@
|
|
|
1
|
+
import { Dialog } from "primereact/dialog";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useImperativeHandle, useState } from "react";
|
|
4
|
+
|
|
5
|
+
export interface GenericDialogHandle {
|
|
6
|
+
show: (props: {
|
|
7
|
+
title: string;
|
|
8
|
+
content: React.ReactNode;
|
|
9
|
+
width?: string;
|
|
10
|
+
height?: string;
|
|
11
|
+
}) => void;
|
|
12
|
+
hide: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const GenericDialog = forwardRef<GenericDialogHandle>((_, ref) => {
|
|
16
|
+
const [content, setContent] = useState<React.ReactNode>(null);
|
|
17
|
+
const [title, setTitle] = useState<string>("");
|
|
18
|
+
const [width, setWidth] = useState<string>("50vw");
|
|
19
|
+
const [height, setHeight] = useState<string>("50vh");
|
|
20
|
+
const [visible, setVisible] = useState<boolean>(false);
|
|
21
|
+
|
|
22
|
+
const show = (props: {
|
|
23
|
+
title: string;
|
|
24
|
+
content: React.ReactNode;
|
|
25
|
+
width?: string;
|
|
26
|
+
height?: string;
|
|
27
|
+
}) => {
|
|
28
|
+
setTitle(props.title);
|
|
29
|
+
setContent(props.content);
|
|
30
|
+
if (props.width) setWidth(props.width);
|
|
31
|
+
if (props.height) setHeight(props.height);
|
|
32
|
+
setVisible(true);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
useImperativeHandle(ref, () => ({
|
|
36
|
+
show,
|
|
37
|
+
hide: () => setVisible(false),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Dialog
|
|
42
|
+
onHide={() => setVisible(false)}
|
|
43
|
+
visible={visible}
|
|
44
|
+
header={title}
|
|
45
|
+
style={{ width, height }}
|
|
46
|
+
>
|
|
47
|
+
{content}
|
|
48
|
+
</Dialog>
|
|
49
|
+
);
|
|
50
|
+
});
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, {
|
|
4
|
+
MouseEvent,
|
|
5
|
+
ReactNode,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { ToastMessage } from "primereact/toast";
|
|
11
|
+
|
|
12
|
+
import { EditorConfiguration, EditorView } from "../../config/types";
|
|
13
|
+
import { FieldAction, InsertingState } from "./EditorClient";
|
|
14
|
+
import { MenuItem } from "primereact/menuitem";
|
|
15
|
+
import { Command, CommandData } from "../commands/commands";
|
|
16
|
+
import { ComponentDetails } from "../services/componentDesignerService";
|
|
17
|
+
import { PageViewContext } from "../page-viewer/pageViewContext";
|
|
18
|
+
import {
|
|
19
|
+
EditOperation,
|
|
20
|
+
EditSession,
|
|
21
|
+
FieldDescriptor,
|
|
22
|
+
HistoryEntry,
|
|
23
|
+
InsertOption,
|
|
24
|
+
LanguageVersions,
|
|
25
|
+
User,
|
|
26
|
+
ValidationResult,
|
|
27
|
+
Comment,
|
|
28
|
+
WorkboxItem,
|
|
29
|
+
Review,
|
|
30
|
+
AddComponentOperation,
|
|
31
|
+
} from "../../types";
|
|
32
|
+
|
|
33
|
+
import { ConfirmationProps } from "../ConfirmationDialog";
|
|
34
|
+
import {
|
|
35
|
+
Component,
|
|
36
|
+
FieldButton,
|
|
37
|
+
ItemDescriptor,
|
|
38
|
+
Page,
|
|
39
|
+
Timings,
|
|
40
|
+
FullItem,
|
|
41
|
+
Version,
|
|
42
|
+
Field,
|
|
43
|
+
} from "../pageModel";
|
|
44
|
+
import { ItemsRepository } from "./itemsRepository";
|
|
45
|
+
import { MediaSelectorMode } from "../media-selector/MediaSelector";
|
|
46
|
+
import { ComponentCommand } from "../commands/componentCommands";
|
|
47
|
+
import { AiTerminalOptions } from "../ai/AiTerminal";
|
|
48
|
+
|
|
49
|
+
export type DragObject = {
|
|
50
|
+
type: "template" | "component" | "link-component" | "items";
|
|
51
|
+
typeId: string;
|
|
52
|
+
templateId?: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
component?: ItemDescriptor;
|
|
55
|
+
items?: ItemDescriptor[];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type SelectionRange = {
|
|
59
|
+
fieldId: string;
|
|
60
|
+
startOffset: number;
|
|
61
|
+
endOffset: number;
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type EditContextType = {
|
|
66
|
+
operations: {
|
|
67
|
+
moveItems: (
|
|
68
|
+
items: ItemDescriptor[],
|
|
69
|
+
target: ItemDescriptor,
|
|
70
|
+
index: number,
|
|
71
|
+
) => Promise<void>;
|
|
72
|
+
addComponent: (
|
|
73
|
+
componentTypeId: string,
|
|
74
|
+
placeholderKey: string,
|
|
75
|
+
index: number,
|
|
76
|
+
parentId?: string,
|
|
77
|
+
) => Promise<AddComponentOperation | undefined>;
|
|
78
|
+
|
|
79
|
+
duplicateComponents: ({ componentIds }: { componentIds: string[] }) => void;
|
|
80
|
+
|
|
81
|
+
ensureLock: (field: FieldDescriptor) => Promise<boolean>;
|
|
82
|
+
lockItems: (item: ItemDescriptor[]) => void;
|
|
83
|
+
unlockItems: (item: ItemDescriptor[]) => void;
|
|
84
|
+
editField: (props: {
|
|
85
|
+
field: FieldDescriptor;
|
|
86
|
+
value?: any;
|
|
87
|
+
rawValue?: string | null;
|
|
88
|
+
refresh?: "none" | "immediate" | "delayed" | "waitForQuietPeriod";
|
|
89
|
+
}) => Promise<void>;
|
|
90
|
+
undo: (numOperations?: number) => Promise<boolean>;
|
|
91
|
+
redo: () => Promise<boolean>;
|
|
92
|
+
executeEditOperation: (operation: EditOperation) => void;
|
|
93
|
+
executeWorkflowCommand: (
|
|
94
|
+
item: ItemDescriptor,
|
|
95
|
+
commandId: string,
|
|
96
|
+
) => Promise<void>;
|
|
97
|
+
renameItem: (item: ItemDescriptor, newName: string) => Promise<void>;
|
|
98
|
+
deleteItems: (items: ItemDescriptor[]) => Promise<void>;
|
|
99
|
+
createItem: (
|
|
100
|
+
parent: ItemDescriptor,
|
|
101
|
+
templateId: string,
|
|
102
|
+
name: string,
|
|
103
|
+
) => Promise<ItemDescriptor | undefined>;
|
|
104
|
+
createVersion: (item: ItemDescriptor) => Promise<void>;
|
|
105
|
+
undoing: boolean;
|
|
106
|
+
};
|
|
107
|
+
comments: Comment[];
|
|
108
|
+
loadComments: () => void;
|
|
109
|
+
setComments: React.Dispatch<React.SetStateAction<Comment[]>>;
|
|
110
|
+
selectedComment: Comment | undefined;
|
|
111
|
+
setSelectedComment: React.Dispatch<React.SetStateAction<Comment | undefined>>;
|
|
112
|
+
showComments: boolean;
|
|
113
|
+
setShowComments: React.Dispatch<React.SetStateAction<boolean>>;
|
|
114
|
+
addComment: () => void;
|
|
115
|
+
item?: FullItem;
|
|
116
|
+
|
|
117
|
+
workboxItems: WorkboxItem[];
|
|
118
|
+
|
|
119
|
+
itemLanguages: LanguageVersions[];
|
|
120
|
+
itemVersions: Version[];
|
|
121
|
+
view?: EditorView;
|
|
122
|
+
|
|
123
|
+
viewName: string;
|
|
124
|
+
switchView: (viewName: string) => void;
|
|
125
|
+
compareMode: boolean;
|
|
126
|
+
setCompareMode: (compareMode: boolean) => void;
|
|
127
|
+
setCenterPanelView: (view: ReactNode) => void;
|
|
128
|
+
configuration: EditorConfiguration;
|
|
129
|
+
showToast: (message: ToastMessage | ToastMessage[]) => void;
|
|
130
|
+
sessionId: string;
|
|
131
|
+
openSplashScreen: () => void;
|
|
132
|
+
getComponentCommands: (component: Component[]) => ComponentCommand[];
|
|
133
|
+
selectMedia: ({
|
|
134
|
+
selectedIdPath,
|
|
135
|
+
mode,
|
|
136
|
+
}: {
|
|
137
|
+
selectedIdPath: string;
|
|
138
|
+
mode: MediaSelectorMode;
|
|
139
|
+
}) => Promise<string | null>;
|
|
140
|
+
|
|
141
|
+
updateUrl: (params: Record<string, string>) => void;
|
|
142
|
+
|
|
143
|
+
previewMode: boolean;
|
|
144
|
+
setPreviewMode: React.Dispatch<React.SetStateAction<boolean>>;
|
|
145
|
+
|
|
146
|
+
selection: string[];
|
|
147
|
+
select: (ids: string[]) => void;
|
|
148
|
+
selectedForInsertion: string;
|
|
149
|
+
selectedRange?: SelectionRange;
|
|
150
|
+
setSelectedRange: React.Dispatch<
|
|
151
|
+
React.SetStateAction<SelectionRange | undefined>
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
setSelectedForInsertion: React.Dispatch<React.SetStateAction<string>>;
|
|
155
|
+
insertMode: boolean;
|
|
156
|
+
setInsertMode: React.Dispatch<React.SetStateAction<boolean>>;
|
|
157
|
+
inserting: InsertingState | undefined;
|
|
158
|
+
|
|
159
|
+
dragStart: (dragObject: DragObject) => void;
|
|
160
|
+
dragEnd: () => void;
|
|
161
|
+
dragObject?: DragObject;
|
|
162
|
+
refreshCompletedFlag: boolean;
|
|
163
|
+
isRefreshing: boolean;
|
|
164
|
+
openCreatePageDialog: () => void;
|
|
165
|
+
|
|
166
|
+
reviews: {
|
|
167
|
+
reviews: Review[];
|
|
168
|
+
loadReviews: () => void;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
droppedInPlaceholder: (
|
|
172
|
+
placeholderKey: string,
|
|
173
|
+
index: number,
|
|
174
|
+
spotPositionElement?: Element,
|
|
175
|
+
spotPositionAnchor?: "left" | "right" | "top" | "bottom",
|
|
176
|
+
insertOption?: InsertOption,
|
|
177
|
+
) => void;
|
|
178
|
+
|
|
179
|
+
lockedField: FieldDescriptor | undefined;
|
|
180
|
+
requestRefresh: (
|
|
181
|
+
mode?: "immediate" | "delayed" | "waitForQuietPeriod",
|
|
182
|
+
) => void;
|
|
183
|
+
page?: Page;
|
|
184
|
+
|
|
185
|
+
currentItemDescriptor?: ItemDescriptor;
|
|
186
|
+
|
|
187
|
+
setScrollIntoView: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
188
|
+
scrollIntoView?: string;
|
|
189
|
+
focusedField?: FieldDescriptor;
|
|
190
|
+
setFocusedField: (
|
|
191
|
+
field: FieldDescriptor | undefined,
|
|
192
|
+
requestLock: boolean,
|
|
193
|
+
) => Promise<boolean>;
|
|
194
|
+
unlockField: (field: FieldDescriptor) => void;
|
|
195
|
+
|
|
196
|
+
readonly: boolean;
|
|
197
|
+
triggerFieldAction: (field: FieldDescriptor, action: FieldButton) => void;
|
|
198
|
+
activeFieldActions: FieldAction[];
|
|
199
|
+
showContextMenu(e: any, menuItems: MenuItem[]): void;
|
|
200
|
+
setCurrentOverlay: React.Dispatch<React.SetStateAction<any>>;
|
|
201
|
+
currentOverlay?: any;
|
|
202
|
+
|
|
203
|
+
showAiPopup: (
|
|
204
|
+
event: MouseEvent<HTMLElement>,
|
|
205
|
+
aiTerminalOptions?: AiTerminalOptions,
|
|
206
|
+
) => void;
|
|
207
|
+
showFieldEditorPopup: (fields: Field[], sections: string[], ev: any) => void;
|
|
208
|
+
validationResult: ValidationResult[] | undefined;
|
|
209
|
+
contentEditorItem: FullItem | undefined;
|
|
210
|
+
|
|
211
|
+
loadItem: (
|
|
212
|
+
itemToLoad: ItemDescriptor | string,
|
|
213
|
+
options?: { addToBrowseHistory?: boolean },
|
|
214
|
+
) => Promise<FullItem | undefined>;
|
|
215
|
+
editHistory: EditOperation[];
|
|
216
|
+
activeSessions: EditSession[];
|
|
217
|
+
validating: boolean;
|
|
218
|
+
isCommandDisabled: <T extends CommandData>({
|
|
219
|
+
command,
|
|
220
|
+
data,
|
|
221
|
+
}: {
|
|
222
|
+
command: Command<T>;
|
|
223
|
+
data?: T;
|
|
224
|
+
}) => boolean;
|
|
225
|
+
|
|
226
|
+
executeCommand: <T extends CommandData>({
|
|
227
|
+
command,
|
|
228
|
+
data,
|
|
229
|
+
event,
|
|
230
|
+
}: {
|
|
231
|
+
command: Command<T>;
|
|
232
|
+
data?: T;
|
|
233
|
+
event?: React.SyntheticEvent;
|
|
234
|
+
}) => Promise<any>;
|
|
235
|
+
|
|
236
|
+
componentDesignerComponent: ComponentDetails | undefined;
|
|
237
|
+
setComponentDesignerComponent: React.Dispatch<
|
|
238
|
+
React.SetStateAction<ComponentDetails | undefined>
|
|
239
|
+
>;
|
|
240
|
+
componentDesignerRendering: FullItem | undefined;
|
|
241
|
+
setComponentDesignerRendering: React.Dispatch<
|
|
242
|
+
React.SetStateAction<FullItem | undefined>
|
|
243
|
+
>;
|
|
244
|
+
inlineEditingFieldElement?: HTMLElement;
|
|
245
|
+
setInlineEditingFieldElement: React.Dispatch<
|
|
246
|
+
React.SetStateAction<HTMLElement | undefined>
|
|
247
|
+
>;
|
|
248
|
+
timings: Timings;
|
|
249
|
+
setTimings: React.Dispatch<React.SetStateAction<Timings>>;
|
|
250
|
+
pageView: PageViewContext;
|
|
251
|
+
|
|
252
|
+
confirm: (props: ConfirmationProps) => void;
|
|
253
|
+
showMessageDialog: (props: { header: string; message: string }) => void;
|
|
254
|
+
|
|
255
|
+
itemsRepository: ItemsRepository;
|
|
256
|
+
browseHistory: HistoryEntry[];
|
|
257
|
+
handleKeyDown: (event: KeyboardEvent) => void;
|
|
258
|
+
startTour: () => void;
|
|
259
|
+
|
|
260
|
+
addSocketMessageListener: (
|
|
261
|
+
callback: (message: { type: string; payload: any }) => void,
|
|
262
|
+
) => () => void;
|
|
263
|
+
compareTo?: ItemDescriptor;
|
|
264
|
+
setCompareTo: React.Dispatch<
|
|
265
|
+
React.SetStateAction<ItemDescriptor | undefined>
|
|
266
|
+
>;
|
|
267
|
+
lastEditedFields: EditedField[];
|
|
268
|
+
revision?: string;
|
|
269
|
+
user?: User;
|
|
270
|
+
statusMessage: React.ReactNode;
|
|
271
|
+
setStatusMessage: React.Dispatch<React.SetStateAction<React.ReactNode>>;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const EditContext = React.createContext<EditContextType | undefined>(undefined);
|
|
275
|
+
export const EditContextProvider = EditContext.Provider;
|
|
276
|
+
|
|
277
|
+
export const useEditContext = () => useContext(EditContext);
|
|
278
|
+
|
|
279
|
+
export function useEditContextRef() {
|
|
280
|
+
const contextValue = useEditContext();
|
|
281
|
+
const contextRef = useRef(contextValue);
|
|
282
|
+
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
contextRef.current = contextValue;
|
|
285
|
+
}, [contextValue]);
|
|
286
|
+
|
|
287
|
+
return contextRef;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export type EditButton = {
|
|
291
|
+
id: string;
|
|
292
|
+
icon: React.ReactNode;
|
|
293
|
+
onClick: (ev: MouseEvent<HTMLButtonElement>) => void;
|
|
294
|
+
label: string;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export type ModifiedField = FieldDescriptor & {
|
|
298
|
+
value: string | null;
|
|
299
|
+
isDirty: boolean;
|
|
300
|
+
modifiedBy: User;
|
|
301
|
+
timestamp: number;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export type ModifiedFieldsContextType = {
|
|
305
|
+
modifiedFields: ModifiedField[];
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export type EditedField = FieldDescriptor & {
|
|
309
|
+
timestamp: number;
|
|
310
|
+
user: User;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const ModifiedFieldsContext = React.createContext<
|
|
314
|
+
ModifiedFieldsContextType | undefined
|
|
315
|
+
>(undefined);
|
|
316
|
+
|
|
317
|
+
export const useModifiedFieldsContext = () => useContext(ModifiedFieldsContext);
|
|
318
|
+
export const ModifiedFieldsContextProvider = ModifiedFieldsContext.Provider;
|
|
319
|
+
|
|
320
|
+
export type OperationsContextType = {
|
|
321
|
+
executingEditOperations: EditOperation[];
|
|
322
|
+
editOperationExecuted: EditOperation | undefined;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const OperationsContext = React.createContext<
|
|
326
|
+
OperationsContextType | undefined
|
|
327
|
+
>(undefined);
|
|
328
|
+
|
|
329
|
+
export const useOperationsContext = () => useContext(OperationsContext);
|
|
330
|
+
export const OperationsContextProvider = OperationsContext.Provider;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EditorConfiguration } from "../../config/types";
|
|
2
|
+
import { ConfirmationDialogHandle } from "../ConfirmationDialog";
|
|
3
|
+
import { ExecutionResult } from "../services/editService";
|
|
4
|
+
|
|
5
|
+
export function handleErrorResult(
|
|
6
|
+
result: ExecutionResult<unknown>,
|
|
7
|
+
ui: {
|
|
8
|
+
showErrorToast: (error: { summary: string; details: string }) => void;
|
|
9
|
+
confirmationDialogRef: React.RefObject<ConfirmationDialogHandle | null>;
|
|
10
|
+
},
|
|
11
|
+
state: {
|
|
12
|
+
configuration: EditorConfiguration;
|
|
13
|
+
}
|
|
14
|
+
) {
|
|
15
|
+
if (result.type === "error") {
|
|
16
|
+
console.log("show error toast", result);
|
|
17
|
+
|
|
18
|
+
ui.showErrorToast({
|
|
19
|
+
summary: result.summary || "Error",
|
|
20
|
+
details: result.details || "An error occurred",
|
|
21
|
+
});
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (result.type === "unauthorized") {
|
|
26
|
+
if (state.configuration.events.onUnauthorized) {
|
|
27
|
+
state.configuration.events.onUnauthorized();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ui.confirmationDialogRef.current?.confirm({
|
|
32
|
+
header: "Not logged in",
|
|
33
|
+
message: "You are not logged in anymore. Proceed to login page?",
|
|
34
|
+
accept: () => {
|
|
35
|
+
window.location.href = "/sitecore/login";
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
ui.showErrorToast({
|
|
39
|
+
summary: result.summary || "Error",
|
|
40
|
+
details: result.details || "An error occurred",
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|