@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 { useEffect } from "react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useEditContext } from "../client/editContext";
|
|
4
|
+
import { Comment } from "./Comment";
|
|
5
|
+
import { Comment as CommentType } from "../../types";
|
|
6
|
+
import { SimpleToolbar } from "../ui/SimpleToolbar";
|
|
7
|
+
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
8
|
+
|
|
9
|
+
export function Comments() {
|
|
10
|
+
const editContext = useEditContext();
|
|
11
|
+
|
|
12
|
+
const [comments, setComments] = useState<CommentType[]>([]);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const comments = editContext?.comments || [];
|
|
16
|
+
comments.sort((a, b) => a.position - b.position);
|
|
17
|
+
setComments(comments);
|
|
18
|
+
}, [editContext]);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className="flex flex-col h-full">
|
|
22
|
+
<SimpleToolbar>
|
|
23
|
+
<SimpleIconButton
|
|
24
|
+
id="add-comment"
|
|
25
|
+
icon="pi pi-plus"
|
|
26
|
+
label="Add Comment"
|
|
27
|
+
onClick={() => {
|
|
28
|
+
editContext?.addComment();
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
<SimpleIconButton
|
|
32
|
+
selected={editContext?.showComments}
|
|
33
|
+
icon="pi pi-eye"
|
|
34
|
+
label="Show Comments"
|
|
35
|
+
onClick={() => {
|
|
36
|
+
editContext?.setShowComments((x) => !x);
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</SimpleToolbar>
|
|
40
|
+
|
|
41
|
+
<div className="flex-1 overflow-auto">
|
|
42
|
+
<div className="p-4 bg-gray-50 border-l border-gray-200 h-fill-available">
|
|
43
|
+
{comments.map((comment) => (
|
|
44
|
+
<Comment key={comment.id} comment={comment} />
|
|
45
|
+
))}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEditContext } from "../../client-components";
|
|
2
|
+
import { formatDate } from "../utils";
|
|
3
|
+
|
|
4
|
+
export function PreviewInfo() {
|
|
5
|
+
const editContext = useEditContext();
|
|
6
|
+
if (!editContext) return null;
|
|
7
|
+
const review = editContext.reviews.reviews.find(
|
|
8
|
+
(x) => x.reviewerEmail === editContext.user?.email
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="flex gap-3 items-center">
|
|
13
|
+
<div className="text-white">
|
|
14
|
+
Welcome to your page <b>preview</b>, {editContext.user?.displayName}!
|
|
15
|
+
<div className="text-gray-300 text-xs">
|
|
16
|
+
{editContext.contentEditorItem?.path}{" "}
|
|
17
|
+
{editContext.contentEditorItem?.language}{" "}
|
|
18
|
+
{editContext.contentEditorItem?.version}
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
{review?.approvalDate && (
|
|
22
|
+
<i
|
|
23
|
+
className="pi pi-check text-green-400 text-2xl font-bold"
|
|
24
|
+
title={"Approved " + formatDate(new Date(review.approvalDate))}
|
|
25
|
+
></i>
|
|
26
|
+
)}
|
|
27
|
+
{review?.rejectedDate && (
|
|
28
|
+
<i
|
|
29
|
+
className="pi pi-times text-red-400 text-2xl font-bold"
|
|
30
|
+
title={"Rejected " + formatDate(new Date(review.rejectedDate))}
|
|
31
|
+
></i>
|
|
32
|
+
)}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { SimpleToolbar } from "../ui/SimpleToolbar";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { SimpleTable } from "../ui/SimpleTable";
|
|
4
|
+
import { Reviewer } from "../../types";
|
|
5
|
+
import { Review } from "../../types";
|
|
6
|
+
import { inviteReviewer, addReview } from "../services/reviewsService";
|
|
7
|
+
import { useEditContext } from "../client/editContext";
|
|
8
|
+
import { Checkbox } from "primereact/checkbox";
|
|
9
|
+
import { formatDate } from "../utils";
|
|
10
|
+
import { InputText } from "primereact/inputtext";
|
|
11
|
+
import { OverlayPanel } from "primereact/overlaypanel";
|
|
12
|
+
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
13
|
+
import { Button } from "primereact/button";
|
|
14
|
+
import uuid from "react-uuid";
|
|
15
|
+
|
|
16
|
+
type ReviewData = {
|
|
17
|
+
review: Review;
|
|
18
|
+
checked: boolean;
|
|
19
|
+
updating?: boolean;
|
|
20
|
+
error?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function Reviews() {
|
|
24
|
+
const [reviewData, setReviewData] = useState<ReviewData[]>([]);
|
|
25
|
+
const [newReviewer, setNewReviewer] = useState<Reviewer>({
|
|
26
|
+
email: "",
|
|
27
|
+
name: "",
|
|
28
|
+
});
|
|
29
|
+
const overlayPanelRef = useRef<OverlayPanel>(null);
|
|
30
|
+
|
|
31
|
+
const editContext = useEditContext();
|
|
32
|
+
|
|
33
|
+
const [showErrors, setShowErrors] = useState(false);
|
|
34
|
+
const [waiting, setWaiting] = useState(false);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (editContext?.reviews) {
|
|
38
|
+
setReviewData(
|
|
39
|
+
editContext.reviews.reviews.map((x) => ({
|
|
40
|
+
review: x,
|
|
41
|
+
checked: false,
|
|
42
|
+
}))
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}, [editContext?.reviews]);
|
|
46
|
+
|
|
47
|
+
// Simple email validation function
|
|
48
|
+
const isValidEmail = (email: string): boolean => {
|
|
49
|
+
// This regular expression is not perfect but works for basic validation
|
|
50
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
51
|
+
return emailRegex.test(email);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const emailAlreadyExists = (email: string): boolean => {
|
|
55
|
+
return reviewData.some((x) => x.review?.reviewerEmail === email);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getStatus = (reviewData?: ReviewData) => {
|
|
59
|
+
if (reviewData?.updating) {
|
|
60
|
+
return <i className="pi pi-spinner pi-spin" />;
|
|
61
|
+
}
|
|
62
|
+
if (reviewData?.error) {
|
|
63
|
+
return (
|
|
64
|
+
<div className="flex items-center gap-1">
|
|
65
|
+
<i className="pi pi-times text-red-500 " /> {reviewData.error}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const review = reviewData?.review;
|
|
70
|
+
|
|
71
|
+
if (review) {
|
|
72
|
+
if (review.approvalDate) {
|
|
73
|
+
return (
|
|
74
|
+
<div className="flex flex-row gap-1">
|
|
75
|
+
<i className="pi pi-check text-green-500 " />
|
|
76
|
+
Approved {formatDate(new Date(review.approvalDate))}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (review.rejectedDate) {
|
|
81
|
+
return (
|
|
82
|
+
<div className="flex flex-row gap-1">
|
|
83
|
+
<i className="pi pi-times text-red-500 " />
|
|
84
|
+
Rejected {formatDate(new Date(review.rejectedDate))}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (review.invitationSentDate) {
|
|
89
|
+
return (
|
|
90
|
+
"Invitation Sent " + formatDate(new Date(review.invitationSentDate))
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return "Not yet invited";
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const sendInvitations = () => {
|
|
98
|
+
setShowErrors(true);
|
|
99
|
+
const invalidReviewers = reviewData.filter(
|
|
100
|
+
(x) =>
|
|
101
|
+
x.checked &&
|
|
102
|
+
(!x.review?.reviewerEmail || !isValidEmail(x.review?.reviewerEmail))
|
|
103
|
+
);
|
|
104
|
+
if (invalidReviewers.length > 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
reviewData.forEach(async (x) => {
|
|
109
|
+
if (!editContext?.currentItemDescriptor) return;
|
|
110
|
+
if (x.checked) {
|
|
111
|
+
x.updating = true;
|
|
112
|
+
setReviewData([...reviewData]);
|
|
113
|
+
const result = await inviteReviewer(x.review);
|
|
114
|
+
if (result.response.status !== 200) {
|
|
115
|
+
x.error = "Error inviting reviewer";
|
|
116
|
+
}
|
|
117
|
+
x.updating = false;
|
|
118
|
+
x.updating = false;
|
|
119
|
+
setReviewData([...reviewData]);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div className="flex flex-col h-full">
|
|
126
|
+
<SimpleToolbar>
|
|
127
|
+
<SimpleIconButton
|
|
128
|
+
label="Add Reviewer"
|
|
129
|
+
icon="pi pi-plus"
|
|
130
|
+
onClick={(x) => {
|
|
131
|
+
overlayPanelRef.current?.toggle(x);
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
document.getElementById("name")?.focus();
|
|
134
|
+
}, 100);
|
|
135
|
+
}}
|
|
136
|
+
/>
|
|
137
|
+
<SimpleIconButton
|
|
138
|
+
label="Send Invitations"
|
|
139
|
+
icon="pi pi-send"
|
|
140
|
+
disabled={!reviewData.some((x) => x.checked)}
|
|
141
|
+
onClick={sendInvitations}
|
|
142
|
+
/>
|
|
143
|
+
</SimpleToolbar>
|
|
144
|
+
<OverlayPanel ref={overlayPanelRef}>
|
|
145
|
+
<div className="p-2 text-xs flex flex-col gap-2">
|
|
146
|
+
<div className="flex flex-col gap-2">
|
|
147
|
+
<label htmlFor="name">Name</label>
|
|
148
|
+
|
|
149
|
+
<InputText
|
|
150
|
+
id="name"
|
|
151
|
+
className="w-full"
|
|
152
|
+
value={newReviewer?.name}
|
|
153
|
+
onChange={(e) => {
|
|
154
|
+
setNewReviewer((x) => ({
|
|
155
|
+
...x!,
|
|
156
|
+
name: e.target.value,
|
|
157
|
+
}));
|
|
158
|
+
}}
|
|
159
|
+
autoFocus
|
|
160
|
+
/>
|
|
161
|
+
{showErrors && !newReviewer?.name && (
|
|
162
|
+
<small style={{ color: "red" }}>Name is required</small>
|
|
163
|
+
)}
|
|
164
|
+
<div className="flex flex-col gap-2">
|
|
165
|
+
<label htmlFor="email">Email</label>
|
|
166
|
+
<InputText
|
|
167
|
+
id="email"
|
|
168
|
+
className="w-full"
|
|
169
|
+
value={newReviewer?.email}
|
|
170
|
+
onChange={(e) => {
|
|
171
|
+
setNewReviewer((x) => ({
|
|
172
|
+
...x!,
|
|
173
|
+
email: e.target.value,
|
|
174
|
+
}));
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
177
|
+
{showErrors && !isValidEmail(newReviewer.email) && (
|
|
178
|
+
<small style={{ color: "red" }}>
|
|
179
|
+
Not a valid email address
|
|
180
|
+
</small>
|
|
181
|
+
)}
|
|
182
|
+
{showErrors && emailAlreadyExists(newReviewer.email) && (
|
|
183
|
+
<small style={{ color: "red" }}>Email already exists</small>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<Button
|
|
188
|
+
label="Add Reviewer"
|
|
189
|
+
disabled={waiting}
|
|
190
|
+
icon="pi pi-plus"
|
|
191
|
+
onClick={async () => {
|
|
192
|
+
if (!editContext?.contentEditorItem) return;
|
|
193
|
+
setShowErrors(true);
|
|
194
|
+
if (emailAlreadyExists(newReviewer.email)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (!isValidEmail(newReviewer.email) || !newReviewer.name) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
setWaiting(true);
|
|
201
|
+
await addReview({
|
|
202
|
+
id: uuid(),
|
|
203
|
+
reviewerName: newReviewer!.name,
|
|
204
|
+
reviewerEmail: newReviewer!.email,
|
|
205
|
+
itemId: editContext.contentEditorItem.id,
|
|
206
|
+
language: editContext.contentEditorItem.language,
|
|
207
|
+
version: editContext.contentEditorItem.version,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
editContext.reviews.loadReviews();
|
|
211
|
+
overlayPanelRef.current?.hide();
|
|
212
|
+
setNewReviewer({
|
|
213
|
+
email: "",
|
|
214
|
+
name: "",
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
setWaiting(false);
|
|
218
|
+
}}
|
|
219
|
+
/>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
</OverlayPanel>
|
|
223
|
+
<div className="flex-1 relative">
|
|
224
|
+
<div className="absolute inset-0 overflow-auto">
|
|
225
|
+
<SimpleTable
|
|
226
|
+
columns={[
|
|
227
|
+
{
|
|
228
|
+
header: (
|
|
229
|
+
<Checkbox
|
|
230
|
+
checked={reviewData.every((x) => x.checked)}
|
|
231
|
+
onChange={(e) => {
|
|
232
|
+
setReviewData((reviews) =>
|
|
233
|
+
reviews.map((x) => ({
|
|
234
|
+
...x,
|
|
235
|
+
checked: e.checked ?? false,
|
|
236
|
+
}))
|
|
237
|
+
);
|
|
238
|
+
}}
|
|
239
|
+
/>
|
|
240
|
+
),
|
|
241
|
+
body: (x) => (
|
|
242
|
+
<Checkbox
|
|
243
|
+
checked={x.checked}
|
|
244
|
+
onChange={(e) => {
|
|
245
|
+
setReviewData((reviews) => {
|
|
246
|
+
// It’s safer to update by index or assign an id to each reviewer.
|
|
247
|
+
// For brevity, we’re using the email to locate the reviewer.
|
|
248
|
+
const index = reviews.findIndex(
|
|
249
|
+
(y) =>
|
|
250
|
+
y.review?.reviewerEmail === x.review?.reviewerEmail
|
|
251
|
+
);
|
|
252
|
+
if (index !== -1) {
|
|
253
|
+
reviews[index]!.checked = e.checked ?? false;
|
|
254
|
+
}
|
|
255
|
+
return [...reviews];
|
|
256
|
+
});
|
|
257
|
+
}}
|
|
258
|
+
/>
|
|
259
|
+
),
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
header: "Name",
|
|
263
|
+
body: (x) => x.review?.reviewerName,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
header: "Email",
|
|
267
|
+
body: (x) => x.review?.reviewerEmail,
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
header: "Status",
|
|
271
|
+
body: (z) => getStatus(z),
|
|
272
|
+
},
|
|
273
|
+
]}
|
|
274
|
+
items={reviewData}
|
|
275
|
+
/>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Command, CommandContext, CommandData } from "../commands/commands";
|
|
2
|
+
import { approveReview, rejectReview } from "../services/reviewsService";
|
|
3
|
+
|
|
4
|
+
export const approveReviewCommand: Command<CommandData> = {
|
|
5
|
+
id: "approveReview",
|
|
6
|
+
label: "Approve Page",
|
|
7
|
+
icon: <i className="pi pi-check text-green-500 mr-3" />,
|
|
8
|
+
execute: async (context: CommandContext<CommandData>) => {
|
|
9
|
+
if (!context.editContext.currentItemDescriptor) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
await approveReview(context.editContext.currentItemDescriptor);
|
|
13
|
+
context.editContext.showToast({
|
|
14
|
+
summary: "Page/item approved",
|
|
15
|
+
severity: "success",
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
disabled: (context) => {
|
|
19
|
+
return !isReviewer(context);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const rejectReviewCommand: Command<CommandData> = {
|
|
23
|
+
id: "rejectReview",
|
|
24
|
+
label: "Reject Page",
|
|
25
|
+
icon: <i className="pi pi-times text-red-500 mr-3" />,
|
|
26
|
+
execute: async (context: CommandContext<CommandData>) => {
|
|
27
|
+
if (!context.editContext.currentItemDescriptor) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await rejectReview(context.editContext.currentItemDescriptor);
|
|
31
|
+
context.editContext.showToast({
|
|
32
|
+
summary: "Page/item rejected",
|
|
33
|
+
severity: "error",
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
disabled: (context) => {
|
|
37
|
+
return !isReviewer(context);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function isReviewer(context: CommandContext<CommandData>) {
|
|
42
|
+
return (
|
|
43
|
+
context.editContext.reviews.reviews.find(
|
|
44
|
+
(x) => x.reviewerEmail === context.editContext.user?.email
|
|
45
|
+
) !== undefined
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useEffect, useState, useMemo } from "react";
|
|
2
|
+
import { getReviewers, getReviews } from "../services/reviewsService";
|
|
3
|
+
|
|
4
|
+
import { Review } from "../../types";
|
|
5
|
+
import uuid from "react-uuid";
|
|
6
|
+
import { ItemDescriptor } from "../pageModel";
|
|
7
|
+
|
|
8
|
+
export function useReviews({
|
|
9
|
+
currentItemDescriptor,
|
|
10
|
+
addSocketMessageListener,
|
|
11
|
+
}: {
|
|
12
|
+
currentItemDescriptor?: ItemDescriptor;
|
|
13
|
+
addSocketMessageListener: (
|
|
14
|
+
callback: (message: { type: string; payload: any }) => void
|
|
15
|
+
) => void;
|
|
16
|
+
}) {
|
|
17
|
+
const [reviews, setReviews] = useState<Review[]>([]);
|
|
18
|
+
|
|
19
|
+
const loadReviews = async () => {
|
|
20
|
+
if (!currentItemDescriptor) return;
|
|
21
|
+
const reviewers = await getReviewers(
|
|
22
|
+
currentItemDescriptor.id,
|
|
23
|
+
currentItemDescriptor.language
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const reviewsResult = await getReviews(
|
|
27
|
+
currentItemDescriptor.id,
|
|
28
|
+
currentItemDescriptor.language,
|
|
29
|
+
currentItemDescriptor.version
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const reviews = reviewsResult.data;
|
|
33
|
+
|
|
34
|
+
if (!reviews) return;
|
|
35
|
+
|
|
36
|
+
reviewers.data?.forEach((reviewer) => {
|
|
37
|
+
if (!currentItemDescriptor) return;
|
|
38
|
+
const existingReview = reviews.find(
|
|
39
|
+
(r) => r.reviewerEmail === reviewer.email
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!existingReview) {
|
|
43
|
+
reviews.push({
|
|
44
|
+
id: uuid(),
|
|
45
|
+
itemId: currentItemDescriptor.id,
|
|
46
|
+
language: currentItemDescriptor.language,
|
|
47
|
+
version: currentItemDescriptor.version,
|
|
48
|
+
reviewerName: reviewer.name,
|
|
49
|
+
reviewerEmail: reviewer.email,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
setReviews(reviews);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
loadReviews();
|
|
59
|
+
}, [currentItemDescriptor]);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return addSocketMessageListener((message) => {
|
|
63
|
+
if (message.type === "reviews-updated") {
|
|
64
|
+
loadReviews();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}, [currentItemDescriptor]);
|
|
68
|
+
|
|
69
|
+
return useMemo(() => ({ reviews, loadReviews }), [reviews]);
|
|
70
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { AiContext } from "../ai/AiTerminal";
|
|
2
|
+
import { EditContextType } from "../client/editContext";
|
|
3
|
+
import { ItemDescriptor } from "../pageModel";
|
|
4
|
+
import { ExecutionResult, post } from "./serviceHelper";
|
|
5
|
+
|
|
6
|
+
export type AiProfile = {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
instructions: string;
|
|
10
|
+
defaultModel: string;
|
|
11
|
+
models: string[];
|
|
12
|
+
prompts: { prompt: string; title: string }[];
|
|
13
|
+
errorMessage?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function loadAiProfiles(
|
|
17
|
+
item: ItemDescriptor
|
|
18
|
+
): Promise<AiProfile[]> {
|
|
19
|
+
let url = "/alpaca/editor/ai/profiles";
|
|
20
|
+
|
|
21
|
+
const response = await post<AiProfile[]>(url, item);
|
|
22
|
+
|
|
23
|
+
if (response.type !== "success") {
|
|
24
|
+
throw new Error("Error loading AI profiles");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return response.data || [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Message = {
|
|
31
|
+
content: string;
|
|
32
|
+
name: string;
|
|
33
|
+
role: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export async function executePrompt(
|
|
37
|
+
messages: Message[],
|
|
38
|
+
editContext: EditContextType,
|
|
39
|
+
createAiContext: ({ editContext }: { editContext: any }) => AiContext,
|
|
40
|
+
allowedFunctions?: string[],
|
|
41
|
+
addContextContent?: boolean,
|
|
42
|
+
options?: RequestInit,
|
|
43
|
+
model?: string,
|
|
44
|
+
callback?: (response: any) => void
|
|
45
|
+
): Promise<any> {
|
|
46
|
+
const context = createAiContext({ editContext });
|
|
47
|
+
|
|
48
|
+
const response = await fetch(context.endpoint, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
messages,
|
|
52
|
+
...context.promptData,
|
|
53
|
+
selection: editContext.selection,
|
|
54
|
+
sessionId: editContext.sessionId,
|
|
55
|
+
allowedFunctions,
|
|
56
|
+
addContextContent,
|
|
57
|
+
model,
|
|
58
|
+
}),
|
|
59
|
+
|
|
60
|
+
credentials: "include",
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
},
|
|
64
|
+
...options,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (!response?.body) return null;
|
|
68
|
+
|
|
69
|
+
const reader = response.body.getReader();
|
|
70
|
+
const decoder = new TextDecoder();
|
|
71
|
+
let buffer = "";
|
|
72
|
+
|
|
73
|
+
let result = null;
|
|
74
|
+
|
|
75
|
+
while (true) {
|
|
76
|
+
const { done, value } = await reader.read();
|
|
77
|
+
|
|
78
|
+
if (done) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
buffer += decoder.decode(value, { stream: true }); // 'stream: true' ensures that any incomplete multi-byte characters aren't malformed.
|
|
83
|
+
|
|
84
|
+
// Split the buffer by newline and keep the last partial line for the next iteration.
|
|
85
|
+
const lines = buffer.split("\n");
|
|
86
|
+
|
|
87
|
+
if (lines.length > 0) {
|
|
88
|
+
buffer = lines.pop() || ""; // Incomplete line (if any) is kept for the next iteration.
|
|
89
|
+
|
|
90
|
+
for (let line of lines) {
|
|
91
|
+
if (line.trim() === "") continue; // Skip empty lines if any.
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const jsonData = JSON.parse(line);
|
|
95
|
+
callback?.(jsonData);
|
|
96
|
+
result = jsonData;
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error("Error parsing line:" + line, e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// If there's any remaining content in the buffer after processing all chunks, try to process it.
|
|
105
|
+
if (buffer.trim() !== "") {
|
|
106
|
+
try {
|
|
107
|
+
const jsonData = JSON.parse(buffer);
|
|
108
|
+
result = jsonData;
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.error("Error parsing the final buffer content:", e);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function executeSearch({
|
|
118
|
+
query,
|
|
119
|
+
editContext,
|
|
120
|
+
maxResults = 10,
|
|
121
|
+
index,
|
|
122
|
+
rootItemIds,
|
|
123
|
+
skipValidation = false,
|
|
124
|
+
}: {
|
|
125
|
+
query: string;
|
|
126
|
+
editContext: EditContextType;
|
|
127
|
+
maxResults: number;
|
|
128
|
+
index: string;
|
|
129
|
+
rootItemIds?: string[];
|
|
130
|
+
skipValidation?: boolean;
|
|
131
|
+
}): Promise<ExecutionResult<unknown>> {
|
|
132
|
+
const response = await fetch("/alpaca/editor/ai/search", {
|
|
133
|
+
method: "POST",
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
contextItem: {
|
|
136
|
+
id: editContext.currentItemDescriptor?.id,
|
|
137
|
+
language: "en",
|
|
138
|
+
version: 0,
|
|
139
|
+
},
|
|
140
|
+
query,
|
|
141
|
+
index,
|
|
142
|
+
maxResults,
|
|
143
|
+
rootItemIds,
|
|
144
|
+
skipValidation,
|
|
145
|
+
}),
|
|
146
|
+
credentials: "include",
|
|
147
|
+
headers: {
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
if (!response.ok) return { type: "error", response };
|
|
153
|
+
|
|
154
|
+
return { type: "success", response, data: await response.json() };
|
|
155
|
+
}
|