@alpaca-editor/core 1.0.3942 → 1.0.3943
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/build.css +3 -0
- package/components.json +21 -0
- package/dist/editor/ContentTree.d.ts +2 -1
- package/dist/editor/ContentTree.js +23 -21
- package/dist/editor/ContentTree.js.map +1 -1
- package/dist/editor/FieldActionsOverlay.js +0 -2
- package/dist/editor/FieldActionsOverlay.js.map +1 -1
- package/dist/editor/ScrollingContentTree.js +1 -1
- package/dist/editor/ScrollingContentTree.js.map +1 -1
- package/dist/editor/Titlebar.js +1 -1
- package/dist/editor/Titlebar.js.map +1 -1
- package/dist/editor/ai/GhostWriter.js +24 -3
- package/dist/editor/ai/GhostWriter.js.map +1 -1
- package/dist/editor/client/EditorClient.js +7 -7
- package/dist/editor/client/EditorClient.js.map +1 -1
- package/dist/editor/field-types/InternalLinkFieldEditor.js +60 -10
- package/dist/editor/field-types/InternalLinkFieldEditor.js.map +1 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js +48 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -1
- package/dist/editor/menubar/PageSelector.js +116 -65
- package/dist/editor/menubar/PageSelector.js.map +1 -1
- package/dist/editor/page-viewer/EditorForm.js +5 -2
- package/dist/editor/page-viewer/EditorForm.js.map +1 -1
- package/dist/editor/ui/ItemSearch.js +14 -8
- package/dist/editor/ui/ItemSearch.js.map +1 -1
- package/dist/editor/ui/PerfectTree.d.ts +4 -2
- package/dist/editor/ui/PerfectTree.js +78 -4
- package/dist/editor/ui/PerfectTree.js.map +1 -1
- package/dist/editor/ui/Splitter.js +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +8 -2
- package/eslint.config.mjs +4 -0
- package/images/bg-shape-black.webp +0 -0
- package/images/wizard-bg.png +0 -0
- package/images/wizard-tour.png +0 -0
- package/images/wizard.png +0 -0
- package/package.json +2 -8
- package/src/client-components/api.ts +6 -0
- package/src/client-components/index.ts +19 -0
- package/src/components/ActionButton.tsx +50 -0
- package/src/components/Error.tsx +57 -0
- package/src/components/ui/CardConnector.tsx +56 -0
- package/src/components/ui/button.tsx +62 -0
- package/src/components/ui/card.tsx +372 -0
- package/src/components/ui/context-menu.tsx +250 -0
- package/src/config/config.tsx +917 -0
- package/src/config/types.ts +286 -0
- package/src/editor/ComponentInfo.tsx +90 -0
- package/src/editor/ConfirmationDialog.tsx +103 -0
- package/src/editor/ContentTree.tsx +733 -0
- package/src/editor/ContextMenu.tsx +230 -0
- package/src/editor/Editor.tsx +90 -0
- package/src/editor/EditorWarning.tsx +34 -0
- package/src/editor/EditorWarnings.tsx +33 -0
- package/src/editor/FieldActionsOverlay.tsx +296 -0
- package/src/editor/FieldEditorPopup.tsx +65 -0
- package/src/editor/FieldHistory.tsx +75 -0
- package/src/editor/FieldList.tsx +190 -0
- package/src/editor/FieldListField.tsx +391 -0
- package/src/editor/FieldListFieldWithFallbacks.tsx +217 -0
- package/src/editor/FloatingToolbar.tsx +163 -0
- package/src/editor/ImageEditor.tsx +128 -0
- package/src/editor/ItemInfo.tsx +90 -0
- package/src/editor/LinkEditorDialog.tsx +196 -0
- package/src/editor/MainLayout.tsx +95 -0
- package/src/editor/MobileLayout.tsx +68 -0
- package/src/editor/NewEditorClient.tsx +11 -0
- package/src/editor/PictureCropper.tsx +568 -0
- package/src/editor/PictureEditor.tsx +301 -0
- package/src/editor/PictureEditorDialog.tsx +381 -0
- package/src/editor/PublishDialog.ignore +74 -0
- package/src/editor/ScrollingContentTree.tsx +68 -0
- package/src/editor/Terminal.tsx +227 -0
- package/src/editor/Titlebar.tsx +104 -0
- package/src/editor/ai/AiPopup.tsx +59 -0
- package/src/editor/ai/AiResponseMessage.tsx +106 -0
- package/src/editor/ai/AiTerminal.tsx +503 -0
- package/src/editor/ai/AiToolCall.tsx +61 -0
- package/src/editor/ai/EditorAiTerminal.tsx +20 -0
- package/src/editor/ai/GhostWriter.tsx +480 -0
- package/src/editor/ai/aiPageModel.ts +108 -0
- package/src/editor/ai/editorAiContext.ts +18 -0
- package/src/editor/client/AboutDialog.tsx +44 -0
- package/src/editor/client/EditorClient.tsx +2241 -0
- package/src/editor/client/GenericDialog.tsx +50 -0
- package/src/editor/client/editContext.ts +416 -0
- package/src/editor/client/helpers.ts +44 -0
- package/src/editor/client/itemsRepository.ts +574 -0
- package/src/editor/client/operations.ts +768 -0
- package/src/editor/client/pageModelBuilder.ts +219 -0
- package/src/editor/commands/commands.ts +22 -0
- package/src/editor/commands/componentCommands.tsx +431 -0
- package/src/editor/commands/createVersionCommand.ts +33 -0
- package/src/editor/commands/deleteVersionCommand.ts +71 -0
- package/src/editor/commands/itemCommands.tsx +351 -0
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
- package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +27 -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 +179 -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 +116 -0
- package/src/editor/context-menu/CopyMoveMenu.tsx +103 -0
- package/src/editor/context-menu/InsertMenu.tsx +347 -0
- package/src/editor/control-center/About.tsx +342 -0
- package/src/editor/control-center/ControlCenterMenu.tsx +76 -0
- package/src/editor/control-center/IndexOverview.tsx +50 -0
- package/src/editor/control-center/IndexSettings.tsx +266 -0
- package/src/editor/control-center/Info.tsx +104 -0
- package/src/editor/control-center/QuotaInfo.tsx +301 -0
- package/src/editor/control-center/Status.tsx +113 -0
- package/src/editor/control-center/WebSocketMessages.tsx +155 -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 +16 -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 +80 -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 +188 -0
- package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
- package/src/editor/field-types/MultiLineText.tsx +82 -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 +127 -0
- package/src/editor/field-types/SingleLineText.tsx +174 -0
- package/src/editor/field-types/TreeListEditor.tsx +261 -0
- package/src/editor/fieldTypes.ts +140 -0
- package/src/editor/media-selector/AiImageSearch.tsx +185 -0
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +94 -0
- package/src/editor/media-selector/MediaFolderBrowser.tsx +321 -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/media-selector/index.ts +8 -0
- package/src/editor/menubar/ActionsMenu.tsx +94 -0
- package/src/editor/menubar/ActiveUsers.tsx +17 -0
- package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
- package/src/editor/menubar/BrowseHistory.tsx +28 -0
- package/src/editor/menubar/ItemLanguageVersion.tsx +76 -0
- package/src/editor/menubar/LanguageSelector.tsx +226 -0
- package/src/editor/menubar/Menu.tsx +83 -0
- package/src/editor/menubar/NavButtons.tsx +74 -0
- package/src/editor/menubar/PageSelector.tsx +278 -0
- package/src/editor/menubar/PageViewerControls.tsx +120 -0
- package/src/editor/menubar/PreviewSecondaryControls.tsx +18 -0
- package/src/editor/menubar/SecondaryControls.tsx +45 -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 +142 -0
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +307 -0
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +59 -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 +338 -0
- package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
- package/src/editor/page-editor-chrome/InlineEditor.tsx +765 -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 +122 -0
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +161 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +169 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +315 -0
- package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +300 -0
- package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +40 -0
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +828 -0
- package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
- package/src/editor/page-viewer/EditorForm.tsx +262 -0
- package/src/editor/page-viewer/MiniMap.tsx +362 -0
- package/src/editor/page-viewer/PageViewer.tsx +169 -0
- package/src/editor/page-viewer/PageViewerFrame.tsx +1022 -0
- package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +412 -0
- package/src/editor/page-viewer/pageViewContext.ts +186 -0
- package/src/editor/pageModel.ts +220 -0
- package/src/editor/picture-shared.tsx +53 -0
- package/src/editor/reviews/Comment.tsx +308 -0
- package/src/editor/reviews/Comments.tsx +125 -0
- package/src/editor/reviews/DiffView.tsx +109 -0
- package/src/editor/reviews/PreviewInfo.tsx +35 -0
- package/src/editor/reviews/Reviews.tsx +280 -0
- package/src/editor/reviews/SuggestedEdit.tsx +316 -0
- package/src/editor/reviews/reviewCommands.tsx +47 -0
- package/src/editor/reviews/useReviews.tsx +70 -0
- package/src/editor/services/aiService.ts +173 -0
- package/src/editor/services/componentDesignerService.ts +151 -0
- package/src/editor/services/contentService.ts +180 -0
- package/src/editor/services/editService.ts +488 -0
- package/src/editor/services/indexService.ts +24 -0
- package/src/editor/services/reviewsService.ts +53 -0
- package/src/editor/services/serviceHelper.ts +95 -0
- package/src/editor/services/suggestedEditsService.ts +39 -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 +161 -0
- package/src/editor/sidebar/ComponentTree.tsx +549 -0
- package/src/editor/sidebar/Debug.tsx +111 -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 +102 -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 +152 -0
- package/src/editor/sidebar/Translations.tsx +295 -0
- package/src/editor/sidebar/Validation.tsx +102 -0
- package/src/editor/sidebar/ViewSelector.tsx +60 -0
- package/src/editor/sidebar/Workbox.tsx +209 -0
- package/src/editor/ui/CenteredMessage.tsx +7 -0
- package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +81 -0
- package/src/editor/ui/CopyToClipboardButton.tsx +24 -0
- package/src/editor/ui/DialogButtons.tsx +11 -0
- package/src/editor/ui/Icons.tsx +709 -0
- package/src/editor/ui/ItemList.tsx +76 -0
- package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
- package/src/editor/ui/ItemSearch.tsx +159 -0
- package/src/editor/ui/PerfectTree.tsx +676 -0
- package/src/editor/ui/Section.tsx +35 -0
- package/src/editor/ui/SimpleIconButton.tsx +54 -0
- package/src/editor/ui/SimpleMenu.tsx +40 -0
- package/src/editor/ui/SimpleTable.tsx +60 -0
- package/src/editor/ui/SimpleTabs.tsx +60 -0
- package/src/editor/ui/SimpleToolbar.tsx +7 -0
- package/src/editor/ui/Spinner.tsx +9 -0
- package/src/editor/ui/Splitter.tsx +420 -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 +486 -0
- package/src/editor/views/CompareView.tsx +245 -0
- package/src/editor/views/EditView.tsx +27 -0
- package/src/editor/views/ItemEditor.tsx +58 -0
- package/src/editor/views/MediaFolderEditView.tsx +66 -0
- package/src/editor/views/SingleEditView.tsx +57 -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/fonts/index.ts +10 -0
- package/src/index.ts +23 -0
- package/src/lib/safelist.tsx +16 -0
- package/src/lib/utils.ts +6 -0
- package/src/page-wizard/PageWizard.tsx +139 -0
- package/src/page-wizard/WizardBox.tsx +4 -0
- package/src/page-wizard/WizardBoxConnector.tsx +56 -0
- package/src/page-wizard/WizardSteps.tsx +458 -0
- package/src/page-wizard/service.ts +35 -0
- package/src/page-wizard/startPageWizardCommand.ts +26 -0
- package/src/page-wizard/steps/BuildPageStep.tsx +259 -0
- package/src/page-wizard/steps/CollectStep.tsx +296 -0
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +454 -0
- package/src/page-wizard/steps/Components.tsx +193 -0
- package/src/page-wizard/steps/ContentStep.tsx +890 -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 +60 -0
- package/src/page-wizard/steps/ImagesStep.tsx +382 -0
- package/src/page-wizard/steps/LayoutStep.tsx +227 -0
- package/src/page-wizard/steps/MetaDataStep.tsx +173 -0
- package/src/page-wizard/steps/SelectStep.tsx +281 -0
- package/src/page-wizard/steps/schema.ts +180 -0
- package/src/page-wizard/steps/usePageCreator.ts +325 -0
- package/src/page-wizard/usePageWizard.ts +79 -0
- package/src/revision.ts +2 -0
- package/src/splash-screen/NewPage.tsx +294 -0
- package/src/splash-screen/OpenPage.tsx +113 -0
- package/src/splash-screen/RecentPages.tsx +123 -0
- package/src/splash-screen/SectionHeadline.tsx +21 -0
- package/src/splash-screen/SplashScreen.tsx +195 -0
- package/src/tour/Tour.tsx +566 -0
- package/src/tour/default-tour.tsx +301 -0
- package/src/tour/preview-tour.tsx +128 -0
- package/src/types.ts +335 -0
- package/styles.css +765 -0
- package/tsconfig.build.json +31 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { deleteVersion } from "../services/editService";
|
|
2
|
+
import { getItemDescriptor } from "../utils";
|
|
3
|
+
import { Command, CommandContext } from "./commands";
|
|
4
|
+
|
|
5
|
+
export function getDeleteVersionCommand({}: {
|
|
6
|
+
language?: string;
|
|
7
|
+
}): Command<CommandContext<any>> {
|
|
8
|
+
return {
|
|
9
|
+
id: "deleteVersion",
|
|
10
|
+
execute: (context) => execute(context),
|
|
11
|
+
label: "Delete Version",
|
|
12
|
+
icon: "pi pi-fw pi-times",
|
|
13
|
+
disabled: (context: CommandContext<any>) =>
|
|
14
|
+
!context.editContext.item?.canLock ||
|
|
15
|
+
context.editContext.item.version === 0 ||
|
|
16
|
+
context.editContext.itemVersions.length === 0,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function execute(context: CommandContext<any>): Promise<void> {
|
|
21
|
+
if (!context.editContext.item) return;
|
|
22
|
+
const descriptor = getItemDescriptor(context.editContext.item);
|
|
23
|
+
|
|
24
|
+
let message =
|
|
25
|
+
"Are you sure you want to delete version " +
|
|
26
|
+
context.editContext.item.version +
|
|
27
|
+
"?";
|
|
28
|
+
|
|
29
|
+
const sessions = context.editContext.activeSessions.filter(
|
|
30
|
+
(x) =>
|
|
31
|
+
((x.item?.id === descriptor.id &&
|
|
32
|
+
x.item?.language === descriptor.language &&
|
|
33
|
+
x.item?.version === descriptor.version) ||
|
|
34
|
+
(x.page?.id === descriptor.id &&
|
|
35
|
+
x.page?.language === descriptor.language &&
|
|
36
|
+
x.page?.version === descriptor.version)) &&
|
|
37
|
+
x.sessionId !== context.editContext.sessionId
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (sessions.length > 0) {
|
|
41
|
+
context.editContext.showMessageDialog({
|
|
42
|
+
header: "Delete Version",
|
|
43
|
+
message:
|
|
44
|
+
"This version is currently locked by " +
|
|
45
|
+
sessions.map((x) => x.user.name).join(", ") +
|
|
46
|
+
". You cannot delete it.",
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
context.editContext.itemVersions[
|
|
53
|
+
context.editContext.itemVersions.length - 1
|
|
54
|
+
]?.version === context.editContext.item.version
|
|
55
|
+
) {
|
|
56
|
+
message += " This is the latest version!";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
context.editContext.confirm?.({
|
|
60
|
+
header: "Delete Version",
|
|
61
|
+
message,
|
|
62
|
+
showCancel: true,
|
|
63
|
+
accept: async () => {
|
|
64
|
+
await deleteVersion(descriptor, context.editContext.sessionId);
|
|
65
|
+
context.editContext.loadItem({
|
|
66
|
+
...descriptor,
|
|
67
|
+
version: 0,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { Command, CommandContext, CommandData } from "./commands";
|
|
2
|
+
import { FullItem, ItemDescriptor } from "../pageModel";
|
|
3
|
+
|
|
4
|
+
import { ItemNameDialog, ItemNameDialogProps } from "../ui/ItemNameDialogNew";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CopyMoveTargetSelectorDialog,
|
|
8
|
+
CopyMoveTargetSelectorDialogProps,
|
|
9
|
+
} from "../ui/CopyMoveTargetSelectorDialog";
|
|
10
|
+
import { defaultTranslateAll } from "./localizeItem/LocalizeItemUtils";
|
|
11
|
+
import { TranslationStatus } from "../../config/types";
|
|
12
|
+
|
|
13
|
+
export type ItemCommandData = CommandData & {
|
|
14
|
+
items: FullItem[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ItemCommandContext = CommandContext<ItemCommandData>;
|
|
18
|
+
|
|
19
|
+
export type ItemCommand = Command<ItemCommandData>;
|
|
20
|
+
|
|
21
|
+
export const deleteItemCommand: ItemCommand = {
|
|
22
|
+
id: "deleteItem",
|
|
23
|
+
label: "Delete",
|
|
24
|
+
icon: "pi pi-times",
|
|
25
|
+
disabled: (context: ItemCommandContext) =>
|
|
26
|
+
!context.data?.items || !context.data?.items[0]?.canDelete || false,
|
|
27
|
+
execute: async (context: ItemCommandContext) => {
|
|
28
|
+
const items = context.data?.items;
|
|
29
|
+
|
|
30
|
+
if (!items || items.length === 0) return;
|
|
31
|
+
const confirmed = await new Promise<boolean>((resolve) => {
|
|
32
|
+
context.editContext.confirm({
|
|
33
|
+
message: (
|
|
34
|
+
<div>
|
|
35
|
+
Are you sure you want to delete{" "}
|
|
36
|
+
<em>{items.map((x) => x.name).join(", ")}</em>? This cannot be
|
|
37
|
+
undone.
|
|
38
|
+
</div>
|
|
39
|
+
),
|
|
40
|
+
header: "Confirmation",
|
|
41
|
+
icon: "pi pi-exclamation-triangle",
|
|
42
|
+
accept: () => resolve(true),
|
|
43
|
+
reject: () => resolve(false),
|
|
44
|
+
showCancel: true,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (confirmed) {
|
|
49
|
+
if (
|
|
50
|
+
items.some(
|
|
51
|
+
(x) => context.editContext.contentEditorItem?.descriptor.id === x.id,
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
54
|
+
const firstItem = items[0];
|
|
55
|
+
if (firstItem) {
|
|
56
|
+
context.editContext.loadItem({
|
|
57
|
+
id: firstItem.parentId,
|
|
58
|
+
language: context.editContext.contentEditorItem!.language,
|
|
59
|
+
version: 0,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await context.editContext.operations.deleteItems(
|
|
65
|
+
items.map((x) => x.descriptor),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
export const renameItemCommand: ItemCommand = {
|
|
74
|
+
id: "renameItem",
|
|
75
|
+
label: "Rename",
|
|
76
|
+
icon: "pi pi-pencil",
|
|
77
|
+
keyBinding: "F2",
|
|
78
|
+
disabled: (context: ItemCommandContext) =>
|
|
79
|
+
!context.data?.items ||
|
|
80
|
+
context.data.items.length !== 1 ||
|
|
81
|
+
!context.data.items[0]?.canRename ||
|
|
82
|
+
false,
|
|
83
|
+
execute: async (context: ItemCommandContext) => {
|
|
84
|
+
const item = context.data?.items[0];
|
|
85
|
+
|
|
86
|
+
if (!item) return;
|
|
87
|
+
const newName = await context.openDialog<string, ItemNameDialogProps>(
|
|
88
|
+
ItemNameDialog,
|
|
89
|
+
{
|
|
90
|
+
name: item.name,
|
|
91
|
+
title: "Rename Item",
|
|
92
|
+
message: "Enter a new name for the item:",
|
|
93
|
+
parentItem: { ...item.descriptor, id: item.parentId },
|
|
94
|
+
itemId: item.id,
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
if (newName) {
|
|
98
|
+
await context.editContext.operations.renameItem(item.descriptor, newName);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
type InsertItemCommandData = ItemCommandData & {
|
|
104
|
+
templateId: string;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type InsertItemCommandContext = CommandContext<InsertItemCommandData>;
|
|
108
|
+
|
|
109
|
+
export type InsertItemCommand = Command<InsertItemCommandData>;
|
|
110
|
+
|
|
111
|
+
export const insertItemCommand: ItemCommand = {
|
|
112
|
+
id: "insertItem",
|
|
113
|
+
label: "Insert Item",
|
|
114
|
+
icon: "pi pi-plus",
|
|
115
|
+
disabled: (context: ItemCommandContext) =>
|
|
116
|
+
!context.data?.items ||
|
|
117
|
+
context.data.items.length !== 1 ||
|
|
118
|
+
!context.data.items[0]?.canCreate ||
|
|
119
|
+
false,
|
|
120
|
+
execute: async (context: InsertItemCommandContext) => {
|
|
121
|
+
const parentItem = context.data?.items[0];
|
|
122
|
+
const templateId = context.data?.templateId;
|
|
123
|
+
|
|
124
|
+
if (!parentItem || !templateId) return;
|
|
125
|
+
|
|
126
|
+
const templateItem = await context.editContext.itemsRepository.getItem({
|
|
127
|
+
id: templateId,
|
|
128
|
+
language: "en",
|
|
129
|
+
version: 0,
|
|
130
|
+
});
|
|
131
|
+
const templateName = templateItem?.name;
|
|
132
|
+
|
|
133
|
+
const name = await context.openDialog<string, ItemNameDialogProps>(
|
|
134
|
+
ItemNameDialog,
|
|
135
|
+
{
|
|
136
|
+
title: "Create Item",
|
|
137
|
+
message: "Enter a name for the new item:",
|
|
138
|
+
name: templateName,
|
|
139
|
+
parentItem: parentItem.descriptor,
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
if (name) {
|
|
143
|
+
const result = await context.editContext.operations.createItem(
|
|
144
|
+
parentItem.descriptor,
|
|
145
|
+
templateId,
|
|
146
|
+
name,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
if (result) {
|
|
150
|
+
context.editContext.loadItem(result);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type MoveCopyItemsCommandData = ItemCommandData & {
|
|
159
|
+
targetItem: ItemDescriptor;
|
|
160
|
+
index: number;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type MoveCopyItemsCommandContext =
|
|
164
|
+
CommandContext<MoveCopyItemsCommandData>;
|
|
165
|
+
|
|
166
|
+
export type MoveCopyItemsCommand = Command<MoveCopyItemsCommandData>;
|
|
167
|
+
|
|
168
|
+
export const moveItemsCommand: MoveCopyItemsCommand = {
|
|
169
|
+
id: "moveItems",
|
|
170
|
+
label: "Move Item(s)",
|
|
171
|
+
icon: "pi pi-arrow-right",
|
|
172
|
+
disabled: (context: MoveCopyItemsCommandContext) =>
|
|
173
|
+
!context.data?.items ||
|
|
174
|
+
context.data.items.some((x) => !x.canDelete) ||
|
|
175
|
+
false,
|
|
176
|
+
execute: async (context: MoveCopyItemsCommandContext) => {
|
|
177
|
+
const items = context.data?.items;
|
|
178
|
+
let targetItem = context.data?.targetItem;
|
|
179
|
+
let index = context.data?.index;
|
|
180
|
+
|
|
181
|
+
if (!items) return;
|
|
182
|
+
|
|
183
|
+
if (!targetItem) {
|
|
184
|
+
const result = await context.openDialog<
|
|
185
|
+
ItemDescriptor,
|
|
186
|
+
CopyMoveTargetSelectorDialogProps
|
|
187
|
+
>(CopyMoveTargetSelectorDialog, {
|
|
188
|
+
items: items ?? [],
|
|
189
|
+
editContext: context.editContext,
|
|
190
|
+
header: "Select Target Item",
|
|
191
|
+
label:
|
|
192
|
+
items?.length && items.length > 1
|
|
193
|
+
? `Move ${items?.length} items`
|
|
194
|
+
: `Move item`,
|
|
195
|
+
});
|
|
196
|
+
if (result) {
|
|
197
|
+
targetItem = result;
|
|
198
|
+
index = -1;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!targetItem) return;
|
|
203
|
+
|
|
204
|
+
context.editContext.operations.moveItems(items, targetItem, index ?? 0);
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const copyItemsCommand: MoveCopyItemsCommand = {
|
|
209
|
+
id: "copyItems",
|
|
210
|
+
label: "Copy Item(s)",
|
|
211
|
+
icon: "pi pi-copy",
|
|
212
|
+
disabled: (context: MoveCopyItemsCommandContext) =>
|
|
213
|
+
!context.data?.items || false,
|
|
214
|
+
execute: async (context: MoveCopyItemsCommandContext) => {
|
|
215
|
+
console.log("copyItemsCommand", context.data);
|
|
216
|
+
const items = context.data?.items;
|
|
217
|
+
let targetItem = context.data?.targetItem;
|
|
218
|
+
let index = context.data?.index;
|
|
219
|
+
|
|
220
|
+
if (!targetItem) {
|
|
221
|
+
const result = await context.openDialog<
|
|
222
|
+
ItemDescriptor,
|
|
223
|
+
CopyMoveTargetSelectorDialogProps
|
|
224
|
+
>(CopyMoveTargetSelectorDialog, {
|
|
225
|
+
items: items ?? [],
|
|
226
|
+
editContext: context.editContext,
|
|
227
|
+
header: "Select Target Item",
|
|
228
|
+
label:
|
|
229
|
+
items?.length && items.length > 1
|
|
230
|
+
? `Copy ${items?.length} items`
|
|
231
|
+
: `Copy item`,
|
|
232
|
+
});
|
|
233
|
+
if (result) {
|
|
234
|
+
targetItem = result;
|
|
235
|
+
index = -1;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!items || !targetItem) return;
|
|
240
|
+
|
|
241
|
+
const result = await context.editContext.operations.copyItems(
|
|
242
|
+
items,
|
|
243
|
+
targetItem,
|
|
244
|
+
index ?? 0,
|
|
245
|
+
);
|
|
246
|
+
if (result && result.length > 0 && result[0]) {
|
|
247
|
+
context.editContext.loadItem(result[0]);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export const duplicateItemCommand: MoveCopyItemsCommand = {
|
|
253
|
+
id: "duplicateItem",
|
|
254
|
+
label: "Duplicate Item",
|
|
255
|
+
icon: "pi pi-clone",
|
|
256
|
+
disabled: (context: MoveCopyItemsCommandContext) =>
|
|
257
|
+
!context.data?.items || context.data.items.length !== 1 || false,
|
|
258
|
+
execute: async (context: MoveCopyItemsCommandContext) => {
|
|
259
|
+
const item = context.data?.items[0];
|
|
260
|
+
console.log("item", item);
|
|
261
|
+
if (!item) return;
|
|
262
|
+
const targetItem = {
|
|
263
|
+
id: item.parentId,
|
|
264
|
+
language: item.language,
|
|
265
|
+
version: 0,
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const newName = await context.openDialog<string, ItemNameDialogProps>(
|
|
269
|
+
ItemNameDialog,
|
|
270
|
+
{
|
|
271
|
+
name: item.name,
|
|
272
|
+
title: "Duplicate Item",
|
|
273
|
+
message: "Enter a name for the new item:",
|
|
274
|
+
parentItem: { ...item.descriptor, id: item.parentId },
|
|
275
|
+
itemId: item.id,
|
|
276
|
+
},
|
|
277
|
+
);
|
|
278
|
+
if (newName) {
|
|
279
|
+
const result = await context.editContext.operations.duplicateItem(
|
|
280
|
+
item.descriptor,
|
|
281
|
+
targetItem,
|
|
282
|
+
newName,
|
|
283
|
+
);
|
|
284
|
+
if (result) {
|
|
285
|
+
context.editContext.loadItem(result);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export type LocalizeItemCommandData = ItemCommandData & {
|
|
294
|
+
targetLanguages: string[];
|
|
295
|
+
translationProvider: string;
|
|
296
|
+
translationStatus: TranslationStatus[];
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export type TargetLanguage = {
|
|
300
|
+
language: string;
|
|
301
|
+
version: number;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export type LocalizeItemCommandContext =
|
|
305
|
+
CommandContext<LocalizeItemCommandData>;
|
|
306
|
+
|
|
307
|
+
export type LocalizeItemCommand = Command<LocalizeItemCommandData>;
|
|
308
|
+
|
|
309
|
+
export const localizeItemCommand: LocalizeItemCommand = {
|
|
310
|
+
id: "localizeItem",
|
|
311
|
+
label: "Localize",
|
|
312
|
+
icon: "pi pi-globe",
|
|
313
|
+
disabled: (context: LocalizeItemCommandContext) =>
|
|
314
|
+
!context.data?.items || context.data.items.length === 0 || false,
|
|
315
|
+
execute: async (context: LocalizeItemCommandContext) => {
|
|
316
|
+
const items = context.data?.items;
|
|
317
|
+
if (
|
|
318
|
+
!items ||
|
|
319
|
+
!items?.length ||
|
|
320
|
+
!context.data?.targetLanguages ||
|
|
321
|
+
!context.data?.translationProvider ||
|
|
322
|
+
!context.data?.translationStatus ||
|
|
323
|
+
!context.data?.translationStatus.length
|
|
324
|
+
) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
await defaultTranslateAll(
|
|
328
|
+
context.data?.targetLanguages,
|
|
329
|
+
context.data?.translationStatus,
|
|
330
|
+
context.editContext.sessionId,
|
|
331
|
+
items[0]!,
|
|
332
|
+
context.data?.translationProvider,
|
|
333
|
+
);
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export const publishItemCommand: ItemCommand = {
|
|
338
|
+
id: "publishItem",
|
|
339
|
+
label: "Publish",
|
|
340
|
+
icon: "pi pi-cloud-upload",
|
|
341
|
+
disabled: (context: ItemCommandContext) =>
|
|
342
|
+
!context.data?.items ||
|
|
343
|
+
context.data.items.length !== 1 ||
|
|
344
|
+
!context.data.items[0]?.canLock ||
|
|
345
|
+
false,
|
|
346
|
+
execute: async (context: ItemCommandContext) => {
|
|
347
|
+
const item = context.data?.items[0];
|
|
348
|
+
if (!item) return;
|
|
349
|
+
await context.editContext.switchView("publish");
|
|
350
|
+
},
|
|
351
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Button } from "primereact/button";
|
|
2
|
+
import { Dialog } from "primereact/dialog";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import DialogButtons from "../../ui/DialogButtons";
|
|
5
|
+
import { DialogProps } from "../../client/editContext";
|
|
6
|
+
import { getLanguagesAndVersions } from "../../services/contentService";
|
|
7
|
+
import { FullItem, ItemDescriptor } from "../../pageModel";
|
|
8
|
+
import { LanguageVersions } from "../../../types";
|
|
9
|
+
import { Checkbox } from "primereact/checkbox";
|
|
10
|
+
|
|
11
|
+
import { EditContextType } from "../../client/editContext";
|
|
12
|
+
import { Spinner } from "../../ui/Spinner";
|
|
13
|
+
|
|
14
|
+
export type LocalizeItemDialogProps = {
|
|
15
|
+
items: FullItem[];
|
|
16
|
+
editContext: EditContextType;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type LanguageData = {
|
|
20
|
+
name: string;
|
|
21
|
+
items: ItemDescriptor[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function LocalizeItemDialog(
|
|
25
|
+
props: LocalizeItemDialogProps & DialogProps<string>,
|
|
26
|
+
) {
|
|
27
|
+
const [languageSelection, setLanguageSelection] = useState<
|
|
28
|
+
Record<string, boolean>
|
|
29
|
+
>({});
|
|
30
|
+
const [languageData, setLanguageData] = useState<Map<string, LanguageData>>();
|
|
31
|
+
|
|
32
|
+
const [isExecuting, setIsExecuting] = useState(false);
|
|
33
|
+
const [currentTask, setCurrentTask] = useState<string>();
|
|
34
|
+
const [completedTasks, setCompletedTasks] = useState<string[]>([]);
|
|
35
|
+
const [finished, setFinished] = useState(false);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const itemDescriptors = props.items.map((x) => x.descriptor);
|
|
39
|
+
|
|
40
|
+
const loadLanguages = async () => {
|
|
41
|
+
const itemLanguages = await Promise.all(
|
|
42
|
+
itemDescriptors.map(async (item: ItemDescriptor) => {
|
|
43
|
+
const result = await getLanguagesAndVersions(item);
|
|
44
|
+
return result.data?.languages || [];
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
const languageMap = new Map<string, LanguageData>();
|
|
48
|
+
itemLanguages.forEach((languages, index) => {
|
|
49
|
+
languages.forEach((language: LanguageVersions) => {
|
|
50
|
+
const languageData: LanguageData = languageMap.get(language.name) || {
|
|
51
|
+
name: language.name,
|
|
52
|
+
items: [],
|
|
53
|
+
};
|
|
54
|
+
if (language.versions > 0 && itemDescriptors[index])
|
|
55
|
+
languageData.items.push(itemDescriptors[index]);
|
|
56
|
+
languageMap.set(language.languageCode, languageData);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
setLanguageData(languageMap);
|
|
60
|
+
};
|
|
61
|
+
loadLanguages();
|
|
62
|
+
}, [props]);
|
|
63
|
+
|
|
64
|
+
async function startLocalization() {
|
|
65
|
+
setIsExecuting(true);
|
|
66
|
+
const completedTasks: string[] = [];
|
|
67
|
+
for (const item of props.items) {
|
|
68
|
+
for (const language of Object.keys(languageSelection)) {
|
|
69
|
+
if (!languageSelection[language]) continue;
|
|
70
|
+
if (
|
|
71
|
+
languageData
|
|
72
|
+
?.get(language)
|
|
73
|
+
?.items.find((x) => x.id === item.descriptor.id)
|
|
74
|
+
)
|
|
75
|
+
continue;
|
|
76
|
+
setCurrentTask(`${item.name} - ${language}`);
|
|
77
|
+
await props.editContext.operations.createVersion({
|
|
78
|
+
id: item.descriptor.id,
|
|
79
|
+
language: language,
|
|
80
|
+
version: 0,
|
|
81
|
+
});
|
|
82
|
+
completedTasks.push(`${item.name} - ${language}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
setFinished(true);
|
|
86
|
+
setCompletedTasks(completedTasks);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const allLanguages = Array.from(languageData?.keys() || []).map((x) => ({
|
|
90
|
+
code: x,
|
|
91
|
+
name: languageData?.get(x)?.name || "",
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
allLanguages.sort((a, b) => a.name.localeCompare(b.name));
|
|
95
|
+
|
|
96
|
+
const dialogContent = getContent();
|
|
97
|
+
|
|
98
|
+
function getContent() {
|
|
99
|
+
if (finished)
|
|
100
|
+
return (
|
|
101
|
+
<div className="justify flex h-full flex-col gap-1">
|
|
102
|
+
{completedTasks.length > 0 && (
|
|
103
|
+
<>
|
|
104
|
+
<div className="px-3 pt-3 text-lg font-bold">
|
|
105
|
+
Finished. Versions created:
|
|
106
|
+
</div>
|
|
107
|
+
<div className="relative flex-1">
|
|
108
|
+
<div className="absolute inset-3 flex flex-col gap-3 overflow-y-auto">
|
|
109
|
+
{completedTasks.map((x, index) => (
|
|
110
|
+
<div key={index}>{x}</div>
|
|
111
|
+
))}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</>
|
|
115
|
+
)}
|
|
116
|
+
{completedTasks.length === 0 && (
|
|
117
|
+
<div className="flex h-full items-center justify-center">
|
|
118
|
+
All items are already localized.
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
<DialogButtons>
|
|
122
|
+
<Button onClick={() => props.onClose?.(null)} label="Close" />
|
|
123
|
+
</DialogButtons>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (isExecuting)
|
|
128
|
+
return (
|
|
129
|
+
<div className="flex h-full items-center justify-center gap-3">
|
|
130
|
+
<Spinner /> Creating version {currentTask}
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div className="justify flex h-full flex-col gap-1 text-sm">
|
|
136
|
+
<div className="flex h-full flex-col gap-2 p-3">
|
|
137
|
+
<div className="my-2">
|
|
138
|
+
Select languages to localize{" "}
|
|
139
|
+
{props.items.map((x) => x.name).join(", ")}:
|
|
140
|
+
</div>
|
|
141
|
+
<div className="my-1 flex items-center gap-2">
|
|
142
|
+
<Checkbox
|
|
143
|
+
checked={allLanguages.every(
|
|
144
|
+
(language) => languageSelection[language.code],
|
|
145
|
+
)}
|
|
146
|
+
onChange={(e) => {
|
|
147
|
+
setLanguageSelection(
|
|
148
|
+
Object.fromEntries(
|
|
149
|
+
Array.from(languageData?.keys() || []).map((language) => [
|
|
150
|
+
language,
|
|
151
|
+
e.checked || false,
|
|
152
|
+
]),
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
}}
|
|
156
|
+
/>{" "}
|
|
157
|
+
All
|
|
158
|
+
</div>
|
|
159
|
+
<div className="relative flex-1">
|
|
160
|
+
<div className="absolute top-0 left-0 h-full w-full overflow-y-auto">
|
|
161
|
+
{allLanguages.map((language) => (
|
|
162
|
+
<div
|
|
163
|
+
key={language.code}
|
|
164
|
+
className="my-2 flex items-center gap-2"
|
|
165
|
+
>
|
|
166
|
+
<Checkbox
|
|
167
|
+
checked={languageSelection[language.code] || false}
|
|
168
|
+
onChange={(e) => {
|
|
169
|
+
setLanguageSelection((prev) => ({
|
|
170
|
+
...prev,
|
|
171
|
+
[language.code]: e.checked || false,
|
|
172
|
+
}));
|
|
173
|
+
}}
|
|
174
|
+
/>
|
|
175
|
+
<div>{language.name}</div>
|
|
176
|
+
</div>
|
|
177
|
+
))}
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
<DialogButtons>
|
|
182
|
+
<Button onClick={startLocalization} label="Start" />
|
|
183
|
+
<Button onClick={() => props.onClose?.(null)} label="Cancel" />
|
|
184
|
+
</DialogButtons>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<Dialog
|
|
191
|
+
visible={true}
|
|
192
|
+
onHide={() => {
|
|
193
|
+
props.onClose?.(null);
|
|
194
|
+
}}
|
|
195
|
+
style={{ width: "75vw", height: "75vh" }}
|
|
196
|
+
header="Localize"
|
|
197
|
+
>
|
|
198
|
+
{dialogContent}
|
|
199
|
+
</Dialog>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { requestTranslation } from "../../services/translationService";
|
|
2
|
+
import { TranslationStatus } from "../../../config/types";
|
|
3
|
+
import { FullItem } from "../../pageModel";
|
|
4
|
+
|
|
5
|
+
export const defaultTranslateAll = async (languageCodes: string[], translationStatus: TranslationStatus[], sessionId: string, item: FullItem, translationProvider: string) => {
|
|
6
|
+
const translationPromises = [];
|
|
7
|
+
|
|
8
|
+
for (const languageCode of languageCodes) {
|
|
9
|
+
const status = translationStatus?.find(
|
|
10
|
+
(x) => x.targetLanguage === languageCode
|
|
11
|
+
);
|
|
12
|
+
if (!status) continue;
|
|
13
|
+
if (status.sourceLanguage === languageCode) continue;
|
|
14
|
+
|
|
15
|
+
translationPromises.push(
|
|
16
|
+
requestTranslation({
|
|
17
|
+
itemId: item.descriptor.id,
|
|
18
|
+
targetLanguage: languageCode,
|
|
19
|
+
sourceLanguage: status.sourceLanguage,
|
|
20
|
+
sessionId: sessionId,
|
|
21
|
+
provider: translationProvider,
|
|
22
|
+
metadata: ""
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await Promise.all(translationPromises);
|
|
27
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CommandContext } from "./commands";
|
|
2
|
+
|
|
3
|
+
export function getUndoCommand() {
|
|
4
|
+
return {
|
|
5
|
+
id: "undo",
|
|
6
|
+
label: "Undo",
|
|
7
|
+
icon: "pi pi-undo",
|
|
8
|
+
execute: async (context: CommandContext<any>) => {
|
|
9
|
+
context.editContext.operations.undo();
|
|
10
|
+
},
|
|
11
|
+
disabled: (context: CommandContext<any>) => {
|
|
12
|
+
return (
|
|
13
|
+
context.editContext.editHistory.length === 0 ||
|
|
14
|
+
!context.editContext.editHistory.find(
|
|
15
|
+
(x) => x.sessionId === context.editContext.sessionId && x.canUndo
|
|
16
|
+
)
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getRedoCommand() {
|
|
23
|
+
return {
|
|
24
|
+
id: "redo",
|
|
25
|
+
label: "Redo",
|
|
26
|
+
icon: "pi pi-refresh",
|
|
27
|
+
execute: async (context: CommandContext<any>) => {
|
|
28
|
+
context.editContext.operations.redo();
|
|
29
|
+
},
|
|
30
|
+
disabled: (context: CommandContext<any>) => {
|
|
31
|
+
return (
|
|
32
|
+
context.editContext.editHistory.length === 0 ||
|
|
33
|
+
!context.editContext.editHistory.find(
|
|
34
|
+
(x) => x.sessionId === context.editContext.sessionId && x.canRedo
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|