@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,182 @@
|
|
|
1
|
+
import { useEffect, 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 { loadPlaceholderInsertOptions, PlaceholderInsertOptions } from "../services/editService";
|
|
15
|
+
|
|
16
|
+
export function usePageModel(
|
|
17
|
+
itemsRepository: ItemsRepository | undefined,
|
|
18
|
+
pageItemDescriptor?: ItemDescriptor
|
|
19
|
+
) {
|
|
20
|
+
const [page, setPage] = useState<Page>();
|
|
21
|
+
const [pageSkeleton, setPageSkeleton] = useState<PageSkeleton>();
|
|
22
|
+
const [insertOptions, setInsertOptions] = useState<PlaceholderInsertOptions[]>([]);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setPage(undefined);
|
|
26
|
+
setPageSkeleton(undefined);
|
|
27
|
+
}, [pageItemDescriptor]);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const loadInsertOptions = async () => {
|
|
31
|
+
if (!pageSkeleton) return;
|
|
32
|
+
|
|
33
|
+
const collectPlaceholderKeys = (skeleton: PageSkeleton): string[] => {
|
|
34
|
+
const keys: string[] = [];
|
|
35
|
+
const collectFromComponent = (component: ComponentSkeleton) => {
|
|
36
|
+
component.placeholders.forEach(placeholder => {
|
|
37
|
+
keys.push(placeholder.key);
|
|
38
|
+
placeholder.components.forEach(c => collectFromComponent(c));
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
collectFromComponent(skeleton.rootComponent);
|
|
42
|
+
return keys;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const placeholderKeys = collectPlaceholderKeys(pageSkeleton);
|
|
46
|
+
const options = await loadPlaceholderInsertOptions(pageSkeleton.item, placeholderKeys);
|
|
47
|
+
setInsertOptions(options);
|
|
48
|
+
};
|
|
49
|
+
loadInsertOptions();
|
|
50
|
+
}, [pageSkeleton]);
|
|
51
|
+
|
|
52
|
+
const updatePageModel = async () => {
|
|
53
|
+
if (!itemsRepository) return;
|
|
54
|
+
|
|
55
|
+
//const start = performance.now();
|
|
56
|
+
const itemsToFetch: ItemDescriptor[] = [];
|
|
57
|
+
if (!pageSkeleton) {
|
|
58
|
+
setPage(undefined);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
itemsToFetch.push(pageSkeleton.item);
|
|
63
|
+
|
|
64
|
+
const collectItems = (component: ComponentSkeleton) => {
|
|
65
|
+
if (component.datasourceItem)
|
|
66
|
+
itemsToFetch.push({
|
|
67
|
+
id: component.datasourceItem.id,
|
|
68
|
+
language: component.datasourceItem.language,
|
|
69
|
+
version: component.datasourceItem.version,
|
|
70
|
+
});
|
|
71
|
+
component.placeholders
|
|
72
|
+
.flatMap((x) => x.components)
|
|
73
|
+
.forEach((c) => collectItems(c));
|
|
74
|
+
component.items.forEach((i) => itemsToFetch.push(i));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
collectItems(pageSkeleton.rootComponent);
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
const fullItems = await itemsRepository.getItems(itemsToFetch);
|
|
81
|
+
|
|
82
|
+
const getItem = (descriptor: ItemDescriptor) =>
|
|
83
|
+
fullItems.find(
|
|
84
|
+
(x) =>
|
|
85
|
+
x.id === descriptor.id &&
|
|
86
|
+
x.language === descriptor.language &&
|
|
87
|
+
x.version === descriptor.version
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const pageItem = await itemsRepository.getItem(pageSkeleton.item);
|
|
91
|
+
|
|
92
|
+
if (!pageItem) {
|
|
93
|
+
setPage(undefined);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const buildModel = (
|
|
98
|
+
skeleton: ComponentSkeleton,
|
|
99
|
+
parentPlaceholder?: Placeholder
|
|
100
|
+
): Component | undefined => {
|
|
101
|
+
|
|
102
|
+
const datasourceItemTemp = skeleton.datasourceItem
|
|
103
|
+
? getItem(skeleton.datasourceItem)
|
|
104
|
+
: undefined;
|
|
105
|
+
|
|
106
|
+
const datasourceItem =
|
|
107
|
+
skeleton.datasourceItem && datasourceItemTemp
|
|
108
|
+
? { ...skeleton.datasourceItem, ...datasourceItemTemp }
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
let name =
|
|
112
|
+
skeleton.name || datasourceItem?.name || skeleton.type || "unknown";
|
|
113
|
+
|
|
114
|
+
const mapItem = (x: RenderedItemSkeleton): RenderedItem | null => {
|
|
115
|
+
const item = getItem(x);
|
|
116
|
+
if (!item) return null;
|
|
117
|
+
return { ...x, ...item };
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const items = skeleton.items.map(mapItem).filter((x) => x !== null);
|
|
121
|
+
|
|
122
|
+
const placeholders: Placeholder[] = [];
|
|
123
|
+
|
|
124
|
+
const component: Component = {
|
|
125
|
+
...skeleton,
|
|
126
|
+
name,
|
|
127
|
+
datasourceItem,
|
|
128
|
+
items,
|
|
129
|
+
placeholders,
|
|
130
|
+
isShared: skeleton.id !== skeleton.datasourceItem?.id,
|
|
131
|
+
parentPlaceholder
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
component.placeholders = skeleton.placeholders.map((x) => {
|
|
136
|
+
const insOpts =
|
|
137
|
+
insertOptions.find((y) => y.key === x.key)?.insertOptions ?? [];
|
|
138
|
+
|
|
139
|
+
const placeholder: Placeholder = {
|
|
140
|
+
...x,
|
|
141
|
+
components: [],
|
|
142
|
+
canSynchronize: false,
|
|
143
|
+
parentComponent: component,
|
|
144
|
+
insertOptions: insOpts,
|
|
145
|
+
};
|
|
146
|
+
placeholder.components = x.components
|
|
147
|
+
.map((y) => buildModel(y, placeholder))
|
|
148
|
+
.filter((x) => x !== undefined);
|
|
149
|
+
|
|
150
|
+
return placeholder;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return component;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const rootComponent = buildModel(pageSkeleton.rootComponent);
|
|
157
|
+
|
|
158
|
+
if (!rootComponent) {
|
|
159
|
+
setPage(undefined);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const page: Page = {
|
|
163
|
+
item: pageItem,
|
|
164
|
+
rootComponent,
|
|
165
|
+
// revision: itemsRepository.revision,
|
|
166
|
+
editRevision: pageSkeleton.editRevision,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
//console.log("Page model updated", performance.now() - start);
|
|
170
|
+
setPage(page);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
updatePageModel();
|
|
176
|
+
}, [pageSkeleton, itemsRepository, insertOptions]);
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
setPageSkeleton,
|
|
180
|
+
page,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenDialog } from "../client/DialogContext";
|
|
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
|
+
|
|
23
|
+
export type CommandData = {};
|
|
@@ -0,0 +1,408 @@
|
|
|
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
|
+
|
|
14
|
+
export type ComponentCommandData = CommandData & {
|
|
15
|
+
components: Component[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ComponentCommandContext = CommandContext<ComponentCommandData>;
|
|
19
|
+
|
|
20
|
+
export type ComponentCommandVisibilityScope =
|
|
21
|
+
| "editFrame"
|
|
22
|
+
| "menu"
|
|
23
|
+
| "contextMenu";
|
|
24
|
+
|
|
25
|
+
export type ComponentCommand = Command<ComponentCommandData> & {
|
|
26
|
+
visibilityScopes: ComponentCommandVisibilityScope[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const isPlaceholder = (x: any): x is Placeholder => x.components !== undefined;
|
|
30
|
+
|
|
31
|
+
export function getSelectedComponentCommands(editContext: EditContextType) {
|
|
32
|
+
const selection = editContext.selection;
|
|
33
|
+
|
|
34
|
+
const selectedComponents = selection
|
|
35
|
+
.map((x) => getComponentById(x, editContext.page!))
|
|
36
|
+
.filter((x) => x) as Component[];
|
|
37
|
+
|
|
38
|
+
const componentCommands = getComponentCommands(
|
|
39
|
+
selectedComponents,
|
|
40
|
+
editContext
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const componentCommandMenuItems = componentCommands.filter(
|
|
44
|
+
(x) => x.visibilityScopes.indexOf("menu") >= 0
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return componentCommandMenuItems;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getComponentCommands(
|
|
51
|
+
entities: (Placeholder | Component)[],
|
|
52
|
+
editContext: EditContextType
|
|
53
|
+
): ComponentCommand[] {
|
|
54
|
+
const components = entities.filter(
|
|
55
|
+
(x) => x && !isPlaceholder(x)
|
|
56
|
+
) as Component[];
|
|
57
|
+
|
|
58
|
+
const commands = [
|
|
59
|
+
getCreateCommentCommand(),
|
|
60
|
+
getInsertCommand(components, editContext),
|
|
61
|
+
getDeleteCommand(components, editContext),
|
|
62
|
+
getDuplicateCommand(components, editContext),
|
|
63
|
+
getSyncCommand(entities, editContext),
|
|
64
|
+
getAiCommand(editContext),
|
|
65
|
+
getDesignCommand(components, editContext),
|
|
66
|
+
getLinkToMasterCommand(components, editContext),
|
|
67
|
+
getInheritChildrenFromMasterCommand(components, editContext),
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
return commands.filter((x) => x !== null);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getInsertCommand(
|
|
74
|
+
components: Component[],
|
|
75
|
+
editContext: EditContextType
|
|
76
|
+
): ComponentCommand | null {
|
|
77
|
+
if (components.length !== 1 || isPlaceholder(components[0])) return null;
|
|
78
|
+
const item = components[0];
|
|
79
|
+
if (!item) return null;
|
|
80
|
+
if (!item.placeholders || item.placeholders.length === 0) return null;
|
|
81
|
+
return {
|
|
82
|
+
id: "insert",
|
|
83
|
+
icon: "pi pi-plus",
|
|
84
|
+
label: "Insert component",
|
|
85
|
+
disabled: (context) => !context.editContext.page?.item.canWriteItem,
|
|
86
|
+
visibilityScopes: ["editFrame", "contextMenu"],
|
|
87
|
+
execute: async () => {
|
|
88
|
+
editContext.setSelectedForInsertion(item.id);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function getDuplicateCommand(
|
|
94
|
+
components: Component[],
|
|
95
|
+
editContext: EditContextType
|
|
96
|
+
): ComponentCommand | null {
|
|
97
|
+
if (components.length !== 1) return null;
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
id: "duplicate",
|
|
101
|
+
icon: "pi pi-copy",
|
|
102
|
+
label: "Duplicate",
|
|
103
|
+
visibilityScopes: ["contextMenu", "menu"],
|
|
104
|
+
disabled: (c) => !(c.editContext.page?.item.canWriteItem || false),
|
|
105
|
+
execute: async (context: CommandContext<any>) => {
|
|
106
|
+
// if (!components[0].parentPlaceholder?.parentComponent.datasourceItem)
|
|
107
|
+
// return;
|
|
108
|
+
|
|
109
|
+
editContext.operations.duplicateComponents({
|
|
110
|
+
componentIds: components.map((x) => x.id),
|
|
111
|
+
});
|
|
112
|
+
context.event?.stopPropagation();
|
|
113
|
+
context.event?.preventDefault();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getAiCommand(editContext: EditContextType): ComponentCommand {
|
|
119
|
+
return {
|
|
120
|
+
id: "ai",
|
|
121
|
+
icon: "pi pi-sparkles",
|
|
122
|
+
label: "AI",
|
|
123
|
+
disabled: () => false,
|
|
124
|
+
|
|
125
|
+
execute: async (context: CommandContext<any>) => {
|
|
126
|
+
const event = context.event!;
|
|
127
|
+
editContext.showAiPopup(event as any);
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
event.stopPropagation();
|
|
130
|
+
},
|
|
131
|
+
visibilityScopes: ["editFrame", "contextMenu"],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getDesignCommand(
|
|
136
|
+
components: Component[],
|
|
137
|
+
editContext: EditContextType
|
|
138
|
+
): ComponentCommand | null {
|
|
139
|
+
if (components.length !== 1 || isPlaceholder(components[0])) return null;
|
|
140
|
+
const item = components[0];
|
|
141
|
+
if (!item) return null;
|
|
142
|
+
if (!item.datasourceItem?.fields) return null;
|
|
143
|
+
if (
|
|
144
|
+
!Object.values(item.datasourceItem.fields).find(
|
|
145
|
+
(x) => x.section === "Design"
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
return null;
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
id: "design",
|
|
152
|
+
icon: "pi pi-palette",
|
|
153
|
+
label: "Design",
|
|
154
|
+
disabled: () => false,
|
|
155
|
+
execute: async (context: CommandContext<any>) => {
|
|
156
|
+
editContext.showFieldEditorPopup(
|
|
157
|
+
item.datasourceItem?.fields || [],
|
|
158
|
+
["Design", "Rendering"],
|
|
159
|
+
context.event!
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
visibilityScopes: ["editFrame", "contextMenu"],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function getLinkToMasterCommand(
|
|
167
|
+
components: Component[],
|
|
168
|
+
editContext: EditContextType
|
|
169
|
+
): ComponentCommand | null {
|
|
170
|
+
if (!components.length) return null;
|
|
171
|
+
if (editContext.page?.item?.masterLanguages?.length === 0) return null;
|
|
172
|
+
|
|
173
|
+
return getCheckboxCommand(
|
|
174
|
+
components,
|
|
175
|
+
editContext,
|
|
176
|
+
"componentLinkedToMasterLanguage",
|
|
177
|
+
"Linked To Master Language"
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function getCheckboxCommand(
|
|
182
|
+
components: Component[],
|
|
183
|
+
editContext: EditContextType,
|
|
184
|
+
fieldName: string,
|
|
185
|
+
label: string
|
|
186
|
+
): ComponentCommand | null {
|
|
187
|
+
const someLinked = components.find(
|
|
188
|
+
(x) =>
|
|
189
|
+
x.datasourceItem?.fields.find((x) => x.name === fieldName)?.rawValue ===
|
|
190
|
+
"1"
|
|
191
|
+
);
|
|
192
|
+
const allLinked = !components.find(
|
|
193
|
+
(x) =>
|
|
194
|
+
x.datasourceItem?.fields.find((x) => x.name === fieldName)?.rawValue !==
|
|
195
|
+
"1"
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
id: fieldName,
|
|
200
|
+
icon:
|
|
201
|
+
"pi pi-" +
|
|
202
|
+
(allLinked ? "check-square" : someLinked ? "stop-circle" : "stop"),
|
|
203
|
+
label,
|
|
204
|
+
disabled: () => false,
|
|
205
|
+
execute: async () => {
|
|
206
|
+
components.forEach((c) => {
|
|
207
|
+
const field = c.datasourceItem?.fields.find(
|
|
208
|
+
(x) => x.name === fieldName
|
|
209
|
+
);
|
|
210
|
+
if (!field) return;
|
|
211
|
+
editContext.operations.editField({
|
|
212
|
+
field: field.descriptor,
|
|
213
|
+
rawValue: allLinked ? "" : "1",
|
|
214
|
+
refresh: "immediate",
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
visibilityScopes: ["menu", "contextMenu"],
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function getInheritChildrenFromMasterCommand(
|
|
223
|
+
components: Component[],
|
|
224
|
+
editContext: EditContextType
|
|
225
|
+
): ComponentCommand | null {
|
|
226
|
+
if (!components.length) return null;
|
|
227
|
+
if (editContext.page?.item?.masterLanguages?.length === 0) return null;
|
|
228
|
+
if (components.find((x) => !x.placeholders || x.placeholders.length === 0))
|
|
229
|
+
return null;
|
|
230
|
+
|
|
231
|
+
return getCheckboxCommand(
|
|
232
|
+
components,
|
|
233
|
+
editContext,
|
|
234
|
+
"inheritChildrenFromMasterLanguage",
|
|
235
|
+
"Inherit Children From Master"
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function isLocked(c: Component, editContext: EditContextType): boolean {
|
|
240
|
+
if (
|
|
241
|
+
editContext.activeSessions.find(
|
|
242
|
+
(x) =>
|
|
243
|
+
x.fieldLock?.item.id === c.id &&
|
|
244
|
+
x.fieldLock.item.language == c.datasourceItem?.language &&
|
|
245
|
+
x.fieldLock.item.version === c.datasourceItem?.version &&
|
|
246
|
+
x.sessionId !== editContext.sessionId
|
|
247
|
+
) !== undefined
|
|
248
|
+
) {
|
|
249
|
+
return true;
|
|
250
|
+
} else
|
|
251
|
+
return (
|
|
252
|
+
c.placeholders?.find(
|
|
253
|
+
(x) =>
|
|
254
|
+
x.components.find((child) => isLocked(child, editContext)) !==
|
|
255
|
+
undefined
|
|
256
|
+
) !== undefined
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function getDeleteCommand(
|
|
261
|
+
components: Component[],
|
|
262
|
+
editContext: EditContextType
|
|
263
|
+
): ComponentCommand | null {
|
|
264
|
+
const applicableComponents = components.filter(
|
|
265
|
+
(c) =>
|
|
266
|
+
((!isPlaceholder(c) && !c.layoutId) ||
|
|
267
|
+
c.layoutId === editContext.page?.item.id) &&
|
|
268
|
+
!isLocked(c, editContext) &&
|
|
269
|
+
editContext.page?.item.canWriteItem
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
if (applicableComponents.length === 0) return null;
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
id: "delete",
|
|
276
|
+
label: "Delete",
|
|
277
|
+
icon: "pi pi-fw pi-trash",
|
|
278
|
+
execute: async (context: CommandContext<any>) =>
|
|
279
|
+
deleteComponents(applicableComponents, context.editContext),
|
|
280
|
+
disabled: () =>
|
|
281
|
+
applicableComponents.length === 0 ||
|
|
282
|
+
applicableComponents.length !== components.length,
|
|
283
|
+
|
|
284
|
+
visibilityScopes: ["editFrame", "menu", "contextMenu"],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function canSynchronize(placeholderData: Placeholder) {
|
|
289
|
+
if (placeholderData.canSynchronize) return true;
|
|
290
|
+
placeholderData.components.forEach((c) => {
|
|
291
|
+
if (c.placeholders?.find((x) => canSynchronize(x))) return true;
|
|
292
|
+
});
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function getSyncCommand(
|
|
297
|
+
components: (Placeholder | Component)[],
|
|
298
|
+
editContext: EditContextType
|
|
299
|
+
): ComponentCommand {
|
|
300
|
+
const placeholders: PlaceholderToSynchronize[] = [];
|
|
301
|
+
|
|
302
|
+
for (const component of components) {
|
|
303
|
+
if (isPlaceholder(component) && canSynchronize(component)) {
|
|
304
|
+
placeholders.push({
|
|
305
|
+
item: component.parentComponent
|
|
306
|
+
? getItemDescriptor(component.parentComponent, editContext)
|
|
307
|
+
: undefined,
|
|
308
|
+
});
|
|
309
|
+
} else {
|
|
310
|
+
if (
|
|
311
|
+
(component as Component).placeholders?.find((x) => canSynchronize(x))
|
|
312
|
+
) {
|
|
313
|
+
placeholders.push({
|
|
314
|
+
item: getItemDescriptor(component as Component, editContext),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const canSync =
|
|
321
|
+
placeholders.length > 0 ||
|
|
322
|
+
(components.length === 0 &&
|
|
323
|
+
editContext.page?.rootComponent.placeholders.find((x) =>
|
|
324
|
+
canSynchronize(x)
|
|
325
|
+
));
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
id: "synchronize",
|
|
329
|
+
label: "Synchronize",
|
|
330
|
+
icon: "pi pi-fw pi-sync",
|
|
331
|
+
disabled: () => !canSync,
|
|
332
|
+
visibilityScopes: ["menu", "editFrame", "contextMenu"],
|
|
333
|
+
execute: async () => {
|
|
334
|
+
const op: SynchronizeComponentsOperation = {
|
|
335
|
+
mainItem: editContext.page!.item.descriptor,
|
|
336
|
+
type: "synchronize-components",
|
|
337
|
+
date: new Date().toISOString(),
|
|
338
|
+
delete: false,
|
|
339
|
+
id: uuid(),
|
|
340
|
+
placeholders: placeholders,
|
|
341
|
+
|
|
342
|
+
description: "Synchronize components",
|
|
343
|
+
};
|
|
344
|
+
editContext.operations.executeEditOperation(op);
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function deleteComponents(
|
|
350
|
+
components: Component[],
|
|
351
|
+
editContext: EditContextType
|
|
352
|
+
) {
|
|
353
|
+
if (!components.length) return;
|
|
354
|
+
|
|
355
|
+
editContext.confirm({
|
|
356
|
+
showCancel: true,
|
|
357
|
+
message:
|
|
358
|
+
(components.length > 1
|
|
359
|
+
? "Are you sure you want to remove these components? "
|
|
360
|
+
: "Are you sure you want to remove this component? ") +
|
|
361
|
+
components.map((x) => x.name).join(", "),
|
|
362
|
+
header: components.length > 1 ? "Remove components" : "Remove component",
|
|
363
|
+
icon: "pi pi-exclamation-triangle",
|
|
364
|
+
accept: () => {
|
|
365
|
+
if (!editContext.page?.item.descriptor) return;
|
|
366
|
+
console.log("Remove components", components);
|
|
367
|
+
const op: RemoveComponentOperation = {
|
|
368
|
+
type: "remove-component",
|
|
369
|
+
date: new Date().toISOString(),
|
|
370
|
+
id: uuid(),
|
|
371
|
+
componentIds: components.map((x) => x.id),
|
|
372
|
+
mainItem: editContext.page.item.descriptor,
|
|
373
|
+
description:
|
|
374
|
+
"Remove components: " + components.map((x) => x.name).join(", "),
|
|
375
|
+
};
|
|
376
|
+
editContext.operations.executeEditOperation(op);
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function getCreateCommentCommand(): ComponentCommand | null {
|
|
382
|
+
// if (components.length !== 1 || isPlaceholder(components[0])) return null;
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
id: "addComment",
|
|
386
|
+
label: "Add Comment",
|
|
387
|
+
icon: "pi pi-comment",
|
|
388
|
+
disabled: () => false,
|
|
389
|
+
visibilityScopes: ["contextMenu"],
|
|
390
|
+
execute: async (context: CommandContext<any>) => {
|
|
391
|
+
context.editContext.addComment();
|
|
392
|
+
context.editContext.switchView("reviews");
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function getItemDescriptor(
|
|
398
|
+
component: Component,
|
|
399
|
+
editContext: EditContextType
|
|
400
|
+
): ItemDescriptor | null {
|
|
401
|
+
return {
|
|
402
|
+
id: component.id,
|
|
403
|
+
language:
|
|
404
|
+
component.datasourceItem?.language || editContext.page!.item.language,
|
|
405
|
+
version:
|
|
406
|
+
component.datasourceItem?.version || editContext.page!.item.version,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|