@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,53 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
import { SimpleTable } from "../ui/SimpleTable";
|
|
3
|
+
|
|
4
|
+
export function Performance() {
|
|
5
|
+
const context = useEditContext();
|
|
6
|
+
if (!context?.timings) return null;
|
|
7
|
+
|
|
8
|
+
const values = Object.keys(context.timings).map((key) => ({
|
|
9
|
+
key,
|
|
10
|
+
value: Math.round(context.timings[key]!),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const columns = [
|
|
14
|
+
{
|
|
15
|
+
body: (entry: any) => {
|
|
16
|
+
if (
|
|
17
|
+
/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/.test(
|
|
18
|
+
entry.key
|
|
19
|
+
)
|
|
20
|
+
) {
|
|
21
|
+
const ids = entry.key
|
|
22
|
+
.split("_")
|
|
23
|
+
.filter((part: string) =>
|
|
24
|
+
/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/.test(
|
|
25
|
+
part
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
className="cursor-pointer"
|
|
31
|
+
onClick={() => context.select(ids)}
|
|
32
|
+
>
|
|
33
|
+
{entry.key}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return entry.key;
|
|
39
|
+
},
|
|
40
|
+
header: "Metric",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
body: (entry: any) => entry.value,
|
|
44
|
+
header: "Time (ms)",
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="overflow-x-auto">
|
|
50
|
+
<SimpleTable items={values} columns={columns} />
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
import { EditSession } from "../../types";
|
|
3
|
+
import { SimpleTable } from "../ui/SimpleTable";
|
|
4
|
+
|
|
5
|
+
export function Sessions() {
|
|
6
|
+
var editContext = useEditContext();
|
|
7
|
+
if (!editContext) return null;
|
|
8
|
+
const sessions = editContext?.activeSessions;
|
|
9
|
+
const columns = [
|
|
10
|
+
{ body: (session: EditSession) => session.user?.name, header: "User" },
|
|
11
|
+
{
|
|
12
|
+
body: (session: EditSession) => (
|
|
13
|
+
<a
|
|
14
|
+
href="#"
|
|
15
|
+
onClick={() => {
|
|
16
|
+
if (session.item) editContext?.loadItem(session.item);
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
{session.item?.name}
|
|
20
|
+
</a>
|
|
21
|
+
),
|
|
22
|
+
header: "Page",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
body: (session: EditSession) => session.item?.language,
|
|
26
|
+
header: "Language",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
body: (session: EditSession) => session.item?.version,
|
|
30
|
+
header: "Version",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
return <SimpleTable items={sessions} columns={columns} />;
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
|
|
3
|
+
import { SidebarView } from "./SidebarView";
|
|
4
|
+
|
|
5
|
+
export function Sidebar() {
|
|
6
|
+
var editContext = useEditContext();
|
|
7
|
+
if (!editContext) return null;
|
|
8
|
+
|
|
9
|
+
const view = editContext.view;
|
|
10
|
+
|
|
11
|
+
if (!view || !view.leftSidebar) return null;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<SidebarView
|
|
15
|
+
sidebar={view.leftSidebar}
|
|
16
|
+
editContext={editContext}
|
|
17
|
+
active={true}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import "allotment/dist/style.css";
|
|
2
|
+
import { Allotment, AllotmentHandle } from "allotment";
|
|
3
|
+
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { EditContextType } from "../client/editContext";
|
|
6
|
+
import { classNames } from "primereact/utils";
|
|
7
|
+
import { Sidebar } from "../../config/types";
|
|
8
|
+
|
|
9
|
+
export function SidebarView({
|
|
10
|
+
sidebar,
|
|
11
|
+
editContext,
|
|
12
|
+
active,
|
|
13
|
+
}: {
|
|
14
|
+
sidebar: Sidebar;
|
|
15
|
+
editContext: EditContextType;
|
|
16
|
+
active: boolean;
|
|
17
|
+
}) {
|
|
18
|
+
const splitter = useRef<AllotmentHandle>(null);
|
|
19
|
+
|
|
20
|
+
const [sizes, setSizes] = useState<number[]>([]);
|
|
21
|
+
const [preferredSizes, setPreferredSizes] = useState<number[] | undefined>(
|
|
22
|
+
undefined
|
|
23
|
+
);
|
|
24
|
+
const [panelsExpanded, setPanelsExpanded] = useState<boolean[]>([]);
|
|
25
|
+
const [sizeToSet, setSizeToSet] = useState<number[] | undefined>();
|
|
26
|
+
|
|
27
|
+
const panelHeaderSize = 40;
|
|
28
|
+
const toggle = (panelIndex: number) => {
|
|
29
|
+
const newSize = panelsExpanded[panelIndex]
|
|
30
|
+
? panelHeaderSize
|
|
31
|
+
: (preferredSizes || sizes)[panelIndex];
|
|
32
|
+
|
|
33
|
+
if (newSize) resizePanel(panelIndex, newSize);
|
|
34
|
+
|
|
35
|
+
setPanelsExpanded((x) => {
|
|
36
|
+
const newState = [...x];
|
|
37
|
+
newState[panelIndex] = !newState[panelIndex];
|
|
38
|
+
return newState;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const resolvedPanels = sidebar.panels.map((x) => {
|
|
43
|
+
if (typeof x === "function") {
|
|
44
|
+
return x(editContext!);
|
|
45
|
+
}
|
|
46
|
+
return x;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
setPanelsExpanded(sidebar.panels.map(() => true));
|
|
51
|
+
setPreferredSizes(() => resolvedPanels.map((x) => x.initialSize));
|
|
52
|
+
}, [sidebar]);
|
|
53
|
+
|
|
54
|
+
const resizePanel = (panelIndex: number, newSize: number) => {
|
|
55
|
+
const totalSize = sizes.reduce((a, b) => a + b, 0);
|
|
56
|
+
const totalOther = totalSize - sizes[panelIndex]!;
|
|
57
|
+
const tmpSizes = [...sizes];
|
|
58
|
+
tmpSizes[panelIndex] = newSize;
|
|
59
|
+
const percentages = tmpSizes.map((x) => x / totalOther);
|
|
60
|
+
percentages[panelIndex] = 0;
|
|
61
|
+
const remaining = totalSize - newSize;
|
|
62
|
+
const newSizes = percentages.map((x) => x * remaining);
|
|
63
|
+
newSizes[panelIndex] = newSize;
|
|
64
|
+
setSizes(newSizes);
|
|
65
|
+
|
|
66
|
+
setSizeToSet(newSizes);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (sizeToSet) splitter.current?.resize(sizeToSet);
|
|
71
|
+
}, [sizeToSet]);
|
|
72
|
+
|
|
73
|
+
const getHeader = (panel: any, index: number) => {
|
|
74
|
+
if (panel.header) return panel.header({ panel, index });
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div
|
|
78
|
+
className={classNames(
|
|
79
|
+
" p-2.5 bg-gray-50 uppercase text-gray-500 text-xs flex justify items-center cursor-pointer relative",
|
|
80
|
+
panelsExpanded[index] ? "border-b border-gray-200" : ""
|
|
81
|
+
)}
|
|
82
|
+
onClick={() => toggle(index)}
|
|
83
|
+
>
|
|
84
|
+
{panel.icon &&
|
|
85
|
+
(typeof panel.icon === "string" ? (
|
|
86
|
+
<i className={classNames(panel.icon, "pi mr-1.5")}></i>
|
|
87
|
+
) : (
|
|
88
|
+
<div className="w-4 h-4 mr-2">{panel.icon}</div>
|
|
89
|
+
))}
|
|
90
|
+
<div className="mr-auto">{panel.title}</div>
|
|
91
|
+
<i
|
|
92
|
+
className={classNames(
|
|
93
|
+
panelsExpanded[index] ? "pi-chevron-up" : "pi-chevron-down",
|
|
94
|
+
"pi text-sm"
|
|
95
|
+
)}
|
|
96
|
+
></i>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const initalSizes = resolvedPanels.map((x) => x.initialSize);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Allotment
|
|
105
|
+
vertical={true}
|
|
106
|
+
snap={true}
|
|
107
|
+
className={!active ? "hidden h-full" : "h-full"}
|
|
108
|
+
ref={splitter}
|
|
109
|
+
defaultSizes={initalSizes}
|
|
110
|
+
onChange={(s) => {
|
|
111
|
+
if (sizes.join(",") != s.join(",")) setSizes(s);
|
|
112
|
+
|
|
113
|
+
const newPreferred = [...(preferredSizes || s)];
|
|
114
|
+
s.forEach((x, i) => {
|
|
115
|
+
if (x > panelHeaderSize) newPreferred[i] = x;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
setPreferredSizes(newPreferred);
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
{resolvedPanels.map((panel, index) => (
|
|
122
|
+
<Allotment.Pane
|
|
123
|
+
key={index}
|
|
124
|
+
// preferredSize={(preferredSizes || initalSizes)[index] + "%"}
|
|
125
|
+
maxSize={
|
|
126
|
+
panelsExpanded.length <= index || panelsExpanded[index]
|
|
127
|
+
? 10000
|
|
128
|
+
: panelHeaderSize
|
|
129
|
+
}
|
|
130
|
+
>
|
|
131
|
+
<div className="flex flex-col h-full">
|
|
132
|
+
{getHeader(panel, index)}
|
|
133
|
+
{panelsExpanded[index] && (
|
|
134
|
+
<div className="overflow-hidden relative flex-1">
|
|
135
|
+
<div
|
|
136
|
+
className={classNames(
|
|
137
|
+
"inset-0 absolute",
|
|
138
|
+
panel.noOverflow ? "" : "overflow-y-auto"
|
|
139
|
+
)}
|
|
140
|
+
>
|
|
141
|
+
{panel.content}
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
</Allotment.Pane>
|
|
147
|
+
))}
|
|
148
|
+
</Allotment>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Button } from "primereact/button";
|
|
2
|
+
import { useEditContext } from "../client/editContext";
|
|
3
|
+
import { Language } from "../pageModel";
|
|
4
|
+
import { SimpleTable } from "../ui/SimpleTable";
|
|
5
|
+
import {
|
|
6
|
+
getTranslationStatus,
|
|
7
|
+
requestTranslation,
|
|
8
|
+
getTranslationProviders,
|
|
9
|
+
} from "../services/translationService";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { TranslationStatus } from "../../config/types";
|
|
12
|
+
|
|
13
|
+
import { ProgressBar } from "primereact/progressbar";
|
|
14
|
+
import { Checkbox } from "primereact/checkbox";
|
|
15
|
+
import { confirmCreateVersion } from "../utils/itemutils";
|
|
16
|
+
import { Dropdown } from "primereact/dropdown";
|
|
17
|
+
|
|
18
|
+
export function Translation() {
|
|
19
|
+
const editContext = useEditContext();
|
|
20
|
+
const [translationStatus, setTranslationStatus] = useState<
|
|
21
|
+
TranslationStatus[] | null
|
|
22
|
+
>(null);
|
|
23
|
+
const [translationProviders, setTranslationProviders] = useState<
|
|
24
|
+
string[] | null
|
|
25
|
+
>(null);
|
|
26
|
+
|
|
27
|
+
const [translationProvider, setTranslationProvider] = useState<string | null>(
|
|
28
|
+
localStorage.getItem("editor.translationProvider") || null
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (!editContext) return null;
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (translationProvider) {
|
|
35
|
+
localStorage.setItem("editor.translationProvider", translationProvider);
|
|
36
|
+
}
|
|
37
|
+
}, [translationProvider]);
|
|
38
|
+
|
|
39
|
+
const languages = editContext?.itemLanguages || [];
|
|
40
|
+
|
|
41
|
+
type TranslationProgress = {
|
|
42
|
+
progress: number;
|
|
43
|
+
message: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const [translationProgress, setTranslationProgress] = useState<
|
|
47
|
+
Map<string, TranslationProgress>
|
|
48
|
+
>(new Map());
|
|
49
|
+
|
|
50
|
+
const item = editContext.contentEditorItem;
|
|
51
|
+
const [checkedLanguages, setCheckedLanguages] = useState<string[]>([]);
|
|
52
|
+
|
|
53
|
+
const selectLanguage = (language: Language) => {
|
|
54
|
+
if (!item) return;
|
|
55
|
+
if (!language.versions) {
|
|
56
|
+
confirmCreateVersion(editContext, language);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
editContext.loadItem({
|
|
61
|
+
...item.descriptor,
|
|
62
|
+
language: language.languageCode,
|
|
63
|
+
version: 0,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const languageName = (language: Language) => {
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
key={language.languageCode}
|
|
71
|
+
className=" flex gap-2"
|
|
72
|
+
onClick={() => selectLanguage(language)}
|
|
73
|
+
>
|
|
74
|
+
<img src={language.icon} className="h-5" /> {language.name}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const translate = async (languageCode: string) => {
|
|
80
|
+
if (!item) return;
|
|
81
|
+
|
|
82
|
+
const status = translationStatus?.find(
|
|
83
|
+
(x) => x.targetLanguage === languageCode
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (!status) return;
|
|
87
|
+
|
|
88
|
+
if (status.sourceLanguage === languageCode) return;
|
|
89
|
+
|
|
90
|
+
setTranslationProgress((p) => {
|
|
91
|
+
p.set(languageCode, { progress: 0, message: "" });
|
|
92
|
+
return new Map(p);
|
|
93
|
+
});
|
|
94
|
+
await requestTranslation({
|
|
95
|
+
itemId: item.descriptor.id,
|
|
96
|
+
targetLanguage: languageCode,
|
|
97
|
+
sourceLanguage: status.sourceLanguage,
|
|
98
|
+
sessionId: editContext.sessionId,
|
|
99
|
+
provider: translationProvider || "",
|
|
100
|
+
});
|
|
101
|
+
loadTranslationStatus();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const loadTranslationStatus = async () => {
|
|
105
|
+
if (!item) return;
|
|
106
|
+
const status = await getTranslationStatus(item.descriptor.id);
|
|
107
|
+
setTranslationStatus(status.data || []);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const loadTranslationProviders = async () => {
|
|
111
|
+
const providers = await getTranslationProviders();
|
|
112
|
+
setTranslationProviders(providers.data || []);
|
|
113
|
+
if (!translationProvider) {
|
|
114
|
+
setTranslationProvider(providers.data?.[0] || null);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const createVersions = async () => {
|
|
119
|
+
if (!item) return;
|
|
120
|
+
checkedLanguages.forEach((language) => {
|
|
121
|
+
editContext.operations.createVersion({
|
|
122
|
+
id: item.descriptor.id,
|
|
123
|
+
language: language,
|
|
124
|
+
version: 0,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
loadTranslationStatus();
|
|
131
|
+
setTranslationProgress(new Map());
|
|
132
|
+
}, [editContext.currentItemDescriptor?.id]);
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
loadTranslationProviders();
|
|
136
|
+
}, []);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
const removeSocketMessageListener = editContext.addSocketMessageListener(
|
|
140
|
+
(message) => {
|
|
141
|
+
if (
|
|
142
|
+
message.type === "translation-started" ||
|
|
143
|
+
message.type === "translation-finished" ||
|
|
144
|
+
message.type === "translation-error"
|
|
145
|
+
) {
|
|
146
|
+
if (message.payload.itemId === item?.descriptor.id) {
|
|
147
|
+
loadTranslationStatus();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (message.type === "translation-progress") {
|
|
152
|
+
if (message.payload.itemId === item?.descriptor.id) {
|
|
153
|
+
setTranslationProgress((p) => {
|
|
154
|
+
p.set(message.payload.language, message.payload);
|
|
155
|
+
return new Map(p);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
return removeSocketMessageListener;
|
|
162
|
+
}, [editContext, setTranslationProgress]);
|
|
163
|
+
|
|
164
|
+
const languageData = languages.map((x) => ({
|
|
165
|
+
...x,
|
|
166
|
+
translationStatus: translationStatus?.find(
|
|
167
|
+
(y) => y.targetLanguage === x.languageCode
|
|
168
|
+
),
|
|
169
|
+
translationProgress: translationProgress.get(x.languageCode),
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
languageData.sort((a, b) => {
|
|
173
|
+
// Sort languages with 0 versions to bottom
|
|
174
|
+
if (a.versions === 0 && b.versions > 0) return 1;
|
|
175
|
+
if (b.versions === 0 && a.versions > 0) return -1;
|
|
176
|
+
|
|
177
|
+
// Sort by name for languages that both have versions or both don't
|
|
178
|
+
return a.name.localeCompare(b.name);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div className="flex flex-col gap-2 h-full">
|
|
183
|
+
<div className="flex p-3 gap-2 justify-end items-center w-full bg-gray-50 flex-wrap">
|
|
184
|
+
<Dropdown
|
|
185
|
+
options={translationProviders || []}
|
|
186
|
+
onChange={(e) => setTranslationProvider(e.value)}
|
|
187
|
+
value={translationProvider}
|
|
188
|
+
/>
|
|
189
|
+
<Button
|
|
190
|
+
size="small"
|
|
191
|
+
icon="pi pi-sparkles"
|
|
192
|
+
onClick={() => {
|
|
193
|
+
checkedLanguages.forEach((x) => translate(x));
|
|
194
|
+
setCheckedLanguages([]);
|
|
195
|
+
}}
|
|
196
|
+
disabled={checkedLanguages.length === 0}
|
|
197
|
+
label="Translate"
|
|
198
|
+
/>
|
|
199
|
+
<Button
|
|
200
|
+
size="small"
|
|
201
|
+
icon="pi pi-plus"
|
|
202
|
+
onClick={() => {
|
|
203
|
+
createVersions();
|
|
204
|
+
setCheckedLanguages([]);
|
|
205
|
+
}}
|
|
206
|
+
disabled={checkedLanguages.length === 0}
|
|
207
|
+
label="Create Versions"
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
<div className="flex-1 relative">
|
|
211
|
+
<div className="overflow-y-auto absolute inset-0">
|
|
212
|
+
<SimpleTable
|
|
213
|
+
columns={[
|
|
214
|
+
{
|
|
215
|
+
header: "",
|
|
216
|
+
body: (x) => (
|
|
217
|
+
<div onClick={(e) => e.stopPropagation()}>
|
|
218
|
+
<Checkbox
|
|
219
|
+
checked={checkedLanguages.includes(x.languageCode)}
|
|
220
|
+
onChange={(ev) => {
|
|
221
|
+
setCheckedLanguages(
|
|
222
|
+
ev.checked
|
|
223
|
+
? [...checkedLanguages, x.languageCode]
|
|
224
|
+
: checkedLanguages.filter(
|
|
225
|
+
(y) => y !== x.languageCode
|
|
226
|
+
)
|
|
227
|
+
);
|
|
228
|
+
}}
|
|
229
|
+
/>
|
|
230
|
+
</div>
|
|
231
|
+
),
|
|
232
|
+
},
|
|
233
|
+
{ header: "Language", body: languageName },
|
|
234
|
+
{ header: "Ver.", body: (x) => x.versions.toString() },
|
|
235
|
+
{
|
|
236
|
+
header: "Src",
|
|
237
|
+
body: (x) => x.translationStatus?.sourceLanguage,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
header: "Status",
|
|
241
|
+
body: (x) => (
|
|
242
|
+
<div className="flex items-center gap-2">
|
|
243
|
+
{x.translationStatus?.status === "In Progress" && (
|
|
244
|
+
<div className="w-full relative">
|
|
245
|
+
<ProgressBar
|
|
246
|
+
style={{ height: "20px" }}
|
|
247
|
+
value={(x.translationProgress?.progress || 0) * 100}
|
|
248
|
+
showValue={false}
|
|
249
|
+
/>
|
|
250
|
+
<div className="absolute inset-0 flex items-center justify-center text-white">
|
|
251
|
+
{x.translationProgress?.message}
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
{x.translationStatus?.status !== "In Progress" && (
|
|
256
|
+
<div title={x.translationStatus?.message}>
|
|
257
|
+
{x.translationStatus?.status || "Not started"}
|
|
258
|
+
</div>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
),
|
|
262
|
+
},
|
|
263
|
+
]}
|
|
264
|
+
items={languageData}
|
|
265
|
+
onRowClick={(data) => selectLanguage(data.item)}
|
|
266
|
+
rowClassName={(item) =>
|
|
267
|
+
item.languageCode == editContext.currentItemDescriptor?.language
|
|
268
|
+
? "bg-neutral-100"
|
|
269
|
+
: ""
|
|
270
|
+
}
|
|
271
|
+
/>
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ProgressSpinner } from "primereact/progressspinner";
|
|
2
|
+
import { SingleValidatorResult } from "../../types";
|
|
3
|
+
import { useEditContext } from "../client/editContext";
|
|
4
|
+
import { SimpleTable } from "../ui/SimpleTable";
|
|
5
|
+
|
|
6
|
+
type SingleResult = SingleValidatorResult & {
|
|
7
|
+
language: string;
|
|
8
|
+
version: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function Validation() {
|
|
12
|
+
const editContext = useEditContext();
|
|
13
|
+
const validationResults = editContext?.validationResult?.flatMap((x) =>
|
|
14
|
+
x.results.map((y) => ({
|
|
15
|
+
...y,
|
|
16
|
+
language: x.item.language,
|
|
17
|
+
version: x.item.version,
|
|
18
|
+
}))
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (!validationResults) return null;
|
|
22
|
+
|
|
23
|
+
const nameBodyTemplate = (validationResult: SingleResult) => {
|
|
24
|
+
const id =
|
|
25
|
+
validationResult.itemId +
|
|
26
|
+
validationResult.language +
|
|
27
|
+
validationResult.version;
|
|
28
|
+
return (
|
|
29
|
+
<div className="flex gap-2 items-center">
|
|
30
|
+
<span
|
|
31
|
+
className={`name-tooltip-${id} break-all`}
|
|
32
|
+
style={{ position: "relative" }}
|
|
33
|
+
>
|
|
34
|
+
{validationResult.itemName}{" "}
|
|
35
|
+
<span className="text-gray-500">
|
|
36
|
+
({validationResult.language}, {validationResult.itemName})
|
|
37
|
+
</span>
|
|
38
|
+
</span>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const validationTemplate = (validationResult: SingleResult) => {
|
|
44
|
+
return <div>{validationResult.message}</div>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const columns = [
|
|
48
|
+
{ body: nameBodyTemplate, header: "Item" },
|
|
49
|
+
{
|
|
50
|
+
body: validationTemplate,
|
|
51
|
+
align: "center",
|
|
52
|
+
header: <i className="pi pi-check" />,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
if (validationResults.length === 0) {
|
|
57
|
+
return (
|
|
58
|
+
<div className="text-gray-600 text-sm text-center p-4">
|
|
59
|
+
No validation results
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div>
|
|
66
|
+
{editContext?.validating && (
|
|
67
|
+
<div className="text-center p-3">
|
|
68
|
+
<ProgressSpinner style={{ width: "20px", height: "20px" }} />
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
{!editContext?.validating && (
|
|
72
|
+
<SimpleTable
|
|
73
|
+
items={validationResults}
|
|
74
|
+
columns={columns}
|
|
75
|
+
onRowClick={async (data) => {
|
|
76
|
+
const itemDescriptor = {
|
|
77
|
+
id: data.item.itemId,
|
|
78
|
+
language: data.item.language,
|
|
79
|
+
version: data.item.version,
|
|
80
|
+
};
|
|
81
|
+
const item = await editContext?.itemsRepository.getItem(
|
|
82
|
+
itemDescriptor
|
|
83
|
+
);
|
|
84
|
+
if (!item || !editContext) return;
|
|
85
|
+
editContext.setCenterPanelView(
|
|
86
|
+
editContext.configuration.editor.views.find(
|
|
87
|
+
(x) => x.name === "content-editor"
|
|
88
|
+
)?.defaultCenterPanelView
|
|
89
|
+
);
|
|
90
|
+
editContext.setFocusedField(
|
|
91
|
+
{
|
|
92
|
+
item: itemDescriptor,
|
|
93
|
+
fieldId: data.item.fieldId,
|
|
94
|
+
},
|
|
95
|
+
true
|
|
96
|
+
);
|
|
97
|
+
}}
|
|
98
|
+
></SimpleTable>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { classNames } from "primereact/utils";
|
|
2
|
+
|
|
3
|
+
import { useEditContext } from "../client/editContext";
|
|
4
|
+
|
|
5
|
+
export function ViewSelector() {
|
|
6
|
+
const editContext = useEditContext();
|
|
7
|
+
|
|
8
|
+
const views =
|
|
9
|
+
editContext?.configuration.editor.views.filter((x) => !x.hidden) ?? [];
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="shadow-right-soft z-10 flex w-11 max-w-11 flex-col gap-1 bg-gray-100">
|
|
13
|
+
{views
|
|
14
|
+
.filter((x) => x.icon)
|
|
15
|
+
.map((x, i) => (
|
|
16
|
+
<div
|
|
17
|
+
title={x.title}
|
|
18
|
+
key={i}
|
|
19
|
+
className={classNames(
|
|
20
|
+
editContext?.viewName == x.name
|
|
21
|
+
? "active text-gray-900"
|
|
22
|
+
: "text-gray-400 hover:text-gray-900",
|
|
23
|
+
"cursor-pointer p-3",
|
|
24
|
+
)}
|
|
25
|
+
data-sidebarview-name={x.name}
|
|
26
|
+
onClick={() => editContext?.switchView(x.name)}
|
|
27
|
+
>
|
|
28
|
+
{typeof x.icon === "string" ? (
|
|
29
|
+
<i
|
|
30
|
+
className={classNames(x.icon)}
|
|
31
|
+
style={{ fontSize: "1.25rem" }}
|
|
32
|
+
/>
|
|
33
|
+
) : (
|
|
34
|
+
x.icon
|
|
35
|
+
)}
|
|
36
|
+
</div>
|
|
37
|
+
))}
|
|
38
|
+
{/* <div
|
|
39
|
+
title="Tour"
|
|
40
|
+
className={
|
|
41
|
+
"text-gray-400 hover:text-gray-900 cursor-pointer p-3"
|
|
42
|
+
}
|
|
43
|
+
onClick={() => editContext!.startTour()}
|
|
44
|
+
>
|
|
45
|
+
<i className="pi pi-question-circle text-xl" />
|
|
46
|
+
</div> */}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|