@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,316 +0,0 @@
|
|
|
1
|
-
import { SuggestedEdit as SuggestedEditType } from "../../types";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { useEditContext } from "../client/editContext";
|
|
4
|
-
import {
|
|
5
|
-
deleteSuggestedEdit,
|
|
6
|
-
createOrUpdateSuggestedEdit,
|
|
7
|
-
} from "../services/suggestedEditsService";
|
|
8
|
-
import { Button } from "../../components/ui/button";
|
|
9
|
-
import { formatDate } from "../utils";
|
|
10
|
-
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
11
|
-
import { OverlayPanel } from "primereact/overlaypanel";
|
|
12
|
-
import { DiffView } from "./DiffView";
|
|
13
|
-
// Import lucide icons (adjust names as needed)
|
|
14
|
-
import { Trash2, GalleryVertical, Check, Brush, XCircle } from "lucide-react";
|
|
15
|
-
// Import patch functions from the diff library.
|
|
16
|
-
import { createPatch, applyPatch } from "diff";
|
|
17
|
-
import { cn } from "../../lib/utils";
|
|
18
|
-
|
|
19
|
-
export function SuggestedEditComponent({ edit }: { edit: SuggestedEditType }) {
|
|
20
|
-
const editContext = useEditContext();
|
|
21
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
22
|
-
const overlayPanelRef = useRef<OverlayPanel>(null);
|
|
23
|
-
const [item, setItem] = useState<any>(null);
|
|
24
|
-
const [patchPossible, setPatchPossible] = useState<boolean>(true);
|
|
25
|
-
|
|
26
|
-
const [patchWarning, setPatchWarning] = useState<string>("");
|
|
27
|
-
const [applied, setApplied] = useState<boolean>(false);
|
|
28
|
-
|
|
29
|
-
const [ignoreFormatting, setIgnoreFormatting] = useState(true);
|
|
30
|
-
const [clipUnchanged, setClipUnchanged] = useState(true);
|
|
31
|
-
|
|
32
|
-
const canApply = editContext?.mode === "edit" && edit.status !== "Applied";
|
|
33
|
-
|
|
34
|
-
// Load the full item from the repository.
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (
|
|
37
|
-
editContext?.itemsRepository &&
|
|
38
|
-
edit.itemId &&
|
|
39
|
-
edit.mainItemLanguage &&
|
|
40
|
-
edit.mainItemVersion !== undefined
|
|
41
|
-
) {
|
|
42
|
-
editContext.itemsRepository
|
|
43
|
-
.getItem({
|
|
44
|
-
id: edit.itemId,
|
|
45
|
-
language: edit.mainItemLanguage,
|
|
46
|
-
version: edit.mainItemVersion,
|
|
47
|
-
})
|
|
48
|
-
.then((loadedItem) => {
|
|
49
|
-
setItem(loadedItem);
|
|
50
|
-
// When the item loads, check if the patch is applicable.
|
|
51
|
-
checkAndComputePatch(loadedItem);
|
|
52
|
-
})
|
|
53
|
-
.catch((err) => {
|
|
54
|
-
console.error("Error loading item:", err);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}, [
|
|
58
|
-
edit.itemId,
|
|
59
|
-
edit.mainItemLanguage,
|
|
60
|
-
edit.mainItemVersion,
|
|
61
|
-
editContext?.itemsRepository,
|
|
62
|
-
]);
|
|
63
|
-
|
|
64
|
-
// Determine if this suggested edit is selected based on the focused field.
|
|
65
|
-
const isSelected =
|
|
66
|
-
editContext?.focusedField &&
|
|
67
|
-
editContext.focusedField.fieldId === edit.fieldId &&
|
|
68
|
-
editContext.focusedField.item.id === edit.itemId;
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (isSelected && ref.current) {
|
|
72
|
-
ref.current.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
73
|
-
}
|
|
74
|
-
}, [isSelected]);
|
|
75
|
-
|
|
76
|
-
// When a suggested edit is clicked, update the focused field and select the item.
|
|
77
|
-
function handleSelectSuggestedEdit() {
|
|
78
|
-
if (edit.fieldId) {
|
|
79
|
-
editContext?.setFocusedField(
|
|
80
|
-
{
|
|
81
|
-
fieldId: edit.fieldId,
|
|
82
|
-
item: {
|
|
83
|
-
id: edit.itemId,
|
|
84
|
-
language: edit.mainItemLanguage,
|
|
85
|
-
version: edit.mainItemVersion,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
false,
|
|
89
|
-
);
|
|
90
|
-
// Also select the item.
|
|
91
|
-
editContext?.select?.([edit.itemId]);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Render contextual info by retrieving item and field names from the loaded item.
|
|
96
|
-
const renderContextInfo = () => {
|
|
97
|
-
const itemName = item ? item.name : null;
|
|
98
|
-
const fieldName =
|
|
99
|
-
item && item.fields
|
|
100
|
-
? item.fields.find(
|
|
101
|
-
(f: { id: string; name?: string }) => f.id === edit.fieldId,
|
|
102
|
-
)?.name
|
|
103
|
-
: null;
|
|
104
|
-
if (!itemName && !fieldName) return null;
|
|
105
|
-
return (
|
|
106
|
-
<div className="mt-3 flex items-center border-t pt-3 text-xs">
|
|
107
|
-
{itemName && <div className="text-2xs text-gray-500">{itemName}</div>}
|
|
108
|
-
{fieldName && itemName && (
|
|
109
|
-
<div className="text-2xs mx-2 text-gray-500">></div>
|
|
110
|
-
)}
|
|
111
|
-
{fieldName && <div className="text-2xs text-gray-500">{fieldName}</div>}
|
|
112
|
-
</div>
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Allow deletion only if the current user is the author.
|
|
117
|
-
const canDelete = edit.author === editContext?.user?.name;
|
|
118
|
-
|
|
119
|
-
// Render the header with author info, creation date, and control buttons.
|
|
120
|
-
const renderHeader = () => {
|
|
121
|
-
return (
|
|
122
|
-
<div className="mb-3 flex items-start justify-between">
|
|
123
|
-
<div>
|
|
124
|
-
<div className="text-xs font-bold text-gray-900" title={edit.author}>
|
|
125
|
-
{edit.authorDisplayName || edit.author}
|
|
126
|
-
</div>
|
|
127
|
-
<div className="text-xs text-gray-500">
|
|
128
|
-
{edit.created ? formatDate(new Date(edit.created)) : ""}
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
<div className="flex items-center gap-1">
|
|
132
|
-
{/* Show apply patch control if not yet applied */}
|
|
133
|
-
{canApply && !applied && patchPossible && (
|
|
134
|
-
<SimpleIconButton
|
|
135
|
-
className="text-gray-500"
|
|
136
|
-
icon={<Check size={14} />}
|
|
137
|
-
label="Apply"
|
|
138
|
-
onClick={handleApplyPatch}
|
|
139
|
-
/>
|
|
140
|
-
)}
|
|
141
|
-
{applied && (
|
|
142
|
-
<i
|
|
143
|
-
className="pi pi-check text-bold px-1 text-xs text-green-500"
|
|
144
|
-
title={
|
|
145
|
-
"Applied by " +
|
|
146
|
-
edit.updatedBy +
|
|
147
|
-
" (" +
|
|
148
|
-
formatDate(new Date(edit.updated!)) +
|
|
149
|
-
")"
|
|
150
|
-
}
|
|
151
|
-
></i>
|
|
152
|
-
)}
|
|
153
|
-
{canDelete && (
|
|
154
|
-
<SimpleIconButton
|
|
155
|
-
className="text-gray-500"
|
|
156
|
-
icon={<Trash2 size={14} />}
|
|
157
|
-
label="Delete"
|
|
158
|
-
onClick={(e: any) => overlayPanelRef.current?.toggle(e)}
|
|
159
|
-
/>
|
|
160
|
-
)}
|
|
161
|
-
<OverlayPanel ref={overlayPanelRef}>
|
|
162
|
-
<Button
|
|
163
|
-
className="m-2"
|
|
164
|
-
variant="outline"
|
|
165
|
-
onClick={async () => {
|
|
166
|
-
await deleteSuggestedEdit(edit);
|
|
167
|
-
}}
|
|
168
|
-
>
|
|
169
|
-
Delete
|
|
170
|
-
</Button>
|
|
171
|
-
</OverlayPanel>
|
|
172
|
-
</div>
|
|
173
|
-
</div>
|
|
174
|
-
);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// Render toggle buttons using SimpleIconButtons.
|
|
178
|
-
const renderDiffToggleButtons = () => {
|
|
179
|
-
return (
|
|
180
|
-
<div className="mb-2 flex gap-2">
|
|
181
|
-
<SimpleIconButton
|
|
182
|
-
icon={<Brush size={14} className="p-0.5" />}
|
|
183
|
-
label="Ignore Formatting"
|
|
184
|
-
onClick={() => setIgnoreFormatting((prev) => !prev)}
|
|
185
|
-
className={cn("text-gray-500", ignoreFormatting ? "bg-gray-200" : "")}
|
|
186
|
-
/>
|
|
187
|
-
<SimpleIconButton
|
|
188
|
-
icon={<GalleryVertical size={14} className="p-0.5" />}
|
|
189
|
-
label="Clip"
|
|
190
|
-
onClick={() => setClipUnchanged((prev) => !prev)}
|
|
191
|
-
className={cn("text-gray-500", clipUnchanged ? "bg-gray-200" : "")}
|
|
192
|
-
/>
|
|
193
|
-
</div>
|
|
194
|
-
);
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
// Helper: Check if the patch is applicable to the current field value.
|
|
198
|
-
async function checkAndComputePatch(loadedItem: any) {
|
|
199
|
-
const field = loadedItem?.fields?.find(
|
|
200
|
-
(f: { id: string }) => f.id === edit.fieldId,
|
|
201
|
-
);
|
|
202
|
-
if (!field) return;
|
|
203
|
-
const currentValue: string = field.rawValue || "";
|
|
204
|
-
const patch = createPatch("field", edit.oldValue, edit.newValue);
|
|
205
|
-
const patchedCandidate = applyPatch(currentValue, patch);
|
|
206
|
-
if (patchedCandidate === false || typeof patchedCandidate !== "string") {
|
|
207
|
-
setPatchPossible(false);
|
|
208
|
-
setPatchWarning("Patch cannot be applied cleanly.");
|
|
209
|
-
} else {
|
|
210
|
-
setPatchPossible(true);
|
|
211
|
-
setPatchWarning("");
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Handler for applying the patch using editContext.operations.editField.
|
|
216
|
-
async function handleApplyPatch() {
|
|
217
|
-
if (!patchPossible) return;
|
|
218
|
-
if (!editContext) return;
|
|
219
|
-
|
|
220
|
-
// Recalculate the patch immediately before applying
|
|
221
|
-
const field = item?.fields?.find(
|
|
222
|
-
(f: { id: string }) => f.id === edit.fieldId,
|
|
223
|
-
);
|
|
224
|
-
if (!field) return;
|
|
225
|
-
const currentValue: string = field.rawValue || "";
|
|
226
|
-
const patch = createPatch("field", edit.oldValue, edit.newValue);
|
|
227
|
-
const patchedCandidate = applyPatch(currentValue, patch);
|
|
228
|
-
|
|
229
|
-
if (patchedCandidate === false || typeof patchedCandidate !== "string") {
|
|
230
|
-
setPatchWarning(
|
|
231
|
-
"Patch cannot be applied cleanly to current field value.",
|
|
232
|
-
);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
await editContext.operations.editField({
|
|
237
|
-
field: {
|
|
238
|
-
fieldId: edit.fieldId,
|
|
239
|
-
item: {
|
|
240
|
-
id: edit.itemId,
|
|
241
|
-
language: edit.mainItemLanguage,
|
|
242
|
-
version: edit.mainItemVersion,
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
value: patchedCandidate,
|
|
246
|
-
rawValue: patchedCandidate,
|
|
247
|
-
refresh: "immediate",
|
|
248
|
-
});
|
|
249
|
-
// Update the suggestion status to "Applied" and persist the update.
|
|
250
|
-
edit.status = "Applied";
|
|
251
|
-
await createOrUpdateSuggestedEdit(edit);
|
|
252
|
-
setApplied(true);
|
|
253
|
-
setPatchWarning("");
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Handler for replacing the field content completely using editContext.operations.editField.
|
|
257
|
-
async function handleReplaceCompletely() {
|
|
258
|
-
if (!editContext) return;
|
|
259
|
-
await editContext.operations.editField({
|
|
260
|
-
field: {
|
|
261
|
-
fieldId: edit.fieldId,
|
|
262
|
-
item: {
|
|
263
|
-
id: edit.itemId,
|
|
264
|
-
language: edit.mainItemLanguage,
|
|
265
|
-
version: edit.mainItemVersion,
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
value: edit.newValue,
|
|
269
|
-
rawValue: edit.newValue,
|
|
270
|
-
refresh: "immediate",
|
|
271
|
-
});
|
|
272
|
-
edit.status = "Applied";
|
|
273
|
-
await createOrUpdateSuggestedEdit(edit);
|
|
274
|
-
setApplied(true);
|
|
275
|
-
setPatchWarning("");
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return (
|
|
279
|
-
<div
|
|
280
|
-
ref={ref}
|
|
281
|
-
key={edit.id}
|
|
282
|
-
data-testid="suggested-edit"
|
|
283
|
-
className={`mb-3 cursor-pointer rounded-lg border-2 bg-white p-3 shadow-sm hover:bg-gray-50 ${
|
|
284
|
-
isSelected ? "border-blue-500" : "border-transparent"
|
|
285
|
-
}`}
|
|
286
|
-
onClick={handleSelectSuggestedEdit}
|
|
287
|
-
>
|
|
288
|
-
{renderHeader()}
|
|
289
|
-
{renderDiffToggleButtons()}
|
|
290
|
-
|
|
291
|
-
<div className="text-sm whitespace-pre-wrap text-gray-700">
|
|
292
|
-
<DiffView
|
|
293
|
-
oldText={edit.oldValue}
|
|
294
|
-
newText={edit.newValue}
|
|
295
|
-
ignoreFormatting={ignoreFormatting}
|
|
296
|
-
clipUnchanged={clipUnchanged}
|
|
297
|
-
clipThreshold={50}
|
|
298
|
-
clipContext={10}
|
|
299
|
-
/>
|
|
300
|
-
{canApply && patchWarning && (
|
|
301
|
-
<div className="mt-1 text-xs text-red-500">
|
|
302
|
-
{patchWarning}
|
|
303
|
-
<a
|
|
304
|
-
className="ml-2 cursor-pointer underline"
|
|
305
|
-
onClick={handleReplaceCompletely}
|
|
306
|
-
>
|
|
307
|
-
Click here to replace the field content.
|
|
308
|
-
</a>
|
|
309
|
-
</div>
|
|
310
|
-
)}
|
|
311
|
-
</div>
|
|
312
|
-
|
|
313
|
-
{renderContextInfo()}
|
|
314
|
-
</div>
|
|
315
|
-
);
|
|
316
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Command, CommandContext, CommandData } from "../commands/commands";
|
|
2
|
-
import { approveReview, rejectReview } from "../services/reviewsService";
|
|
3
|
-
|
|
4
|
-
export const approveReviewCommand: Command<CommandData> = {
|
|
5
|
-
id: "approveReview",
|
|
6
|
-
label: "Approve Page",
|
|
7
|
-
icon: <i className="pi pi-check text-green-500" />,
|
|
8
|
-
execute: async (context: CommandContext<CommandData>) => {
|
|
9
|
-
if (!context.editContext.currentItemDescriptor) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
await approveReview(context.editContext.currentItemDescriptor);
|
|
13
|
-
context.editContext.showToast({
|
|
14
|
-
summary: "Page/item approved",
|
|
15
|
-
severity: "success",
|
|
16
|
-
});
|
|
17
|
-
},
|
|
18
|
-
disabled: (context) => {
|
|
19
|
-
return !isReviewer(context);
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
export const rejectReviewCommand: Command<CommandData> = {
|
|
23
|
-
id: "rejectReview",
|
|
24
|
-
label: "Reject Page",
|
|
25
|
-
icon: <i className="pi pi-times text-red-500" />,
|
|
26
|
-
execute: async (context: CommandContext<CommandData>) => {
|
|
27
|
-
if (!context.editContext.currentItemDescriptor) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
await rejectReview(context.editContext.currentItemDescriptor);
|
|
31
|
-
context.editContext.showToast({
|
|
32
|
-
summary: "Page/item rejected",
|
|
33
|
-
severity: "error",
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
disabled: (context) => {
|
|
37
|
-
return !isReviewer(context);
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
function isReviewer(context: CommandContext<CommandData>) {
|
|
42
|
-
return (
|
|
43
|
-
context.editContext.reviews.reviews.find(
|
|
44
|
-
(x) => x.reviewerEmail === context.editContext.user?.email,
|
|
45
|
-
) !== undefined
|
|
46
|
-
);
|
|
47
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState, useMemo } from "react";
|
|
2
|
-
import { getReviewers, getReviews } from "../services/reviewsService";
|
|
3
|
-
|
|
4
|
-
import { Review } from "../../types";
|
|
5
|
-
import uuid from "react-uuid";
|
|
6
|
-
import { ItemDescriptor } from "../pageModel";
|
|
7
|
-
|
|
8
|
-
export function useReviews({
|
|
9
|
-
currentItemDescriptor,
|
|
10
|
-
addSocketMessageListener,
|
|
11
|
-
}: {
|
|
12
|
-
currentItemDescriptor?: ItemDescriptor;
|
|
13
|
-
addSocketMessageListener: (
|
|
14
|
-
callback: (message: { type: string; payload: any }) => void
|
|
15
|
-
) => void;
|
|
16
|
-
}) {
|
|
17
|
-
const [reviews, setReviews] = useState<Review[]>([]);
|
|
18
|
-
|
|
19
|
-
const loadReviews = async () => {
|
|
20
|
-
if (!currentItemDescriptor) return;
|
|
21
|
-
const reviewers = await getReviewers(
|
|
22
|
-
currentItemDescriptor.id,
|
|
23
|
-
currentItemDescriptor.language
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const reviewsResult = await getReviews(
|
|
27
|
-
currentItemDescriptor.id,
|
|
28
|
-
currentItemDescriptor.language,
|
|
29
|
-
currentItemDescriptor.version
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const reviews = reviewsResult.data;
|
|
33
|
-
|
|
34
|
-
if (!reviews) return;
|
|
35
|
-
|
|
36
|
-
reviewers.data?.forEach((reviewer) => {
|
|
37
|
-
if (!currentItemDescriptor) return;
|
|
38
|
-
const existingReview = reviews.find(
|
|
39
|
-
(r) => r.reviewerEmail === reviewer.email
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
if (!existingReview) {
|
|
43
|
-
reviews.push({
|
|
44
|
-
id: uuid(),
|
|
45
|
-
itemId: currentItemDescriptor.id,
|
|
46
|
-
language: currentItemDescriptor.language,
|
|
47
|
-
version: currentItemDescriptor.version,
|
|
48
|
-
reviewerName: reviewer.name,
|
|
49
|
-
reviewerEmail: reviewer.email,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
setReviews(reviews);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
loadReviews();
|
|
59
|
-
}, [currentItemDescriptor]);
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
return addSocketMessageListener((message) => {
|
|
63
|
-
if (message.type === "reviews-updated") {
|
|
64
|
-
loadReviews();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}, [currentItemDescriptor]);
|
|
68
|
-
|
|
69
|
-
return useMemo(() => ({ reviews, loadReviews }), [reviews]);
|
|
70
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { AiContext } from "../ai/AiTerminal";
|
|
2
|
-
import { EditContextType } from "../client/editContext";
|
|
3
|
-
import { FieldDescriptor, ItemDescriptor } from "../pageModel";
|
|
4
|
-
|
|
5
|
-
import { ExecutionResult, get, post } from "./serviceHelper";
|
|
6
|
-
|
|
7
|
-
export type AiProfile = {
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
instructions: string;
|
|
11
|
-
defaultModel: string;
|
|
12
|
-
models: string[];
|
|
13
|
-
prompts: { prompt: string; title: string }[];
|
|
14
|
-
errorMessage?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export async function loadAiProfiles(
|
|
18
|
-
item: ItemDescriptor,
|
|
19
|
-
): Promise<AiProfile[]> {
|
|
20
|
-
let url = "/alpaca/editor/ai/profiles";
|
|
21
|
-
|
|
22
|
-
const response = await post<AiProfile[]>(url, item);
|
|
23
|
-
|
|
24
|
-
if (response.type !== "success") {
|
|
25
|
-
throw new Error("Error loading AI profiles");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return response.data || [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type Message = {
|
|
32
|
-
content: string;
|
|
33
|
-
name: string;
|
|
34
|
-
role: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export async function executePrompt(
|
|
38
|
-
messages: Message[],
|
|
39
|
-
editContext: EditContextType,
|
|
40
|
-
createAiContext: ({ editContext }: { editContext: any }) => AiContext,
|
|
41
|
-
promptOptions: {
|
|
42
|
-
allowedFunctions?: string[];
|
|
43
|
-
addContextContent?: boolean;
|
|
44
|
-
addAllContent?: boolean;
|
|
45
|
-
profile?: string;
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
options?: RequestInit,
|
|
49
|
-
model?: string,
|
|
50
|
-
callback?: (response: any) => void,
|
|
51
|
-
): Promise<any> {
|
|
52
|
-
const context = createAiContext({ editContext });
|
|
53
|
-
|
|
54
|
-
const response = await fetch(context.endpoint, {
|
|
55
|
-
method: "POST",
|
|
56
|
-
body: JSON.stringify({
|
|
57
|
-
messages,
|
|
58
|
-
...context.promptData,
|
|
59
|
-
selection: editContext.selection,
|
|
60
|
-
sessionId: editContext.sessionId,
|
|
61
|
-
...promptOptions,
|
|
62
|
-
model,
|
|
63
|
-
}),
|
|
64
|
-
|
|
65
|
-
credentials: "include",
|
|
66
|
-
headers: {
|
|
67
|
-
"Content-Type": "application/json",
|
|
68
|
-
},
|
|
69
|
-
...options,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (!response?.body) return null;
|
|
73
|
-
|
|
74
|
-
const reader = response.body.getReader();
|
|
75
|
-
const decoder = new TextDecoder();
|
|
76
|
-
let buffer = "";
|
|
77
|
-
|
|
78
|
-
let result = null;
|
|
79
|
-
|
|
80
|
-
while (true) {
|
|
81
|
-
const { done, value } = await reader.read();
|
|
82
|
-
|
|
83
|
-
if (done) {
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
buffer += decoder.decode(value, { stream: true }); // 'stream: true' ensures that any incomplete multi-byte characters aren't malformed.
|
|
88
|
-
|
|
89
|
-
// Split the buffer by newline and keep the last partial line for the next iteration.
|
|
90
|
-
const lines = buffer.split("\n");
|
|
91
|
-
|
|
92
|
-
if (lines.length > 0) {
|
|
93
|
-
buffer = lines.pop() || ""; // Incomplete line (if any) is kept for the next iteration.
|
|
94
|
-
|
|
95
|
-
for (let line of lines) {
|
|
96
|
-
if (line.trim() === "") continue; // Skip empty lines if any.
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const jsonData = JSON.parse(line);
|
|
100
|
-
callback?.(jsonData);
|
|
101
|
-
result = jsonData;
|
|
102
|
-
} catch (e) {
|
|
103
|
-
console.error("Error parsing line:" + line, e);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// If there's any remaining content in the buffer after processing all chunks, try to process it.
|
|
110
|
-
if (buffer.trim() !== "") {
|
|
111
|
-
try {
|
|
112
|
-
const jsonData = JSON.parse(buffer);
|
|
113
|
-
result = jsonData;
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.error("Error parsing the final buffer content:", e);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export async function executeSearch({
|
|
123
|
-
query,
|
|
124
|
-
editContext,
|
|
125
|
-
maxResults = 10,
|
|
126
|
-
index,
|
|
127
|
-
rootItemIds,
|
|
128
|
-
skipValidation = false,
|
|
129
|
-
}: {
|
|
130
|
-
query: string;
|
|
131
|
-
editContext: EditContextType;
|
|
132
|
-
maxResults: number;
|
|
133
|
-
index: string;
|
|
134
|
-
rootItemIds?: string[];
|
|
135
|
-
skipValidation?: boolean;
|
|
136
|
-
}): Promise<ExecutionResult<unknown>> {
|
|
137
|
-
const response = await fetch("/alpaca/editor/ai/search", {
|
|
138
|
-
method: "POST",
|
|
139
|
-
body: JSON.stringify({
|
|
140
|
-
contextItem: {
|
|
141
|
-
id: editContext.currentItemDescriptor?.id,
|
|
142
|
-
language: "en",
|
|
143
|
-
version: 0,
|
|
144
|
-
},
|
|
145
|
-
query,
|
|
146
|
-
index,
|
|
147
|
-
maxResults,
|
|
148
|
-
rootItemIds,
|
|
149
|
-
skipValidation,
|
|
150
|
-
}),
|
|
151
|
-
credentials: "include",
|
|
152
|
-
headers: {
|
|
153
|
-
"Content-Type": "application/json",
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
if (!response.ok) return { type: "error", response };
|
|
158
|
-
|
|
159
|
-
return { type: "success", response, data: await response.json() };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export async function generateImage(
|
|
163
|
-
options: FieldDescriptor & {
|
|
164
|
-
prompt: string;
|
|
165
|
-
sessionId: string;
|
|
166
|
-
pageItem: ItemDescriptor;
|
|
167
|
-
},
|
|
168
|
-
): Promise<ExecutionResult<any>> {
|
|
169
|
-
const response = await post("/alpaca/editor/ai/generateImage", options);
|
|
170
|
-
return response;
|
|
171
|
-
}
|
|
172
|
-
export async function requestQuota() {
|
|
173
|
-
await get("/alpaca/editor/ai/requestQuota");
|
|
174
|
-
}
|