@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,462 @@
|
|
|
1
|
+
import Cookies from "universal-cookie";
|
|
2
|
+
import {
|
|
3
|
+
EditOperation,
|
|
4
|
+
FieldDescriptor,
|
|
5
|
+
FieldHistoryItem,
|
|
6
|
+
InsertOption,
|
|
7
|
+
User,
|
|
8
|
+
} from "../../types";
|
|
9
|
+
import { ItemTreeNodeData } from "./contentService";
|
|
10
|
+
import { ExecutionResult, get, post } from "./serviceHelper";
|
|
11
|
+
import {
|
|
12
|
+
Field,
|
|
13
|
+
FieldButton,
|
|
14
|
+
ItemDescriptor,
|
|
15
|
+
ItemIdAndName,
|
|
16
|
+
} from "../pageModel";
|
|
17
|
+
import { PictureRawValue } from "../fieldTypes";
|
|
18
|
+
|
|
19
|
+
export type PlaceholderInsertOptions = {
|
|
20
|
+
key: string;
|
|
21
|
+
insertOptions: InsertOption[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type { ExecutionResult } from "./serviceHelper";
|
|
25
|
+
|
|
26
|
+
export function connectSocket(sessionId: string): WebSocket {
|
|
27
|
+
const host = window.location.hostname;
|
|
28
|
+
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
29
|
+
const port = window.location.port ? `:${window.location.port}` : "";
|
|
30
|
+
|
|
31
|
+
const socketUrl = `${protocol}//${host}${port}/alpaca/editor/socket?sessionId=${sessionId}`;
|
|
32
|
+
|
|
33
|
+
console.log("Connect to socket: " + socketUrl);
|
|
34
|
+
|
|
35
|
+
return new WebSocket(socketUrl);
|
|
36
|
+
}
|
|
37
|
+
export async function getPictureValue(
|
|
38
|
+
field: Field,
|
|
39
|
+
pictureRawValue: PictureRawValue,
|
|
40
|
+
site: string,
|
|
41
|
+
sessionId: string,
|
|
42
|
+
) {
|
|
43
|
+
const fieldItem = field.descriptor.item;
|
|
44
|
+
if (!fieldItem) return;
|
|
45
|
+
|
|
46
|
+
const response = await fetch(
|
|
47
|
+
"/alpaca/editor/getPictureValue?sessionId=" + sessionId,
|
|
48
|
+
{
|
|
49
|
+
method: "POST",
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
site,
|
|
52
|
+
itemId: fieldItem.id,
|
|
53
|
+
itemLanguage: fieldItem.language,
|
|
54
|
+
itemVersion: fieldItem.version,
|
|
55
|
+
pictureFieldId: field.id,
|
|
56
|
+
pictureValue: JSON.stringify(pictureRawValue),
|
|
57
|
+
}),
|
|
58
|
+
credentials: "include",
|
|
59
|
+
headers: {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
Cookie: new Cookies().getAll(),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
return await response.json();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function executeEditOperation(
|
|
69
|
+
editOperation: EditOperation,
|
|
70
|
+
sessionId: string,
|
|
71
|
+
): Promise<ExecutionResult<unknown>> {
|
|
72
|
+
editOperation.sessionId = sessionId;
|
|
73
|
+
|
|
74
|
+
return post("/alpaca/editor/edit", editOperation, sessionId);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function executeUndo(
|
|
78
|
+
sessionId: string,
|
|
79
|
+
editOperationIds: string[],
|
|
80
|
+
): Promise<ExecutionResult<any>> {
|
|
81
|
+
return post("/alpaca/editor/undo", { editOperationIds }, sessionId);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function executeRedo(
|
|
85
|
+
sessionId: string,
|
|
86
|
+
editOperationId: string,
|
|
87
|
+
): Promise<ExecutionResult<any>> {
|
|
88
|
+
return post(
|
|
89
|
+
"/alpaca/editor/redo",
|
|
90
|
+
{ editOperationIds: [editOperationId] },
|
|
91
|
+
sessionId,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function executeDeleteItems(
|
|
96
|
+
items: ItemDescriptor[],
|
|
97
|
+
): Promise<ExecutionResult<any>> {
|
|
98
|
+
return post("/alpaca/editor/deleteItems", items);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getItemDescriptor(item: ItemDescriptor) {
|
|
102
|
+
return {
|
|
103
|
+
id: item.id,
|
|
104
|
+
language: item.language,
|
|
105
|
+
version: item.version,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function lockItems(
|
|
110
|
+
items: ItemDescriptor[],
|
|
111
|
+
): Promise<ExecutionResult<any>> {
|
|
112
|
+
const response = await post(
|
|
113
|
+
"/alpaca/editor/lock",
|
|
114
|
+
items.map(getItemDescriptor),
|
|
115
|
+
);
|
|
116
|
+
return response;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function unlockItems(
|
|
120
|
+
items: ItemDescriptor[],
|
|
121
|
+
): Promise<ExecutionResult<any>> {
|
|
122
|
+
const response = await post(
|
|
123
|
+
"/alpaca/editor/unlock",
|
|
124
|
+
items.map(getItemDescriptor),
|
|
125
|
+
);
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function lockField(
|
|
130
|
+
item: ItemDescriptor,
|
|
131
|
+
fieldId: string,
|
|
132
|
+
sessionId: string,
|
|
133
|
+
): Promise<ExecutionResult<any>> {
|
|
134
|
+
const response = await post("/alpaca/editor/lockField", {
|
|
135
|
+
item,
|
|
136
|
+
fieldId: fieldId,
|
|
137
|
+
sessionId: sessionId,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return response;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function releaseFieldLocks(
|
|
144
|
+
sessionId: string,
|
|
145
|
+
): Promise<ExecutionResult<any>> {
|
|
146
|
+
const response = await post("/alpaca/editor/releaseFieldLocks", {
|
|
147
|
+
sessionId,
|
|
148
|
+
});
|
|
149
|
+
return response;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function validateItems(
|
|
153
|
+
items: ItemDescriptor[],
|
|
154
|
+
sessionId: string,
|
|
155
|
+
): Promise<ExecutionResult<any>> {
|
|
156
|
+
const response = await post(
|
|
157
|
+
"/alpaca/editor/validate",
|
|
158
|
+
items.map(getItemDescriptor),
|
|
159
|
+
sessionId,
|
|
160
|
+
);
|
|
161
|
+
if (response.type !== "success") return response;
|
|
162
|
+
|
|
163
|
+
return await response;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function executeWorkflowCommand(
|
|
167
|
+
item: ItemDescriptor,
|
|
168
|
+
commandId: string,
|
|
169
|
+
comment: string,
|
|
170
|
+
): Promise<ExecutionResult<any>> {
|
|
171
|
+
const response = await post("/alpaca/editor/executeWorkflowCommand", {
|
|
172
|
+
item,
|
|
173
|
+
commandId,
|
|
174
|
+
comment,
|
|
175
|
+
});
|
|
176
|
+
return response;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function executeFieldAction(
|
|
180
|
+
item: ItemDescriptor,
|
|
181
|
+
fieldId: string,
|
|
182
|
+
pageItem: ItemDescriptor,
|
|
183
|
+
action: string,
|
|
184
|
+
sessionId: string,
|
|
185
|
+
selectedText: string,
|
|
186
|
+
callback: (data: any) => void,
|
|
187
|
+
): Promise<ExecutionResult<any>> {
|
|
188
|
+
const response = await fetch(
|
|
189
|
+
"/alpaca/editor/executeFieldAction?sessionId=" + sessionId,
|
|
190
|
+
{
|
|
191
|
+
method: "POST",
|
|
192
|
+
body: JSON.stringify({
|
|
193
|
+
item,
|
|
194
|
+
pageItem,
|
|
195
|
+
fieldId,
|
|
196
|
+
action,
|
|
197
|
+
selectedText,
|
|
198
|
+
sessionId,
|
|
199
|
+
}),
|
|
200
|
+
credentials: "include",
|
|
201
|
+
headers: {
|
|
202
|
+
"Content-Type": "application/json",
|
|
203
|
+
Cookie: new Cookies().getAll(),
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
if (response.status === 500 || response.redirected) {
|
|
208
|
+
return {
|
|
209
|
+
type: "error",
|
|
210
|
+
summary: "Error",
|
|
211
|
+
details: "An error occured executing the field action.",
|
|
212
|
+
response,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (response.status === 401) {
|
|
217
|
+
return {
|
|
218
|
+
type: "error",
|
|
219
|
+
summary: "Unauthorized",
|
|
220
|
+
details: "Not logged in anymore?",
|
|
221
|
+
response,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!response?.body)
|
|
226
|
+
return {
|
|
227
|
+
type: "error",
|
|
228
|
+
summary: "Error",
|
|
229
|
+
details: "An error occured.",
|
|
230
|
+
response,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const reader = response.body.getReader();
|
|
234
|
+
const decoder = new TextDecoder();
|
|
235
|
+
let buffer = "";
|
|
236
|
+
|
|
237
|
+
let result = null;
|
|
238
|
+
|
|
239
|
+
while (true) {
|
|
240
|
+
const { done, value } = await reader.read();
|
|
241
|
+
|
|
242
|
+
if (done) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
buffer += decoder.decode(value, { stream: true }); // 'stream: true' ensures that any incomplete multi-byte characters aren't malformed.
|
|
247
|
+
|
|
248
|
+
// Split the buffer by newline and keep the last partial line for the next iteration.
|
|
249
|
+
const lines = buffer.split("\n");
|
|
250
|
+
|
|
251
|
+
if (lines.length > 0) {
|
|
252
|
+
buffer = lines.pop() || ""; // Incomplete line (if any) is kept for the next iteration.
|
|
253
|
+
|
|
254
|
+
for (let line of lines) {
|
|
255
|
+
if (line.trim() === "") continue; // Skip empty lines if any.
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
const jsonData = JSON.parse(line);
|
|
259
|
+
callback(jsonData);
|
|
260
|
+
result = jsonData;
|
|
261
|
+
} catch (e) {
|
|
262
|
+
console.error("Error parsing line:" + line, e);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// If there's any remaining content in the buffer after processing all chunks, try to process it.
|
|
269
|
+
if (buffer.trim() !== "") {
|
|
270
|
+
try {
|
|
271
|
+
const jsonData = JSON.parse(buffer);
|
|
272
|
+
result = jsonData;
|
|
273
|
+
} catch (e) {
|
|
274
|
+
console.error("Error parsing the final buffer content:", e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
callback(result);
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export async function createVersion(
|
|
282
|
+
page: ItemDescriptor,
|
|
283
|
+
sessionId: string,
|
|
284
|
+
): Promise<ExecutionResult<any>> {
|
|
285
|
+
const response = await fetch(
|
|
286
|
+
// configuration.services.editorService.baseUrl +
|
|
287
|
+
"/alpaca/editor/createVersion?sessionId=" + sessionId,
|
|
288
|
+
{
|
|
289
|
+
method: "POST",
|
|
290
|
+
body: JSON.stringify({
|
|
291
|
+
item: page,
|
|
292
|
+
}),
|
|
293
|
+
credentials: "include",
|
|
294
|
+
headers: {
|
|
295
|
+
"Content-Type": "application/json",
|
|
296
|
+
Cookie: new Cookies().getAll(),
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
if (response.ok) return { type: "success", response };
|
|
302
|
+
else {
|
|
303
|
+
if (response.status === 401) {
|
|
304
|
+
return {
|
|
305
|
+
type: "error",
|
|
306
|
+
summary: "Unauthorized",
|
|
307
|
+
details: "Not logged in anymore?",
|
|
308
|
+
response,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
type: "error",
|
|
314
|
+
summary: "Error",
|
|
315
|
+
details: "An error occured while saving changes.",
|
|
316
|
+
response,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export async function deleteVersion(
|
|
322
|
+
page: ItemDescriptor,
|
|
323
|
+
sessionId: string,
|
|
324
|
+
): Promise<ExecutionResult<any>> {
|
|
325
|
+
const url = "/alpaca/editor/deleteVersion?sessionId=" + sessionId;
|
|
326
|
+
return await post<any>(url, { item: getItemDescriptor(page) });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export async function loadInsertOptions(
|
|
330
|
+
item: ItemDescriptor,
|
|
331
|
+
): Promise<ItemTreeNodeData[]> {
|
|
332
|
+
let url =
|
|
333
|
+
//configuration.services.editorService.baseUrl +
|
|
334
|
+
"/alpaca/editor/insertoptions";
|
|
335
|
+
|
|
336
|
+
const response = await fetch(url, {
|
|
337
|
+
method: "POST",
|
|
338
|
+
credentials: "include",
|
|
339
|
+
body: JSON.stringify(item),
|
|
340
|
+
headers: {
|
|
341
|
+
"Content-Type": "application/json",
|
|
342
|
+
Cookie: new Cookies().getAll(),
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
return await response.json();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export async function loadPlaceholderInsertOptions(
|
|
349
|
+
pageItem: ItemDescriptor,
|
|
350
|
+
placeholderKeys: string[],
|
|
351
|
+
): Promise<PlaceholderInsertOptions[]> {
|
|
352
|
+
let url = "/alpaca/editor/placeholderinsertoptions";
|
|
353
|
+
|
|
354
|
+
const response = await fetch(url, {
|
|
355
|
+
method: "POST",
|
|
356
|
+
credentials: "include",
|
|
357
|
+
body: JSON.stringify({ pageItem, placeholderKeys }),
|
|
358
|
+
headers: {
|
|
359
|
+
"Content-Type": "application/json",
|
|
360
|
+
Cookie: new Cookies().getAll(),
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
return await response.json();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export async function loadFieldButtons(
|
|
367
|
+
field: FieldDescriptor,
|
|
368
|
+
): Promise<FieldButton[]> {
|
|
369
|
+
let url =
|
|
370
|
+
//configuration.services.editorService.baseUrl +
|
|
371
|
+
"/alpaca/editor/fieldbuttons";
|
|
372
|
+
|
|
373
|
+
const response = await fetch(url, {
|
|
374
|
+
method: "POST",
|
|
375
|
+
credentials: "include",
|
|
376
|
+
body: JSON.stringify(field),
|
|
377
|
+
headers: {
|
|
378
|
+
"Content-Type": "application/json",
|
|
379
|
+
Cookie: new Cookies().getAll(),
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
return await response.json();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export async function getLookupSources(
|
|
386
|
+
field: Field,
|
|
387
|
+
sessionId: string,
|
|
388
|
+
): Promise<ItemIdAndName[]> {
|
|
389
|
+
let url = "/alpaca/editor/getlookupsources";
|
|
390
|
+
const fieldItem = field.descriptor.item;
|
|
391
|
+
|
|
392
|
+
const response = await post<ItemIdAndName[]>(
|
|
393
|
+
url,
|
|
394
|
+
{ item: fieldItem, fieldId: field.id },
|
|
395
|
+
sessionId,
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
return (await response.data) || [];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export async function executeCreateItem(
|
|
402
|
+
parent: ItemDescriptor,
|
|
403
|
+
templateId: string,
|
|
404
|
+
name: string,
|
|
405
|
+
): Promise<ExecutionResult<any>> {
|
|
406
|
+
let url = "/alpaca/editor/createItem";
|
|
407
|
+
|
|
408
|
+
const resopnse = post<ItemDescriptor>(url, { parent, templateId, name });
|
|
409
|
+
return resopnse;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export async function getEditHistory(
|
|
413
|
+
item: ItemDescriptor,
|
|
414
|
+
): Promise<ExecutionResult<EditOperation[]>> {
|
|
415
|
+
let url =
|
|
416
|
+
"/alpaca/editor/editHistory?itemId=" +
|
|
417
|
+
item.id +
|
|
418
|
+
"&language=" +
|
|
419
|
+
item.language +
|
|
420
|
+
"&version=" +
|
|
421
|
+
item.version;
|
|
422
|
+
|
|
423
|
+
const result = get<EditOperation[]>(url);
|
|
424
|
+
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export async function getFieldHistory(
|
|
429
|
+
item: ItemDescriptor,
|
|
430
|
+
fieldId: string,
|
|
431
|
+
): Promise<ExecutionResult<FieldHistoryItem[]>> {
|
|
432
|
+
let url =
|
|
433
|
+
"/alpaca/editor/fieldHistory?itemId=" +
|
|
434
|
+
item.id +
|
|
435
|
+
"&language=" +
|
|
436
|
+
item.language +
|
|
437
|
+
"&version=" +
|
|
438
|
+
item.version +
|
|
439
|
+
"&fieldId=" +
|
|
440
|
+
fieldId;
|
|
441
|
+
|
|
442
|
+
const result = get<FieldHistoryItem[]>(url);
|
|
443
|
+
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export async function getUserInfo(): Promise<User> {
|
|
448
|
+
const response = await fetch("/alpaca/editor/userinfo");
|
|
449
|
+
return await response.json();
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export async function executeMoveItems(
|
|
453
|
+
items: ItemDescriptor[],
|
|
454
|
+
target: ItemDescriptor,
|
|
455
|
+
index: number,
|
|
456
|
+
): Promise<ExecutionResult<any>> {
|
|
457
|
+
return post("/alpaca/editor/moveItems", {
|
|
458
|
+
items: items.map(getItemDescriptor),
|
|
459
|
+
target: getItemDescriptor(target),
|
|
460
|
+
index,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IndexStatus } from "../../types";
|
|
2
|
+
import { get, post } from "./serviceHelper";
|
|
3
|
+
|
|
4
|
+
export async function getIndexStatus(index: string) {
|
|
5
|
+
var result = await get<IndexStatus>("/alpaca/headless/editor/index/status?name=" + index);
|
|
6
|
+
return result.data;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function setupIndex(index: string) {
|
|
10
|
+
await post("/alpaca/headless/editor/index/setup?name=" + index, {});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function setupRebuildJob(index: string) {
|
|
14
|
+
await post("/alpaca/headless/editor/index/setuprebuildjob?name=" + index, {});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function rebuildIndex(index: string) {
|
|
18
|
+
await post("/alpaca/headless/editor/index/rebuild?name=" + index, {});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function getIndexes(): Promise<string[]> {
|
|
22
|
+
var result = await get<string[]>("/alpaca/headless/editor/index/list");
|
|
23
|
+
return result.data || [];
|
|
24
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
import { get, post } from "./serviceHelper";
|
|
3
|
+
import { Comment, Review, Reviewer } from "../../types";
|
|
4
|
+
import { ItemDescriptor } from "../pageModel";
|
|
5
|
+
|
|
6
|
+
export function createOrUpdateComment(comment: Comment) {
|
|
7
|
+
return post("/alpaca/editor/comments/save", comment);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getComments(itemId: string, language: string, version: number) {
|
|
11
|
+
return get<Comment[]>(`/alpaca/editor/comments/index?mainItemId=${itemId}&language=${language}&version=${version}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function resolveComment(comment: Comment) {
|
|
15
|
+
return post(`/alpaca/editor/comments/resolve?commentId=${comment.id}`, {});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function deleteComment(comment: Comment) {
|
|
19
|
+
return post(`/alpaca/editor/comments/delete?commentId=${comment.id}`, {});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getReviewers(itemId: string, language: string) {
|
|
23
|
+
return get<Reviewer[]>(`/alpaca/editor/reviews/reviewers?itemId=${itemId}&language=${language}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getReviews(itemId: string, language: string, version: number) {
|
|
27
|
+
return get<Review[]>(`/alpaca/editor/reviews/index?itemId=${itemId}&language=${language}&version=${version}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function inviteReviewer(review: Review) {
|
|
31
|
+
return post(`/alpaca/editor/reviews/invite`, review);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function addReview(review:Review) {
|
|
35
|
+
return post(`/alpaca/editor/reviews/add`, review);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function approveReview(itemDescriptor: ItemDescriptor) {
|
|
39
|
+
return post(`/alpaca/editor/reviews/approve`, itemDescriptor);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function rejectReview(itemDescriptor: ItemDescriptor) {
|
|
43
|
+
return post(`/alpaca/editor/reviews/reject`, itemDescriptor);
|
|
44
|
+
}
|
|
45
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export type ExecutionResult<T> = {
|
|
2
|
+
type: "success" | "error" | "unauthorized";
|
|
3
|
+
summary?: string;
|
|
4
|
+
details?: string;
|
|
5
|
+
response: Response;
|
|
6
|
+
data?: T;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export async function post<T>(
|
|
10
|
+
url: string,
|
|
11
|
+
body: any,
|
|
12
|
+
session?: string
|
|
13
|
+
): Promise<ExecutionResult<T>> {
|
|
14
|
+
if (session) url += "?sessionId=" + session;
|
|
15
|
+
|
|
16
|
+
const response = await fetch(
|
|
17
|
+
url,
|
|
18
|
+
{
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: JSON.stringify(body),
|
|
21
|
+
credentials: "include",
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return handleResponse<T>(response);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function get<T>(
|
|
32
|
+
url: string,
|
|
33
|
+
session?: string
|
|
34
|
+
): Promise<ExecutionResult<T>> {
|
|
35
|
+
if (session) url += "?sessionId=" + session;
|
|
36
|
+
const response = await fetch(
|
|
37
|
+
url,
|
|
38
|
+
{
|
|
39
|
+
method: "GET",
|
|
40
|
+
credentials: "include",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return handleResponse<T>(response);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function handleResponse<T>(
|
|
51
|
+
response: Response,
|
|
52
|
+
): Promise<ExecutionResult<T>> {
|
|
53
|
+
if (response.status === 400) {
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
return {
|
|
56
|
+
type: "error",
|
|
57
|
+
summary: data.summary,
|
|
58
|
+
details: data.details,
|
|
59
|
+
response,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (response.status === 500 || response.redirected) {
|
|
64
|
+
return {
|
|
65
|
+
type: "error",
|
|
66
|
+
summary: "Error",
|
|
67
|
+
details: await response.text(),
|
|
68
|
+
response,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (response.status === 401) {
|
|
73
|
+
return {
|
|
74
|
+
type: "unauthorized",
|
|
75
|
+
summary: "Unauthorized",
|
|
76
|
+
details: "Not logged in anymore?",
|
|
77
|
+
response,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (response.status !== 200) {
|
|
82
|
+
return { type: "error", response, details: await response.text() };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!response.headers.get("content-type")?.includes("application/json")) {
|
|
86
|
+
return {
|
|
87
|
+
type: "success",
|
|
88
|
+
response,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const data = (await response.json()) as T;
|
|
93
|
+
|
|
94
|
+
return { type: "success", response, data };
|
|
95
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TranslationStatus } from "../../config/types";
|
|
2
|
+
import { LanguagesAndVersions } from "../../types";
|
|
3
|
+
import { get, post } from "./serviceHelper";
|
|
4
|
+
|
|
5
|
+
export async function requestTranslation({itemId, targetLanguage, sourceLanguage, sessionId, provider}: {itemId: string, targetLanguage: string, sourceLanguage: string, sessionId: string, provider: string} ) {
|
|
6
|
+
return await post<LanguagesAndVersions>(
|
|
7
|
+
"/alpaca/editor/translation/requestTranslation",
|
|
8
|
+
{ itemId, targetLanguage, sourceLanguage, sessionId, provider }
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export async function getTranslationStatus(itemId: string) {
|
|
14
|
+
return await get<TranslationStatus[]>(
|
|
15
|
+
`/alpaca/editor/translation/getTranslations?itemId=${itemId}`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function getTranslationProviders() {
|
|
20
|
+
return await get<string[]>(`/alpaca/editor/translation/providers`);
|
|
21
|
+
}
|