@alpaca-editor/core 1.0.3938 → 1.0.3941
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/dist/components/ActionButton.d.ts +1 -0
- package/dist/components/ActionButton.js +2 -2
- package/dist/components/ActionButton.js.map +1 -1
- package/dist/editor/ContentTree.js +12 -8
- package/dist/editor/ContentTree.js.map +1 -1
- package/dist/editor/ContextMenu.d.ts +1 -1
- package/dist/editor/ContextMenu.js +17 -3
- package/dist/editor/ContextMenu.js.map +1 -1
- package/dist/editor/FieldActionsOverlay.d.ts +18 -0
- package/dist/editor/FieldActionsOverlay.js +139 -0
- package/dist/editor/FieldActionsOverlay.js.map +1 -0
- package/dist/editor/FieldHistory.d.ts +2 -1
- package/dist/editor/FieldHistory.js +11 -8
- package/dist/editor/FieldHistory.js.map +1 -1
- package/dist/editor/FieldListField.js +14 -17
- package/dist/editor/FieldListField.js.map +1 -1
- package/dist/editor/PictureCropper.js +65 -23
- package/dist/editor/PictureCropper.js.map +1 -1
- package/dist/editor/PictureEditor.js +43 -3
- package/dist/editor/PictureEditor.js.map +1 -1
- package/dist/editor/Titlebar.js +19 -10
- package/dist/editor/Titlebar.js.map +1 -1
- package/dist/editor/ai/AiTerminal.js +27 -41
- package/dist/editor/ai/AiTerminal.js.map +1 -1
- package/dist/editor/ai/GhostWriter.js +21 -2
- package/dist/editor/ai/GhostWriter.js.map +1 -1
- package/dist/editor/client/EditorClient.js +48 -18
- package/dist/editor/client/EditorClient.js.map +1 -1
- package/dist/editor/client/editContext.d.ts +1 -1
- package/dist/editor/client/editContext.js.map +1 -1
- package/dist/editor/client/itemsRepository.js +126 -90
- package/dist/editor/client/itemsRepository.js.map +1 -1
- package/dist/editor/commands/componentCommands.js +7 -3
- package/dist/editor/commands/componentCommands.js.map +1 -1
- package/dist/editor/media-selector/MediaFolderBrowser.d.ts +5 -0
- package/dist/editor/media-selector/MediaFolderBrowser.js +77 -0
- package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -0
- package/dist/editor/media-selector/MediaSelector.js +1 -1
- package/dist/editor/media-selector/MediaSelector.js.map +1 -1
- package/dist/editor/media-selector/Thumbnails.js +2 -2
- package/dist/editor/media-selector/index.d.ts +8 -0
- package/dist/editor/media-selector/index.js +9 -0
- package/dist/editor/media-selector/index.js.map +1 -0
- package/dist/editor/menubar/BrowseHistory.js +3 -4
- package/dist/editor/menubar/BrowseHistory.js.map +1 -1
- package/dist/editor/menubar/PageSelector.js +62 -10
- package/dist/editor/menubar/PageSelector.js.map +1 -1
- package/dist/editor/page-editor-chrome/FieldActionIndicator.js +1 -1
- package/dist/editor/page-editor-chrome/FieldActionIndicator.js.map +1 -1
- package/dist/editor/page-editor-chrome/useInlineAICompletion.js +37 -11
- package/dist/editor/page-editor-chrome/useInlineAICompletion.js.map +1 -1
- package/dist/editor/page-viewer/PageViewerFrame.js +98 -2
- package/dist/editor/page-viewer/PageViewerFrame.js.map +1 -1
- package/dist/editor/pageModel.d.ts +14 -0
- package/dist/editor/reviews/Comment.js +3 -2
- package/dist/editor/reviews/Comment.js.map +1 -1
- package/dist/editor/services/aiService.js +0 -1
- package/dist/editor/services/aiService.js.map +1 -1
- package/dist/editor/services/editService.d.ts +1 -1
- package/dist/editor/services/editService.js +2 -1
- package/dist/editor/services/editService.js.map +1 -1
- package/dist/editor/sidebar/ComponentTree.js +3 -4
- package/dist/editor/sidebar/ComponentTree.js.map +1 -1
- package/dist/editor/ui/Icons.js +1 -1
- package/dist/editor/ui/Icons.js.map +1 -1
- package/dist/editor/ui/ItemList.d.ts +16 -0
- package/dist/editor/ui/ItemList.js +19 -0
- package/dist/editor/ui/ItemList.js.map +1 -0
- package/dist/editor/ui/ItemSearch.js +2 -12
- package/dist/editor/ui/ItemSearch.js.map +1 -1
- package/dist/editor/ui/SimpleTabs.d.ts +1 -0
- package/dist/editor/ui/SimpleTabs.js +3 -3
- package/dist/editor/ui/SimpleTabs.js.map +1 -1
- package/dist/editor/ui/Splitter.js +61 -6
- package/dist/editor/ui/Splitter.js.map +1 -1
- package/dist/editor/views/MediaFolderEditView.d.ts +4 -0
- package/dist/editor/views/MediaFolderEditView.js +40 -0
- package/dist/editor/views/MediaFolderEditView.js.map +1 -0
- package/dist/editor/views/SingleEditView.js +9 -1
- package/dist/editor/views/SingleEditView.js.map +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +64 -13
- package/package.json +8 -2
- package/.prettierrc +0 -3
- package/build.css +0 -3
- package/components.json +0 -21
- package/eslint.config.mjs +0 -4
- 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/src/client-components/api.ts +0 -6
- package/src/client-components/index.ts +0 -19
- package/src/components/ActionButton.tsx +0 -41
- package/src/components/Error.tsx +0 -57
- package/src/components/ui/CardConnector.tsx +0 -56
- package/src/components/ui/button.tsx +0 -62
- package/src/components/ui/card.tsx +0 -372
- package/src/components/ui/context-menu.tsx +0 -250
- package/src/config/config.tsx +0 -917
- package/src/config/types.ts +0 -286
- package/src/editor/ComponentInfo.tsx +0 -90
- package/src/editor/ConfirmationDialog.tsx +0 -103
- package/src/editor/ContentTree.tsx +0 -727
- package/src/editor/ContextMenu.tsx +0 -212
- package/src/editor/Editor.tsx +0 -90
- package/src/editor/EditorWarning.tsx +0 -34
- package/src/editor/EditorWarnings.tsx +0 -33
- package/src/editor/FieldEditorPopup.tsx +0 -65
- package/src/editor/FieldHistory.tsx +0 -74
- package/src/editor/FieldList.tsx +0 -190
- package/src/editor/FieldListField.tsx +0 -391
- package/src/editor/FieldListFieldWithFallbacks.tsx +0 -217
- package/src/editor/FloatingToolbar.tsx +0 -163
- package/src/editor/ImageEditor.tsx +0 -128
- package/src/editor/ItemInfo.tsx +0 -90
- package/src/editor/LinkEditorDialog.tsx +0 -196
- package/src/editor/MainLayout.tsx +0 -95
- package/src/editor/MobileLayout.tsx +0 -68
- package/src/editor/NewEditorClient.tsx +0 -11
- package/src/editor/PictureCropper.tsx +0 -503
- package/src/editor/PictureEditor.tsx +0 -212
- package/src/editor/PictureEditorDialog.tsx +0 -381
- package/src/editor/PublishDialog.ignore +0 -74
- package/src/editor/ScrollingContentTree.tsx +0 -67
- package/src/editor/Terminal.tsx +0 -227
- package/src/editor/Titlebar.tsx +0 -93
- package/src/editor/ai/AiPopup.tsx +0 -59
- package/src/editor/ai/AiResponseMessage.tsx +0 -106
- package/src/editor/ai/AiTerminal.tsx +0 -514
- package/src/editor/ai/AiToolCall.tsx +0 -61
- package/src/editor/ai/EditorAiTerminal.tsx +0 -20
- package/src/editor/ai/GhostWriter.tsx +0 -432
- package/src/editor/ai/aiPageModel.ts +0 -108
- package/src/editor/ai/editorAiContext.ts +0 -18
- package/src/editor/client/AboutDialog.tsx +0 -44
- package/src/editor/client/EditorClient.tsx +0 -2197
- package/src/editor/client/GenericDialog.tsx +0 -50
- package/src/editor/client/editContext.ts +0 -412
- package/src/editor/client/helpers.ts +0 -44
- package/src/editor/client/itemsRepository.ts +0 -538
- package/src/editor/client/operations.ts +0 -768
- package/src/editor/client/pageModelBuilder.ts +0 -219
- package/src/editor/commands/commands.ts +0 -22
- package/src/editor/commands/componentCommands.tsx +0 -424
- package/src/editor/commands/createVersionCommand.ts +0 -33
- package/src/editor/commands/deleteVersionCommand.ts +0 -71
- package/src/editor/commands/itemCommands.tsx +0 -351
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +0 -201
- package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +0 -27
- package/src/editor/commands/undo.ts +0 -39
- package/src/editor/component-designer/ComponentDesigner.tsx +0 -70
- package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +0 -11
- package/src/editor/component-designer/ComponentDesignerMenu.tsx +0 -91
- package/src/editor/component-designer/ComponentEditor.tsx +0 -97
- package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +0 -31
- package/src/editor/component-designer/ComponentRenderingEditor.tsx +0 -104
- package/src/editor/component-designer/ComponentsDropdown.tsx +0 -39
- package/src/editor/component-designer/PlaceholdersEditor.tsx +0 -179
- package/src/editor/component-designer/RenderingsDropdown.tsx +0 -36
- package/src/editor/component-designer/TemplateEditor.tsx +0 -236
- package/src/editor/component-designer/aiContext.ts +0 -23
- package/src/editor/componentTreeHelper.tsx +0 -116
- package/src/editor/context-menu/CopyMoveMenu.tsx +0 -103
- package/src/editor/context-menu/InsertMenu.tsx +0 -347
- package/src/editor/control-center/About.tsx +0 -342
- package/src/editor/control-center/ControlCenterMenu.tsx +0 -76
- package/src/editor/control-center/IndexOverview.tsx +0 -50
- package/src/editor/control-center/IndexSettings.tsx +0 -266
- package/src/editor/control-center/Info.tsx +0 -104
- package/src/editor/control-center/QuotaInfo.tsx +0 -301
- package/src/editor/control-center/Status.tsx +0 -113
- package/src/editor/control-center/WebSocketMessages.tsx +0 -155
- package/src/editor/editor-warnings/ItemLocked.tsx +0 -63
- package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +0 -22
- package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +0 -23
- package/src/editor/editor-warnings/NoWriteAccess.tsx +0 -16
- package/src/editor/editor-warnings/ValidationErrors.tsx +0 -54
- package/src/editor/field-types/AttachmentEditor.tsx +0 -9
- package/src/editor/field-types/CheckboxEditor.tsx +0 -47
- package/src/editor/field-types/DropLinkEditor.tsx +0 -80
- package/src/editor/field-types/DropListEditor.tsx +0 -84
- package/src/editor/field-types/ImageFieldEditor.tsx +0 -65
- package/src/editor/field-types/InternalLinkFieldEditor.tsx +0 -117
- package/src/editor/field-types/LinkFieldEditor.tsx +0 -85
- package/src/editor/field-types/MultiLineText.tsx +0 -82
- package/src/editor/field-types/PictureFieldEditor.tsx +0 -121
- package/src/editor/field-types/RawEditor.tsx +0 -53
- package/src/editor/field-types/ReactQuill.tsx +0 -580
- package/src/editor/field-types/RichTextEditor.tsx +0 -22
- package/src/editor/field-types/RichTextEditorComponent.tsx +0 -127
- package/src/editor/field-types/SingleLineText.tsx +0 -174
- package/src/editor/field-types/TreeListEditor.tsx +0 -261
- package/src/editor/fieldTypes.ts +0 -140
- package/src/editor/media-selector/AiImageSearch.tsx +0 -185
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +0 -94
- package/src/editor/media-selector/MediaSelector.tsx +0 -42
- package/src/editor/media-selector/Preview.tsx +0 -14
- package/src/editor/media-selector/Thumbnails.tsx +0 -48
- package/src/editor/media-selector/TreeSelector.tsx +0 -292
- package/src/editor/media-selector/UploadZone.tsx +0 -137
- package/src/editor/menubar/ActionsMenu.tsx +0 -94
- package/src/editor/menubar/ActiveUsers.tsx +0 -17
- package/src/editor/menubar/ApproveAndPublish.tsx +0 -18
- package/src/editor/menubar/BrowseHistory.tsx +0 -37
- package/src/editor/menubar/ItemLanguageVersion.tsx +0 -76
- package/src/editor/menubar/LanguageSelector.tsx +0 -226
- package/src/editor/menubar/Menu.tsx +0 -83
- package/src/editor/menubar/NavButtons.tsx +0 -74
- package/src/editor/menubar/PageSelector.tsx +0 -141
- package/src/editor/menubar/PageViewerControls.tsx +0 -120
- package/src/editor/menubar/PreviewSecondaryControls.tsx +0 -18
- package/src/editor/menubar/SecondaryControls.tsx +0 -45
- package/src/editor/menubar/Separator.tsx +0 -12
- package/src/editor/menubar/SiteInfo.tsx +0 -53
- package/src/editor/menubar/User.tsx +0 -27
- package/src/editor/menubar/VersionSelector.tsx +0 -142
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +0 -307
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +0 -35
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +0 -59
- package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +0 -23
- package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +0 -64
- package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +0 -35
- package/src/editor/page-editor-chrome/FrameMenu.tsx +0 -338
- package/src/editor/page-editor-chrome/FrameMenus.tsx +0 -48
- package/src/editor/page-editor-chrome/InlineEditor.tsx +0 -765
- package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +0 -61
- package/src/editor/page-editor-chrome/NoLayout.tsx +0 -36
- package/src/editor/page-editor-chrome/PageEditorChrome.tsx +0 -122
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +0 -161
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +0 -169
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +0 -315
- package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +0 -300
- package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +0 -40
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +0 -791
- package/src/editor/page-viewer/DeviceToolbar.tsx +0 -70
- package/src/editor/page-viewer/EditorForm.tsx +0 -258
- package/src/editor/page-viewer/MiniMap.tsx +0 -362
- package/src/editor/page-viewer/PageViewer.tsx +0 -169
- package/src/editor/page-viewer/PageViewerFrame.tsx +0 -879
- package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +0 -412
- package/src/editor/page-viewer/pageViewContext.ts +0 -186
- package/src/editor/pageModel.ts +0 -208
- package/src/editor/picture-shared.tsx +0 -53
- package/src/editor/reviews/Comment.tsx +0 -308
- package/src/editor/reviews/Comments.tsx +0 -125
- package/src/editor/reviews/DiffView.tsx +0 -109
- package/src/editor/reviews/PreviewInfo.tsx +0 -35
- package/src/editor/reviews/Reviews.tsx +0 -280
- package/src/editor/reviews/SuggestedEdit.tsx +0 -316
- package/src/editor/reviews/reviewCommands.tsx +0 -47
- package/src/editor/reviews/useReviews.tsx +0 -70
- package/src/editor/services/aiService.ts +0 -174
- package/src/editor/services/componentDesignerService.ts +0 -151
- package/src/editor/services/contentService.ts +0 -180
- package/src/editor/services/editService.ts +0 -486
- package/src/editor/services/indexService.ts +0 -24
- package/src/editor/services/reviewsService.ts +0 -53
- package/src/editor/services/serviceHelper.ts +0 -95
- package/src/editor/services/suggestedEditsService.ts +0 -39
- package/src/editor/services/systemService.ts +0 -5
- package/src/editor/services/translationService.ts +0 -21
- package/src/editor/services-server/api.ts +0 -150
- package/src/editor/services-server/graphQL.ts +0 -106
- package/src/editor/sidebar/ComponentPalette.tsx +0 -161
- package/src/editor/sidebar/ComponentTree.tsx +0 -548
- package/src/editor/sidebar/ComponentTree2.tsxx +0 -490
- package/src/editor/sidebar/Debug.tsx +0 -111
- package/src/editor/sidebar/DictionaryEditor.tsx +0 -261
- package/src/editor/sidebar/EditHistory.tsx +0 -134
- package/src/editor/sidebar/GraphQL.tsx +0 -164
- package/src/editor/sidebar/Insert.tsx +0 -35
- package/src/editor/sidebar/MainContentTree.tsx +0 -102
- package/src/editor/sidebar/Performance.tsx +0 -53
- package/src/editor/sidebar/Sessions.tsx +0 -35
- package/src/editor/sidebar/Sidebar.tsx +0 -20
- package/src/editor/sidebar/SidebarView.tsx +0 -152
- package/src/editor/sidebar/Translations.tsx +0 -295
- package/src/editor/sidebar/Validation.tsx +0 -102
- package/src/editor/sidebar/ViewSelector.tsx +0 -60
- package/src/editor/sidebar/Workbox.tsx +0 -209
- package/src/editor/ui/CenteredMessage.tsx +0 -7
- package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +0 -81
- package/src/editor/ui/CopyToClipboardButton.tsx +0 -24
- package/src/editor/ui/DialogButtons.tsx +0 -11
- package/src/editor/ui/Icons.tsx +0 -708
- package/src/editor/ui/ItemNameDialogNew.tsx +0 -118
- package/src/editor/ui/ItemSearch.tsx +0 -190
- package/src/editor/ui/PerfectTree.tsx +0 -571
- package/src/editor/ui/Section.tsx +0 -35
- package/src/editor/ui/SimpleIconButton.tsx +0 -54
- package/src/editor/ui/SimpleMenu.tsx +0 -40
- package/src/editor/ui/SimpleTable.tsx +0 -60
- package/src/editor/ui/SimpleTabs.tsx +0 -55
- package/src/editor/ui/SimpleToolbar.tsx +0 -7
- package/src/editor/ui/Spinner.tsx +0 -9
- package/src/editor/ui/Splitter.tsx +0 -314
- package/src/editor/ui/StackedPanels.tsx +0 -134
- package/src/editor/ui/Toolbar.tsx +0 -7
- package/src/editor/utils/id-helper.ts +0 -3
- package/src/editor/utils/insertOptions.ts +0 -69
- package/src/editor/utils/itemutils.ts +0 -29
- package/src/editor/utils/useMemoDebug.ts +0 -28
- package/src/editor/utils.ts +0 -486
- package/src/editor/views/CompareView.tsx +0 -245
- package/src/editor/views/EditView.tsx +0 -27
- package/src/editor/views/ItemEditor.tsx +0 -58
- package/src/editor/views/SingleEditView.tsx +0 -46
- 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 +0 -10
- package/src/index.ts +0 -23
- package/src/lib/safelist.tsx +0 -16
- package/src/lib/utils.ts +0 -6
- package/src/page-wizard/PageWizard.tsx +0 -139
- package/src/page-wizard/WizardBox.tsx +0 -4
- package/src/page-wizard/WizardBoxConnector.tsx +0 -56
- package/src/page-wizard/WizardSteps.tsx +0 -458
- package/src/page-wizard/service.ts +0 -35
- package/src/page-wizard/startPageWizardCommand.ts +0 -26
- package/src/page-wizard/steps/BuildPageStep.tsx +0 -259
- package/src/page-wizard/steps/CollectStep.tsx +0 -296
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +0 -454
- package/src/page-wizard/steps/Components.tsx +0 -193
- package/src/page-wizard/steps/ContentStep.tsx +0 -890
- package/src/page-wizard/steps/EditButton.tsx +0 -34
- package/src/page-wizard/steps/FieldEditor.tsx +0 -102
- package/src/page-wizard/steps/Generate.tsx +0 -60
- package/src/page-wizard/steps/ImagesStep.tsx +0 -382
- package/src/page-wizard/steps/LayoutStep.tsx +0 -227
- package/src/page-wizard/steps/MetaDataStep.tsx +0 -173
- package/src/page-wizard/steps/SelectStep.tsx +0 -281
- package/src/page-wizard/steps/schema.ts +0 -180
- package/src/page-wizard/steps/usePageCreator.ts +0 -325
- package/src/page-wizard/usePageWizard.ts +0 -79
- package/src/revision.ts +0 -2
- package/src/splash-screen/NewPage.tsx +0 -294
- package/src/splash-screen/OpenPage.tsx +0 -113
- package/src/splash-screen/RecentPages.tsx +0 -123
- package/src/splash-screen/SectionHeadline.tsx +0 -21
- package/src/splash-screen/SplashScreen.tsx +0 -195
- package/src/tour/Tour.tsx +0 -566
- package/src/tour/default-tour.tsx +0 -301
- package/src/tour/preview-tour.tsx +0 -128
- package/src/types.ts +0 -335
- package/styles.css +0 -765
- package/tsconfig.build.json +0 -31
- package/tsconfig.json +0 -14
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
Component,
|
|
4
|
-
ComponentSkeleton,
|
|
5
|
-
ItemDescriptor,
|
|
6
|
-
Page,
|
|
7
|
-
PageSkeleton,
|
|
8
|
-
Placeholder,
|
|
9
|
-
RenderedItem,
|
|
10
|
-
RenderedItemSkeleton,
|
|
11
|
-
} from "../pageModel";
|
|
12
|
-
|
|
13
|
-
import { ItemsRepository } from "./itemsRepository";
|
|
14
|
-
import {
|
|
15
|
-
loadPlaceholderInsertOptions,
|
|
16
|
-
PlaceholderInsertOptions,
|
|
17
|
-
} from "../services/editService";
|
|
18
|
-
|
|
19
|
-
export function usePageModel(
|
|
20
|
-
itemsRepository: ItemsRepository | undefined,
|
|
21
|
-
pageItemDescriptor?: ItemDescriptor,
|
|
22
|
-
) {
|
|
23
|
-
const [page, setPage] = useState<Page>();
|
|
24
|
-
const [pageSkeleton, setPageSkeleton] = useState<PageSkeleton>();
|
|
25
|
-
const [insertOptions, setInsertOptions] = useState<
|
|
26
|
-
PlaceholderInsertOptions[]
|
|
27
|
-
>([]);
|
|
28
|
-
|
|
29
|
-
const insertOptionsCache = useRef<Record<string, PlaceholderInsertOptions>>(
|
|
30
|
-
{},
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// 2) whenever the descriptor changes, reset skeleton, page and clear cache
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
setPage(undefined);
|
|
36
|
-
setPageSkeleton(undefined);
|
|
37
|
-
insertOptionsCache.current = {};
|
|
38
|
-
setInsertOptions([]);
|
|
39
|
-
}, [pageItemDescriptor]);
|
|
40
|
-
|
|
41
|
-
// 3) collect all placeholder-keys in a skeleton
|
|
42
|
-
const collectPlaceholderKeys = (skeleton: PageSkeleton): string[] => {
|
|
43
|
-
const keys: string[] = [];
|
|
44
|
-
const collect = (c: ComponentSkeleton) => {
|
|
45
|
-
c.placeholders.forEach((ph) => {
|
|
46
|
-
keys.push(ph.key);
|
|
47
|
-
ph.components.forEach(collect);
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
collect(skeleton.rootComponent);
|
|
51
|
-
return keys;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// 4) load only missing insertOptions
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const loadInsertOptions = async () => {
|
|
57
|
-
if (!pageSkeleton) return;
|
|
58
|
-
|
|
59
|
-
const allKeys = collectPlaceholderKeys(pageSkeleton);
|
|
60
|
-
// find which keys we haven’t cached yet
|
|
61
|
-
const missingKeys = allKeys.filter(
|
|
62
|
-
(k) => !(k in insertOptionsCache.current),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (missingKeys.length) {
|
|
66
|
-
const newlyFetched = await loadPlaceholderInsertOptions(
|
|
67
|
-
pageSkeleton.item,
|
|
68
|
-
missingKeys,
|
|
69
|
-
);
|
|
70
|
-
// stash them in our cache
|
|
71
|
-
newlyFetched.forEach((opt) => {
|
|
72
|
-
insertOptionsCache.current[opt.key] = opt;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// now build the full list in the original placeholder order
|
|
77
|
-
const optionsInOrder = allKeys
|
|
78
|
-
.map((k) => insertOptionsCache.current[k])
|
|
79
|
-
.filter((opt): opt is PlaceholderInsertOptions => !!opt);
|
|
80
|
-
|
|
81
|
-
setInsertOptions(optionsInOrder);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
loadInsertOptions();
|
|
85
|
-
}, [pageSkeleton]);
|
|
86
|
-
|
|
87
|
-
const updatePageModel = async () => {
|
|
88
|
-
if (!itemsRepository) return;
|
|
89
|
-
|
|
90
|
-
//const start = performance.now();
|
|
91
|
-
const itemsToFetch: ItemDescriptor[] = [];
|
|
92
|
-
if (!pageSkeleton) {
|
|
93
|
-
setPage(undefined);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
itemsToFetch.push(pageSkeleton.item);
|
|
98
|
-
|
|
99
|
-
const collectItems = (component: ComponentSkeleton) => {
|
|
100
|
-
if (component.datasourceItem)
|
|
101
|
-
itemsToFetch.push({
|
|
102
|
-
id: component.datasourceItem.id,
|
|
103
|
-
language: component.datasourceItem.language,
|
|
104
|
-
version: component.datasourceItem.version,
|
|
105
|
-
});
|
|
106
|
-
component.placeholders
|
|
107
|
-
.flatMap((x) => x.components)
|
|
108
|
-
.forEach((c) => collectItems(c));
|
|
109
|
-
component.items.forEach((i) => itemsToFetch.push(i));
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
collectItems(pageSkeleton.rootComponent);
|
|
113
|
-
|
|
114
|
-
const itemStubs = await itemsRepository.getItemsStubs(itemsToFetch);
|
|
115
|
-
|
|
116
|
-
const getItem = (descriptor: ItemDescriptor) =>
|
|
117
|
-
itemStubs.find(
|
|
118
|
-
(x) =>
|
|
119
|
-
x.id === descriptor.id &&
|
|
120
|
-
x.language === descriptor.language &&
|
|
121
|
-
x.version === descriptor.version,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const pageItem = await itemsRepository.getItem(pageSkeleton.item);
|
|
125
|
-
|
|
126
|
-
if (!pageItem) {
|
|
127
|
-
setPage(undefined);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const buildModel = (
|
|
132
|
-
skeleton: ComponentSkeleton,
|
|
133
|
-
parentPlaceholder?: Placeholder,
|
|
134
|
-
): Component | undefined => {
|
|
135
|
-
const datasourceItemTemp = skeleton.datasourceItem
|
|
136
|
-
? getItem(skeleton.datasourceItem)
|
|
137
|
-
: undefined;
|
|
138
|
-
|
|
139
|
-
const datasourceItem =
|
|
140
|
-
skeleton.datasourceItem && datasourceItemTemp
|
|
141
|
-
? { ...skeleton.datasourceItem, ...datasourceItemTemp }
|
|
142
|
-
: undefined;
|
|
143
|
-
|
|
144
|
-
let name =
|
|
145
|
-
skeleton.name || datasourceItem?.name || skeleton.type || "unknown";
|
|
146
|
-
|
|
147
|
-
const mapItem = (x: RenderedItemSkeleton): RenderedItem | null => {
|
|
148
|
-
const item = getItem(x);
|
|
149
|
-
if (!item) return null;
|
|
150
|
-
return { ...x, ...item };
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const items = skeleton.items.map(mapItem).filter((x) => x !== null);
|
|
154
|
-
|
|
155
|
-
const placeholders: Placeholder[] = [];
|
|
156
|
-
|
|
157
|
-
const component: Component = {
|
|
158
|
-
...skeleton,
|
|
159
|
-
name,
|
|
160
|
-
icon: datasourceItem?.icon,
|
|
161
|
-
datasourceItem,
|
|
162
|
-
items,
|
|
163
|
-
placeholders,
|
|
164
|
-
isShared: !(datasourceItem?.path.startsWith(pageItem.path) || true),
|
|
165
|
-
parentPlaceholder,
|
|
166
|
-
type: datasourceItem?.templateName || "", // TODO: We need the name for AI page wizard - we should not use the template name
|
|
167
|
-
typeId: skeleton.typeId || datasourceItem?.templateId || "",
|
|
168
|
-
canBeMoved:
|
|
169
|
-
!datasourceItem ||
|
|
170
|
-
datasourceItem?.id !== parentPlaceholder?.parentComponent?.id,
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
component.placeholders = skeleton.placeholders.map((x) => {
|
|
174
|
-
const insOpts =
|
|
175
|
-
insertOptions.find((y) => y.key === x.key)?.insertOptions ?? [];
|
|
176
|
-
|
|
177
|
-
const placeholder: Placeholder = {
|
|
178
|
-
...x,
|
|
179
|
-
components: [],
|
|
180
|
-
canSynchronize: false,
|
|
181
|
-
parentComponent: component,
|
|
182
|
-
insertOptions: insOpts,
|
|
183
|
-
};
|
|
184
|
-
placeholder.components = x.components
|
|
185
|
-
.map((y) => buildModel(y, placeholder))
|
|
186
|
-
.filter((x) => x !== undefined);
|
|
187
|
-
|
|
188
|
-
return placeholder;
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
return component;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const rootComponent = buildModel(pageSkeleton.rootComponent);
|
|
195
|
-
|
|
196
|
-
if (!rootComponent) {
|
|
197
|
-
setPage(undefined);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const page: Page = {
|
|
201
|
-
item: pageItem,
|
|
202
|
-
rootComponent,
|
|
203
|
-
// revision: itemsRepository.revision,
|
|
204
|
-
editRevision: pageSkeleton.editRevision,
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
//console.log("Page model updated", performance.now() - start);
|
|
208
|
-
setPage(page);
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
useEffect(() => {
|
|
212
|
-
updatePageModel();
|
|
213
|
-
}, [pageSkeleton, itemsRepository, insertOptions]);
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
setPageSkeleton,
|
|
217
|
-
page,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { OpenDialog } from "../client/editContext";
|
|
2
|
-
import { EditContextType } from "../client/editContext";
|
|
3
|
-
|
|
4
|
-
export type CommandContext<T> = {
|
|
5
|
-
editContext: EditContextType;
|
|
6
|
-
openDialog: OpenDialog;
|
|
7
|
-
event?: React.SyntheticEvent;
|
|
8
|
-
searchParams?: URLSearchParams;
|
|
9
|
-
pathname?: string;
|
|
10
|
-
data?: T;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type Command<T extends CommandData> = {
|
|
14
|
-
id: string;
|
|
15
|
-
label: string;
|
|
16
|
-
icon: React.ReactNode;
|
|
17
|
-
execute(context: CommandContext<T>): Promise<any>;
|
|
18
|
-
disabled: (context: CommandContext<T>) => boolean;
|
|
19
|
-
keyBinding?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type CommandData = {};
|
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import { EditContextType } from "../client/editContext";
|
|
2
|
-
import uuid from "react-uuid";
|
|
3
|
-
import { Command, CommandContext, CommandData } from "./commands";
|
|
4
|
-
|
|
5
|
-
import { getComponentById } from "../componentTreeHelper";
|
|
6
|
-
import {
|
|
7
|
-
PlaceholderToSynchronize,
|
|
8
|
-
RemoveComponentOperation,
|
|
9
|
-
SynchronizeComponentsOperation,
|
|
10
|
-
} from "../../types";
|
|
11
|
-
|
|
12
|
-
import { Component, ItemDescriptor, Placeholder } from "../pageModel";
|
|
13
|
-
import {
|
|
14
|
-
Check,
|
|
15
|
-
Copy,
|
|
16
|
-
MessageCircleMore,
|
|
17
|
-
Palette,
|
|
18
|
-
Plus,
|
|
19
|
-
RefreshCcw,
|
|
20
|
-
Sparkles,
|
|
21
|
-
Square,
|
|
22
|
-
StopCircle,
|
|
23
|
-
Trash2,
|
|
24
|
-
TriangleAlert,
|
|
25
|
-
} from "lucide-react";
|
|
26
|
-
|
|
27
|
-
export type ComponentCommandData = CommandData & {
|
|
28
|
-
components: Component[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type ComponentCommandContext = CommandContext<ComponentCommandData>;
|
|
32
|
-
|
|
33
|
-
export type ComponentCommandVisibilityScope =
|
|
34
|
-
| "editFrame"
|
|
35
|
-
| "menu"
|
|
36
|
-
| "contextMenu";
|
|
37
|
-
|
|
38
|
-
export type ComponentCommand = Command<ComponentCommandData> & {
|
|
39
|
-
visibilityScopes: ComponentCommandVisibilityScope[];
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const isPlaceholder = (x: any): x is Placeholder => x.components !== undefined;
|
|
43
|
-
const defaultIconSize = 16;
|
|
44
|
-
|
|
45
|
-
// export function getSelectedComponentCommands(editContext: EditContextType) {
|
|
46
|
-
// const selection = editContext.selection;
|
|
47
|
-
|
|
48
|
-
// const selectedComponents = selection
|
|
49
|
-
// .map((x) => getComponentById(x, editContext.page!))
|
|
50
|
-
// .filter((x) => x) as Component[];
|
|
51
|
-
|
|
52
|
-
// const componentCommands = getComponentCommands(
|
|
53
|
-
// selectedComponents,
|
|
54
|
-
// editContext,
|
|
55
|
-
// );
|
|
56
|
-
|
|
57
|
-
// const componentCommandMenuItems = componentCommands.filter(
|
|
58
|
-
// (x) => x.visibilityScopes.indexOf("menu") >= 0,
|
|
59
|
-
// );
|
|
60
|
-
|
|
61
|
-
// return componentCommandMenuItems;
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
|
-
export async function getComponentCommands(
|
|
65
|
-
entities: (Placeholder | Component)[],
|
|
66
|
-
editContext: EditContextType,
|
|
67
|
-
): Promise<ComponentCommand[]> {
|
|
68
|
-
const components = entities.filter(
|
|
69
|
-
(x) => x && !isPlaceholder(x),
|
|
70
|
-
) as Component[];
|
|
71
|
-
|
|
72
|
-
const commands = [
|
|
73
|
-
await getCreateCommentCommand(components),
|
|
74
|
-
await getInsertCommand(components, editContext),
|
|
75
|
-
await getDeleteCommand(components, editContext),
|
|
76
|
-
await getDuplicateCommand(components, editContext),
|
|
77
|
-
await getSyncCommand(entities, editContext),
|
|
78
|
-
await getAiCommand(editContext),
|
|
79
|
-
await getDesignCommand(components, editContext),
|
|
80
|
-
await getLinkToMasterCommand(components, editContext),
|
|
81
|
-
await getInheritChildrenFromMasterCommand(components, editContext),
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
return commands.filter((x) => x !== null);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getInsertCommand(
|
|
88
|
-
components: Component[],
|
|
89
|
-
editContext: EditContextType,
|
|
90
|
-
): ComponentCommand | null {
|
|
91
|
-
if (components.length !== 1 || isPlaceholder(components[0])) return null;
|
|
92
|
-
const item = components[0];
|
|
93
|
-
if (!item) return null;
|
|
94
|
-
if (!item.placeholders || item.placeholders.length === 0) return null;
|
|
95
|
-
return {
|
|
96
|
-
id: "insert",
|
|
97
|
-
icon: <Plus size={defaultIconSize} />,
|
|
98
|
-
label: "Insert component",
|
|
99
|
-
disabled: (context) => !context.editContext.page?.item.canWriteItem,
|
|
100
|
-
visibilityScopes: ["editFrame", "contextMenu"],
|
|
101
|
-
execute: async () => {
|
|
102
|
-
editContext.setSelectedForInsertion(item.id);
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getDuplicateCommand(
|
|
108
|
-
components: Component[],
|
|
109
|
-
editContext: EditContextType,
|
|
110
|
-
): ComponentCommand | null {
|
|
111
|
-
if (components.length !== 1) return null;
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
id: "duplicate",
|
|
115
|
-
icon: <Copy size={defaultIconSize} />,
|
|
116
|
-
label: "Duplicate",
|
|
117
|
-
visibilityScopes: ["contextMenu", "menu"],
|
|
118
|
-
disabled: (c) => !(c.editContext.page?.item.canWriteItem || false),
|
|
119
|
-
execute: async (context: CommandContext<any>) => {
|
|
120
|
-
// if (!components[0].parentPlaceholder?.parentComponent.datasourceItem)
|
|
121
|
-
// return;
|
|
122
|
-
|
|
123
|
-
editContext.operations.duplicateComponents({
|
|
124
|
-
componentIds: components.map((x) => x.id),
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function getAiCommand(editContext: EditContextType): ComponentCommand {
|
|
131
|
-
return {
|
|
132
|
-
id: "ai",
|
|
133
|
-
icon: <Sparkles size={defaultIconSize} />,
|
|
134
|
-
label: "AI",
|
|
135
|
-
disabled: () => false,
|
|
136
|
-
|
|
137
|
-
execute: async (context: CommandContext<any>) => {
|
|
138
|
-
const event = context.event!;
|
|
139
|
-
editContext.showAiPopup(event as any);
|
|
140
|
-
event.preventDefault();
|
|
141
|
-
event.stopPropagation();
|
|
142
|
-
},
|
|
143
|
-
visibilityScopes: ["editFrame", "contextMenu"],
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function getDesignCommand(
|
|
148
|
-
components: Component[],
|
|
149
|
-
editContext: EditContextType,
|
|
150
|
-
): Promise<ComponentCommand | null> {
|
|
151
|
-
if (components.length !== 1 || isPlaceholder(components[0])) return null;
|
|
152
|
-
const component = components[0];
|
|
153
|
-
if (!component || !component.datasourceItem) return null;
|
|
154
|
-
const item = await editContext.itemsRepository.getItem(
|
|
155
|
-
component.datasourceItem,
|
|
156
|
-
);
|
|
157
|
-
if (!item) return null;
|
|
158
|
-
if (!Object.values(item.fields).find((x) => x.section === "Design"))
|
|
159
|
-
return null;
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
id: "design",
|
|
163
|
-
icon: <Palette size={defaultIconSize} />,
|
|
164
|
-
label: "Design",
|
|
165
|
-
disabled: () => false,
|
|
166
|
-
execute: async (context: CommandContext<any>) => {
|
|
167
|
-
editContext.showFieldEditorPopup(
|
|
168
|
-
item.fields || [],
|
|
169
|
-
["Design", "Rendering"],
|
|
170
|
-
context.event!,
|
|
171
|
-
);
|
|
172
|
-
},
|
|
173
|
-
visibilityScopes: ["editFrame", "contextMenu"],
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function getLinkToMasterCommand(
|
|
178
|
-
components: Component[],
|
|
179
|
-
editContext: EditContextType,
|
|
180
|
-
): Promise<ComponentCommand | null> {
|
|
181
|
-
if (!components.length) return null;
|
|
182
|
-
if (editContext.page?.item?.masterLanguages?.length === 0) return null;
|
|
183
|
-
|
|
184
|
-
return getCheckboxCommand(
|
|
185
|
-
components,
|
|
186
|
-
editContext,
|
|
187
|
-
"componentLinkedToMasterLanguage",
|
|
188
|
-
"Linked To Master Language",
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async function getCheckboxCommand(
|
|
193
|
-
components: Component[],
|
|
194
|
-
editContext: EditContextType,
|
|
195
|
-
fieldName: string,
|
|
196
|
-
label: string,
|
|
197
|
-
): Promise<ComponentCommand | null> {
|
|
198
|
-
const items = await editContext.itemsRepository.getItems(
|
|
199
|
-
components.filter((x) => x.datasourceItem).map((x) => x.datasourceItem!),
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const someLinked = items.find(
|
|
203
|
-
(y) => y.fields.find((z) => z.name === fieldName)?.rawValue === "1",
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
const allLinked = !items.find(
|
|
207
|
-
(y) => y.fields.find((z) => z.name === fieldName)?.rawValue !== "1",
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
id: fieldName,
|
|
212
|
-
icon: allLinked ? (
|
|
213
|
-
<Check size={defaultIconSize} />
|
|
214
|
-
) : someLinked ? (
|
|
215
|
-
<StopCircle size={defaultIconSize} />
|
|
216
|
-
) : (
|
|
217
|
-
<Square size={defaultIconSize} />
|
|
218
|
-
),
|
|
219
|
-
label,
|
|
220
|
-
disabled: () => false,
|
|
221
|
-
execute: async () => {
|
|
222
|
-
items.forEach((c) => {
|
|
223
|
-
const field = c.fields.find((x) => x.name === fieldName);
|
|
224
|
-
if (!field) return;
|
|
225
|
-
editContext.operations.editField({
|
|
226
|
-
field: field.descriptor,
|
|
227
|
-
rawValue: allLinked ? "" : "1",
|
|
228
|
-
refresh: "immediate",
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
},
|
|
232
|
-
visibilityScopes: ["menu", "contextMenu"],
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async function getInheritChildrenFromMasterCommand(
|
|
237
|
-
components: Component[],
|
|
238
|
-
editContext: EditContextType,
|
|
239
|
-
): Promise<ComponentCommand | null> {
|
|
240
|
-
if (!components.length) return null;
|
|
241
|
-
if (editContext.page?.item?.masterLanguages?.length === 0) return null;
|
|
242
|
-
if (components.find((x) => !x.placeholders || x.placeholders.length === 0))
|
|
243
|
-
return null;
|
|
244
|
-
|
|
245
|
-
return getCheckboxCommand(
|
|
246
|
-
components,
|
|
247
|
-
editContext,
|
|
248
|
-
"inheritChildrenFromMasterLanguage",
|
|
249
|
-
"Inherit Children From Master",
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function isLocked(c: Component, editContext: EditContextType): boolean {
|
|
254
|
-
if (
|
|
255
|
-
editContext.activeSessions.find(
|
|
256
|
-
(x) =>
|
|
257
|
-
x.fieldLock?.item.id === c.id &&
|
|
258
|
-
x.fieldLock.item.language == c.datasourceItem?.language &&
|
|
259
|
-
x.fieldLock.item.version === c.datasourceItem?.version &&
|
|
260
|
-
x.sessionId !== editContext.sessionId,
|
|
261
|
-
) !== undefined
|
|
262
|
-
) {
|
|
263
|
-
return true;
|
|
264
|
-
} else
|
|
265
|
-
return (
|
|
266
|
-
c.placeholders?.find(
|
|
267
|
-
(x) =>
|
|
268
|
-
x.components.find((child) => isLocked(child, editContext)) !==
|
|
269
|
-
undefined,
|
|
270
|
-
) !== undefined
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function getDeleteCommand(
|
|
275
|
-
components: Component[],
|
|
276
|
-
editContext: EditContextType,
|
|
277
|
-
): ComponentCommand | null {
|
|
278
|
-
const applicableComponents = components.filter(
|
|
279
|
-
(c) =>
|
|
280
|
-
((!isPlaceholder(c) && !c.layoutId) ||
|
|
281
|
-
c.layoutId === editContext.page?.item.id) &&
|
|
282
|
-
!isLocked(c, editContext) &&
|
|
283
|
-
editContext.page?.item.canWriteItem,
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
if (applicableComponents.length === 0) return null;
|
|
287
|
-
|
|
288
|
-
return {
|
|
289
|
-
id: "delete",
|
|
290
|
-
label: "Delete",
|
|
291
|
-
icon: <Trash2 size={14} />,
|
|
292
|
-
execute: async (context: CommandContext<any>) =>
|
|
293
|
-
deleteComponents(applicableComponents, context.editContext),
|
|
294
|
-
disabled: () =>
|
|
295
|
-
applicableComponents.length === 0 ||
|
|
296
|
-
applicableComponents.length !== components.length,
|
|
297
|
-
|
|
298
|
-
visibilityScopes: ["editFrame", "menu", "contextMenu"],
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function canSynchronize(placeholderData: Placeholder) {
|
|
303
|
-
if (placeholderData.canSynchronize) return true;
|
|
304
|
-
placeholderData.components.forEach((c) => {
|
|
305
|
-
if (c.placeholders?.find((x) => canSynchronize(x))) return true;
|
|
306
|
-
});
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function getSyncCommand(
|
|
311
|
-
components: (Placeholder | Component)[],
|
|
312
|
-
editContext: EditContextType,
|
|
313
|
-
): ComponentCommand {
|
|
314
|
-
const placeholders: PlaceholderToSynchronize[] = [];
|
|
315
|
-
|
|
316
|
-
for (const component of components) {
|
|
317
|
-
if (isPlaceholder(component) && canSynchronize(component)) {
|
|
318
|
-
placeholders.push({
|
|
319
|
-
item: component.parentComponent
|
|
320
|
-
? getItemDescriptor(component.parentComponent, editContext)
|
|
321
|
-
: undefined,
|
|
322
|
-
});
|
|
323
|
-
} else {
|
|
324
|
-
if (
|
|
325
|
-
(component as Component).placeholders?.find((x) => canSynchronize(x))
|
|
326
|
-
) {
|
|
327
|
-
placeholders.push({
|
|
328
|
-
item: getItemDescriptor(component as Component, editContext),
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const canSync =
|
|
335
|
-
placeholders.length > 0 ||
|
|
336
|
-
(components.length === 0 &&
|
|
337
|
-
editContext.page?.rootComponent.placeholders.find((x) =>
|
|
338
|
-
canSynchronize(x),
|
|
339
|
-
));
|
|
340
|
-
|
|
341
|
-
return {
|
|
342
|
-
id: "synchronize",
|
|
343
|
-
label: "Synchronize",
|
|
344
|
-
icon: <RefreshCcw size={14} />,
|
|
345
|
-
disabled: () => !canSync,
|
|
346
|
-
visibilityScopes: ["menu", "editFrame", "contextMenu"],
|
|
347
|
-
execute: async () => {
|
|
348
|
-
const op: SynchronizeComponentsOperation = {
|
|
349
|
-
mainItem: editContext.page!.item.descriptor,
|
|
350
|
-
type: "synchronize-components",
|
|
351
|
-
date: new Date().toISOString(),
|
|
352
|
-
delete: false,
|
|
353
|
-
id: uuid(),
|
|
354
|
-
placeholders: placeholders,
|
|
355
|
-
|
|
356
|
-
description: "Synchronize components",
|
|
357
|
-
};
|
|
358
|
-
editContext.operations.executeEditOperation(op);
|
|
359
|
-
},
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function deleteComponents(
|
|
364
|
-
components: Component[],
|
|
365
|
-
editContext: EditContextType,
|
|
366
|
-
) {
|
|
367
|
-
if (!components.length) return;
|
|
368
|
-
|
|
369
|
-
editContext.confirm({
|
|
370
|
-
showCancel: true,
|
|
371
|
-
message:
|
|
372
|
-
(components.length > 1
|
|
373
|
-
? "Are you sure you want to remove these components? "
|
|
374
|
-
: "Are you sure you want to remove this component? ") +
|
|
375
|
-
components.map((x) => x.name).join(", "),
|
|
376
|
-
header: components.length > 1 ? "Remove components" : "Remove component",
|
|
377
|
-
icon: <TriangleAlert size={14} />,
|
|
378
|
-
accept: () => {
|
|
379
|
-
if (!editContext.page?.item.descriptor) return;
|
|
380
|
-
console.log("Remove components", components);
|
|
381
|
-
const op: RemoveComponentOperation = {
|
|
382
|
-
type: "remove-component",
|
|
383
|
-
date: new Date().toISOString(),
|
|
384
|
-
id: uuid(),
|
|
385
|
-
componentIds: components.map((x) => x.id),
|
|
386
|
-
mainItem: editContext.page.item.descriptor,
|
|
387
|
-
description:
|
|
388
|
-
"Remove components: " + components.map((x) => x.name).join(", "),
|
|
389
|
-
};
|
|
390
|
-
editContext.operations.executeEditOperation(op);
|
|
391
|
-
},
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function getCreateCommentCommand(
|
|
396
|
-
components: Component[],
|
|
397
|
-
): ComponentCommand | null {
|
|
398
|
-
if (components.length !== 1 || isPlaceholder(components[0])) return null;
|
|
399
|
-
|
|
400
|
-
return {
|
|
401
|
-
id: "addComment",
|
|
402
|
-
label: "Add Comment",
|
|
403
|
-
icon: <MessageCircleMore size={14} />,
|
|
404
|
-
disabled: () => false,
|
|
405
|
-
visibilityScopes: ["contextMenu"],
|
|
406
|
-
execute: async (context: CommandContext<any>) => {
|
|
407
|
-
context.editContext.addComment();
|
|
408
|
-
context.editContext.switchView("reviews");
|
|
409
|
-
},
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function getItemDescriptor(
|
|
414
|
-
component: Component,
|
|
415
|
-
editContext: EditContextType,
|
|
416
|
-
): ItemDescriptor | null {
|
|
417
|
-
return {
|
|
418
|
-
id: component.id,
|
|
419
|
-
language:
|
|
420
|
-
component.datasourceItem?.language || editContext.page!.item.language,
|
|
421
|
-
version:
|
|
422
|
-
component.datasourceItem?.version || editContext.page!.item.version,
|
|
423
|
-
};
|
|
424
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createVersion } from "../services/editService";
|
|
2
|
-
import { getItemDescriptor } from "../utils";
|
|
3
|
-
import { Command, CommandContext } from "./commands";
|
|
4
|
-
|
|
5
|
-
export function getCreateAndSwitchToNewVersionCommand({
|
|
6
|
-
language,
|
|
7
|
-
}: {
|
|
8
|
-
language?: string;
|
|
9
|
-
}): Command<CommandContext<any>> {
|
|
10
|
-
return {
|
|
11
|
-
id: "createAndSwitchToNewVersion",
|
|
12
|
-
execute: (context) => execute(context, language),
|
|
13
|
-
label: "Add Version",
|
|
14
|
-
icon: "pi pi-fw pi-plus",
|
|
15
|
-
disabled: (context: CommandContext<any>) =>
|
|
16
|
-
!context.editContext.item?.canLock,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function execute(
|
|
21
|
-
context: CommandContext<any>,
|
|
22
|
-
language?: string
|
|
23
|
-
): Promise<void> {
|
|
24
|
-
if (!context.editContext.item) return;
|
|
25
|
-
const descriptor = getItemDescriptor(context.editContext.item);
|
|
26
|
-
if (language) descriptor.language = language;
|
|
27
|
-
await createVersion(descriptor, context.editContext.sessionId);
|
|
28
|
-
|
|
29
|
-
context.editContext.loadItem({
|
|
30
|
-
...descriptor,
|
|
31
|
-
version: 0,
|
|
32
|
-
});
|
|
33
|
-
}
|