@alpaca-editor/core 1.0.3941 → 1.0.3943
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +3 -0
- package/build.css +3 -0
- package/components.json +21 -0
- package/dist/editor/ContentTree.d.ts +2 -1
- package/dist/editor/ContentTree.js +23 -21
- package/dist/editor/ContentTree.js.map +1 -1
- package/dist/editor/FieldActionsOverlay.js +0 -2
- package/dist/editor/FieldActionsOverlay.js.map +1 -1
- package/dist/editor/ScrollingContentTree.js +1 -1
- package/dist/editor/ScrollingContentTree.js.map +1 -1
- package/dist/editor/Titlebar.js +1 -1
- package/dist/editor/Titlebar.js.map +1 -1
- package/dist/editor/ai/GhostWriter.js +24 -3
- package/dist/editor/ai/GhostWriter.js.map +1 -1
- package/dist/editor/client/EditorClient.js +7 -7
- package/dist/editor/client/EditorClient.js.map +1 -1
- package/dist/editor/field-types/InternalLinkFieldEditor.js +60 -10
- package/dist/editor/field-types/InternalLinkFieldEditor.js.map +1 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js +48 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -1
- package/dist/editor/menubar/PageSelector.js +116 -65
- package/dist/editor/menubar/PageSelector.js.map +1 -1
- package/dist/editor/page-viewer/EditorForm.js +5 -2
- package/dist/editor/page-viewer/EditorForm.js.map +1 -1
- package/dist/editor/ui/ItemSearch.js +14 -8
- package/dist/editor/ui/ItemSearch.js.map +1 -1
- package/dist/editor/ui/PerfectTree.d.ts +4 -2
- package/dist/editor/ui/PerfectTree.js +78 -4
- package/dist/editor/ui/PerfectTree.js.map +1 -1
- package/dist/editor/ui/Splitter.js +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +8 -2
- package/eslint.config.mjs +4 -0
- package/images/bg-shape-black.webp +0 -0
- package/images/wizard-bg.png +0 -0
- package/images/wizard-tour.png +0 -0
- package/images/wizard.png +0 -0
- package/package.json +2 -8
- package/src/client-components/api.ts +6 -0
- package/src/client-components/index.ts +19 -0
- package/src/components/ActionButton.tsx +50 -0
- package/src/components/Error.tsx +57 -0
- package/src/components/ui/CardConnector.tsx +56 -0
- package/src/components/ui/button.tsx +62 -0
- package/src/components/ui/card.tsx +372 -0
- package/src/components/ui/context-menu.tsx +250 -0
- package/src/config/config.tsx +917 -0
- package/src/config/types.ts +286 -0
- package/src/editor/ComponentInfo.tsx +90 -0
- package/src/editor/ConfirmationDialog.tsx +103 -0
- package/src/editor/ContentTree.tsx +733 -0
- package/src/editor/ContextMenu.tsx +230 -0
- package/src/editor/Editor.tsx +90 -0
- package/src/editor/EditorWarning.tsx +34 -0
- package/src/editor/EditorWarnings.tsx +33 -0
- package/src/editor/FieldActionsOverlay.tsx +296 -0
- package/src/editor/FieldEditorPopup.tsx +65 -0
- package/src/editor/FieldHistory.tsx +75 -0
- package/src/editor/FieldList.tsx +190 -0
- package/src/editor/FieldListField.tsx +391 -0
- package/src/editor/FieldListFieldWithFallbacks.tsx +217 -0
- package/src/editor/FloatingToolbar.tsx +163 -0
- package/src/editor/ImageEditor.tsx +128 -0
- package/src/editor/ItemInfo.tsx +90 -0
- package/src/editor/LinkEditorDialog.tsx +196 -0
- package/src/editor/MainLayout.tsx +95 -0
- package/src/editor/MobileLayout.tsx +68 -0
- package/src/editor/NewEditorClient.tsx +11 -0
- package/src/editor/PictureCropper.tsx +568 -0
- package/src/editor/PictureEditor.tsx +301 -0
- package/src/editor/PictureEditorDialog.tsx +381 -0
- package/src/editor/PublishDialog.ignore +74 -0
- package/src/editor/ScrollingContentTree.tsx +68 -0
- package/src/editor/Terminal.tsx +227 -0
- package/src/editor/Titlebar.tsx +104 -0
- package/src/editor/ai/AiPopup.tsx +59 -0
- package/src/editor/ai/AiResponseMessage.tsx +106 -0
- package/src/editor/ai/AiTerminal.tsx +503 -0
- package/src/editor/ai/AiToolCall.tsx +61 -0
- package/src/editor/ai/EditorAiTerminal.tsx +20 -0
- package/src/editor/ai/GhostWriter.tsx +480 -0
- package/src/editor/ai/aiPageModel.ts +108 -0
- package/src/editor/ai/editorAiContext.ts +18 -0
- package/src/editor/client/AboutDialog.tsx +44 -0
- package/src/editor/client/EditorClient.tsx +2241 -0
- package/src/editor/client/GenericDialog.tsx +50 -0
- package/src/editor/client/editContext.ts +416 -0
- package/src/editor/client/helpers.ts +44 -0
- package/src/editor/client/itemsRepository.ts +574 -0
- package/src/editor/client/operations.ts +768 -0
- package/src/editor/client/pageModelBuilder.ts +219 -0
- package/src/editor/commands/commands.ts +22 -0
- package/src/editor/commands/componentCommands.tsx +431 -0
- package/src/editor/commands/createVersionCommand.ts +33 -0
- package/src/editor/commands/deleteVersionCommand.ts +71 -0
- package/src/editor/commands/itemCommands.tsx +351 -0
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
- package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +27 -0
- package/src/editor/commands/undo.ts +39 -0
- package/src/editor/component-designer/ComponentDesigner.tsx +70 -0
- package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +11 -0
- package/src/editor/component-designer/ComponentDesignerMenu.tsx +91 -0
- package/src/editor/component-designer/ComponentEditor.tsx +97 -0
- package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +31 -0
- package/src/editor/component-designer/ComponentRenderingEditor.tsx +104 -0
- package/src/editor/component-designer/ComponentsDropdown.tsx +39 -0
- package/src/editor/component-designer/PlaceholdersEditor.tsx +179 -0
- package/src/editor/component-designer/RenderingsDropdown.tsx +36 -0
- package/src/editor/component-designer/TemplateEditor.tsx +236 -0
- package/src/editor/component-designer/aiContext.ts +23 -0
- package/src/editor/componentTreeHelper.tsx +116 -0
- package/src/editor/context-menu/CopyMoveMenu.tsx +103 -0
- package/src/editor/context-menu/InsertMenu.tsx +347 -0
- package/src/editor/control-center/About.tsx +342 -0
- package/src/editor/control-center/ControlCenterMenu.tsx +76 -0
- package/src/editor/control-center/IndexOverview.tsx +50 -0
- package/src/editor/control-center/IndexSettings.tsx +266 -0
- package/src/editor/control-center/Info.tsx +104 -0
- package/src/editor/control-center/QuotaInfo.tsx +301 -0
- package/src/editor/control-center/Status.tsx +113 -0
- package/src/editor/control-center/WebSocketMessages.tsx +155 -0
- package/src/editor/editor-warnings/ItemLocked.tsx +63 -0
- package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +22 -0
- package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +23 -0
- package/src/editor/editor-warnings/NoWriteAccess.tsx +16 -0
- package/src/editor/editor-warnings/ValidationErrors.tsx +54 -0
- package/src/editor/field-types/AttachmentEditor.tsx +9 -0
- package/src/editor/field-types/CheckboxEditor.tsx +47 -0
- package/src/editor/field-types/DropLinkEditor.tsx +80 -0
- package/src/editor/field-types/DropListEditor.tsx +84 -0
- package/src/editor/field-types/ImageFieldEditor.tsx +65 -0
- package/src/editor/field-types/InternalLinkFieldEditor.tsx +188 -0
- package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
- package/src/editor/field-types/MultiLineText.tsx +82 -0
- package/src/editor/field-types/PictureFieldEditor.tsx +121 -0
- package/src/editor/field-types/RawEditor.tsx +53 -0
- package/src/editor/field-types/ReactQuill.tsx +580 -0
- package/src/editor/field-types/RichTextEditor.tsx +22 -0
- package/src/editor/field-types/RichTextEditorComponent.tsx +127 -0
- package/src/editor/field-types/SingleLineText.tsx +174 -0
- package/src/editor/field-types/TreeListEditor.tsx +261 -0
- package/src/editor/fieldTypes.ts +140 -0
- package/src/editor/media-selector/AiImageSearch.tsx +185 -0
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +94 -0
- package/src/editor/media-selector/MediaFolderBrowser.tsx +321 -0
- package/src/editor/media-selector/MediaSelector.tsx +42 -0
- package/src/editor/media-selector/Preview.tsx +14 -0
- package/src/editor/media-selector/Thumbnails.tsx +48 -0
- package/src/editor/media-selector/TreeSelector.tsx +292 -0
- package/src/editor/media-selector/UploadZone.tsx +137 -0
- package/src/editor/media-selector/index.ts +8 -0
- package/src/editor/menubar/ActionsMenu.tsx +94 -0
- package/src/editor/menubar/ActiveUsers.tsx +17 -0
- package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
- package/src/editor/menubar/BrowseHistory.tsx +28 -0
- package/src/editor/menubar/ItemLanguageVersion.tsx +76 -0
- package/src/editor/menubar/LanguageSelector.tsx +226 -0
- package/src/editor/menubar/Menu.tsx +83 -0
- package/src/editor/menubar/NavButtons.tsx +74 -0
- package/src/editor/menubar/PageSelector.tsx +278 -0
- package/src/editor/menubar/PageViewerControls.tsx +120 -0
- package/src/editor/menubar/PreviewSecondaryControls.tsx +18 -0
- package/src/editor/menubar/SecondaryControls.tsx +45 -0
- package/src/editor/menubar/Separator.tsx +12 -0
- package/src/editor/menubar/SiteInfo.tsx +53 -0
- package/src/editor/menubar/User.tsx +27 -0
- package/src/editor/menubar/VersionSelector.tsx +142 -0
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +307 -0
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +59 -0
- package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +23 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +64 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +35 -0
- package/src/editor/page-editor-chrome/FrameMenu.tsx +338 -0
- package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
- package/src/editor/page-editor-chrome/InlineEditor.tsx +765 -0
- package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +61 -0
- package/src/editor/page-editor-chrome/NoLayout.tsx +36 -0
- package/src/editor/page-editor-chrome/PageEditorChrome.tsx +122 -0
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +161 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +169 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +315 -0
- package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +300 -0
- package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +40 -0
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +828 -0
- package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
- package/src/editor/page-viewer/EditorForm.tsx +262 -0
- package/src/editor/page-viewer/MiniMap.tsx +362 -0
- package/src/editor/page-viewer/PageViewer.tsx +169 -0
- package/src/editor/page-viewer/PageViewerFrame.tsx +1022 -0
- package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +412 -0
- package/src/editor/page-viewer/pageViewContext.ts +186 -0
- package/src/editor/pageModel.ts +220 -0
- package/src/editor/picture-shared.tsx +53 -0
- package/src/editor/reviews/Comment.tsx +308 -0
- package/src/editor/reviews/Comments.tsx +125 -0
- package/src/editor/reviews/DiffView.tsx +109 -0
- package/src/editor/reviews/PreviewInfo.tsx +35 -0
- package/src/editor/reviews/Reviews.tsx +280 -0
- package/src/editor/reviews/SuggestedEdit.tsx +316 -0
- package/src/editor/reviews/reviewCommands.tsx +47 -0
- package/src/editor/reviews/useReviews.tsx +70 -0
- package/src/editor/services/aiService.ts +173 -0
- package/src/editor/services/componentDesignerService.ts +151 -0
- package/src/editor/services/contentService.ts +180 -0
- package/src/editor/services/editService.ts +488 -0
- package/src/editor/services/indexService.ts +24 -0
- package/src/editor/services/reviewsService.ts +53 -0
- package/src/editor/services/serviceHelper.ts +95 -0
- package/src/editor/services/suggestedEditsService.ts +39 -0
- package/src/editor/services/systemService.ts +5 -0
- package/src/editor/services/translationService.ts +21 -0
- package/src/editor/services-server/api.ts +150 -0
- package/src/editor/services-server/graphQL.ts +106 -0
- package/src/editor/sidebar/ComponentPalette.tsx +161 -0
- package/src/editor/sidebar/ComponentTree.tsx +549 -0
- package/src/editor/sidebar/Debug.tsx +111 -0
- package/src/editor/sidebar/DictionaryEditor.tsx +261 -0
- package/src/editor/sidebar/EditHistory.tsx +134 -0
- package/src/editor/sidebar/GraphQL.tsx +164 -0
- package/src/editor/sidebar/Insert.tsx +35 -0
- package/src/editor/sidebar/MainContentTree.tsx +102 -0
- package/src/editor/sidebar/Performance.tsx +53 -0
- package/src/editor/sidebar/Sessions.tsx +35 -0
- package/src/editor/sidebar/Sidebar.tsx +20 -0
- package/src/editor/sidebar/SidebarView.tsx +152 -0
- package/src/editor/sidebar/Translations.tsx +295 -0
- package/src/editor/sidebar/Validation.tsx +102 -0
- package/src/editor/sidebar/ViewSelector.tsx +60 -0
- package/src/editor/sidebar/Workbox.tsx +209 -0
- package/src/editor/ui/CenteredMessage.tsx +7 -0
- package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +81 -0
- package/src/editor/ui/CopyToClipboardButton.tsx +24 -0
- package/src/editor/ui/DialogButtons.tsx +11 -0
- package/src/editor/ui/Icons.tsx +709 -0
- package/src/editor/ui/ItemList.tsx +76 -0
- package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
- package/src/editor/ui/ItemSearch.tsx +159 -0
- package/src/editor/ui/PerfectTree.tsx +676 -0
- package/src/editor/ui/Section.tsx +35 -0
- package/src/editor/ui/SimpleIconButton.tsx +54 -0
- package/src/editor/ui/SimpleMenu.tsx +40 -0
- package/src/editor/ui/SimpleTable.tsx +60 -0
- package/src/editor/ui/SimpleTabs.tsx +60 -0
- package/src/editor/ui/SimpleToolbar.tsx +7 -0
- package/src/editor/ui/Spinner.tsx +9 -0
- package/src/editor/ui/Splitter.tsx +420 -0
- package/src/editor/ui/StackedPanels.tsx +134 -0
- package/src/editor/ui/Toolbar.tsx +7 -0
- package/src/editor/utils/id-helper.ts +3 -0
- package/src/editor/utils/insertOptions.ts +69 -0
- package/src/editor/utils/itemutils.ts +29 -0
- package/src/editor/utils/useMemoDebug.ts +28 -0
- package/src/editor/utils.ts +486 -0
- package/src/editor/views/CompareView.tsx +245 -0
- package/src/editor/views/EditView.tsx +27 -0
- package/src/editor/views/ItemEditor.tsx +58 -0
- package/src/editor/views/MediaFolderEditView.tsx +66 -0
- package/src/editor/views/SingleEditView.tsx +57 -0
- package/src/fonts/Geist-Black.woff2 +0 -0
- package/src/fonts/Geist-Bold.woff2 +0 -0
- package/src/fonts/Geist-ExtraBold.woff2 +0 -0
- package/src/fonts/Geist-ExtraLight.woff2 +0 -0
- package/src/fonts/Geist-Light.woff2 +0 -0
- package/src/fonts/Geist-Medium.woff2 +0 -0
- package/src/fonts/Geist-Regular.woff2 +0 -0
- package/src/fonts/Geist-SemiBold.woff2 +0 -0
- package/src/fonts/Geist-Thin.woff2 +0 -0
- package/src/fonts/Geist[wght].woff2 +0 -0
- package/src/fonts/index.ts +10 -0
- package/src/index.ts +23 -0
- package/src/lib/safelist.tsx +16 -0
- package/src/lib/utils.ts +6 -0
- package/src/page-wizard/PageWizard.tsx +139 -0
- package/src/page-wizard/WizardBox.tsx +4 -0
- package/src/page-wizard/WizardBoxConnector.tsx +56 -0
- package/src/page-wizard/WizardSteps.tsx +458 -0
- package/src/page-wizard/service.ts +35 -0
- package/src/page-wizard/startPageWizardCommand.ts +26 -0
- package/src/page-wizard/steps/BuildPageStep.tsx +259 -0
- package/src/page-wizard/steps/CollectStep.tsx +296 -0
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +454 -0
- package/src/page-wizard/steps/Components.tsx +193 -0
- package/src/page-wizard/steps/ContentStep.tsx +890 -0
- package/src/page-wizard/steps/EditButton.tsx +34 -0
- package/src/page-wizard/steps/FieldEditor.tsx +102 -0
- package/src/page-wizard/steps/Generate.tsx +60 -0
- package/src/page-wizard/steps/ImagesStep.tsx +382 -0
- package/src/page-wizard/steps/LayoutStep.tsx +227 -0
- package/src/page-wizard/steps/MetaDataStep.tsx +173 -0
- package/src/page-wizard/steps/SelectStep.tsx +281 -0
- package/src/page-wizard/steps/schema.ts +180 -0
- package/src/page-wizard/steps/usePageCreator.ts +325 -0
- package/src/page-wizard/usePageWizard.ts +79 -0
- package/src/revision.ts +2 -0
- package/src/splash-screen/NewPage.tsx +294 -0
- package/src/splash-screen/OpenPage.tsx +113 -0
- package/src/splash-screen/RecentPages.tsx +123 -0
- package/src/splash-screen/SectionHeadline.tsx +21 -0
- package/src/splash-screen/SplashScreen.tsx +195 -0
- package/src/tour/Tour.tsx +566 -0
- package/src/tour/default-tour.tsx +301 -0
- package/src/tour/preview-tour.tsx +128 -0
- package/src/types.ts +335 -0
- package/styles.css +765 -0
- package/tsconfig.build.json +31 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ResultItem } from "./ItemSearch";
|
|
2
|
+
import { ItemDescriptor } from "../pageModel";
|
|
3
|
+
|
|
4
|
+
interface ItemListProps {
|
|
5
|
+
items: ResultItem[];
|
|
6
|
+
onItemHover?: (item: ResultItem | undefined) => void;
|
|
7
|
+
onItemClick: (
|
|
8
|
+
item: ItemDescriptor & { path?: string; idPath?: string; icon?: string },
|
|
9
|
+
) => void;
|
|
10
|
+
maxItems?: number;
|
|
11
|
+
className?: string;
|
|
12
|
+
showPath?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ItemList: React.FC<ItemListProps> = ({
|
|
16
|
+
items,
|
|
17
|
+
onItemHover,
|
|
18
|
+
onItemClick,
|
|
19
|
+
maxItems = 6,
|
|
20
|
+
className = "",
|
|
21
|
+
showPath = true,
|
|
22
|
+
}) => {
|
|
23
|
+
const filteredItems = items.filter((x) => x.language).slice(0, maxItems);
|
|
24
|
+
|
|
25
|
+
const handleItemClick = (item: ResultItem) => {
|
|
26
|
+
onItemClick({
|
|
27
|
+
id: item.id,
|
|
28
|
+
language: item.language,
|
|
29
|
+
version: 0,
|
|
30
|
+
path: item.path,
|
|
31
|
+
icon: item.icon,
|
|
32
|
+
idPath: item.idPath,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (filteredItems.length === 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className={`flex flex-1 flex-col gap-1 overflow-y-auto ${className}`}>
|
|
42
|
+
{filteredItems.map((item) => (
|
|
43
|
+
<div
|
|
44
|
+
key={item.id + item.language}
|
|
45
|
+
className="flex cursor-pointer items-start gap-2 rounded p-1 text-xs hover:bg-gray-50"
|
|
46
|
+
onMouseEnter={() => onItemHover?.(item)}
|
|
47
|
+
onMouseLeave={() => onItemHover?.(undefined)}
|
|
48
|
+
onClick={() => handleItemClick(item)}
|
|
49
|
+
>
|
|
50
|
+
{item.icon && (
|
|
51
|
+
<img
|
|
52
|
+
src={item.icon}
|
|
53
|
+
width="16"
|
|
54
|
+
height="16"
|
|
55
|
+
className="mt-0.5 flex-shrink-0"
|
|
56
|
+
/>
|
|
57
|
+
)}
|
|
58
|
+
|
|
59
|
+
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
60
|
+
<div className="truncate font-medium text-gray-900">
|
|
61
|
+
{item.name}
|
|
62
|
+
<span className="text-2xs ml-1 text-gray-400">
|
|
63
|
+
({item.language})
|
|
64
|
+
</span>
|
|
65
|
+
</div>
|
|
66
|
+
{showPath && (
|
|
67
|
+
<div className="text-2xs break-words text-gray-500">
|
|
68
|
+
{item.path}
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Dialog } from "primereact/dialog";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import DialogButtons from "./DialogButtons";
|
|
5
|
+
import { Button } from "primereact/button";
|
|
6
|
+
import { InputText } from "primereact/inputtext";
|
|
7
|
+
import { DialogProps } from "../client/editContext";
|
|
8
|
+
import { ItemDescriptor } from "../pageModel";
|
|
9
|
+
import { useEditContext } from "../client/editContext";
|
|
10
|
+
import { getChildren } from "../services/contentService";
|
|
11
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
12
|
+
|
|
13
|
+
export type ItemNameDialogProps = {
|
|
14
|
+
name?: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
parentItem?: ItemDescriptor;
|
|
18
|
+
itemId?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function ItemNameDialog(
|
|
22
|
+
props: ItemNameDialogProps & DialogProps<string>,
|
|
23
|
+
) {
|
|
24
|
+
const editContext = useEditContext();
|
|
25
|
+
const [name, setName] = useState("");
|
|
26
|
+
const [validationError, setValidationError] = useState<string>();
|
|
27
|
+
const [isValid, setIsValid] = useState(false);
|
|
28
|
+
|
|
29
|
+
const nameRef = useRef<HTMLInputElement>(null);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setName(props?.name || "");
|
|
33
|
+
}, [props]);
|
|
34
|
+
|
|
35
|
+
const checkNameValidDebounced = useDebouncedCallback(
|
|
36
|
+
async () => checkName(),
|
|
37
|
+
500,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
checkNameValidDebounced();
|
|
42
|
+
}, [name]);
|
|
43
|
+
|
|
44
|
+
const checkName = async () => {
|
|
45
|
+
let valid = name.trim().length > 0;
|
|
46
|
+
|
|
47
|
+
if (!props.parentItem) {
|
|
48
|
+
setIsValid(valid);
|
|
49
|
+
setValidationError(valid ? undefined : "Name is required");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (valid) {
|
|
54
|
+
const children = await getChildren(
|
|
55
|
+
props.parentItem.id,
|
|
56
|
+
editContext?.sessionId ?? "",
|
|
57
|
+
[],
|
|
58
|
+
false,
|
|
59
|
+
props.parentItem?.language || "en",
|
|
60
|
+
);
|
|
61
|
+
if (
|
|
62
|
+
children.find(
|
|
63
|
+
(x) =>
|
|
64
|
+
x.name.toLocaleLowerCase() === name.trim().toLocaleLowerCase() &&
|
|
65
|
+
(props.itemId ? x.id !== props.itemId : true),
|
|
66
|
+
)
|
|
67
|
+
) {
|
|
68
|
+
valid = false;
|
|
69
|
+
setValidationError("A page with this name already exists.");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (valid) setValidationError(undefined);
|
|
74
|
+
setIsValid(valid);
|
|
75
|
+
return valid;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleOk = () => {
|
|
79
|
+
props.onClose?.(name);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Dialog
|
|
84
|
+
visible={true}
|
|
85
|
+
onHide={() => {
|
|
86
|
+
props.onClose?.(null);
|
|
87
|
+
}}
|
|
88
|
+
onShow={() => {
|
|
89
|
+
nameRef.current?.focus();
|
|
90
|
+
nameRef.current?.select();
|
|
91
|
+
}}
|
|
92
|
+
style={{ width: "400px" }}
|
|
93
|
+
header={props?.title ?? "Name"}
|
|
94
|
+
>
|
|
95
|
+
<div className="p-3">
|
|
96
|
+
<div className="my-2 text-sm">
|
|
97
|
+
{props.message || "Enter a name for the new item:"}
|
|
98
|
+
</div>
|
|
99
|
+
<InputText
|
|
100
|
+
ref={nameRef}
|
|
101
|
+
value={name}
|
|
102
|
+
className="w-full"
|
|
103
|
+
onChange={(e) => setName(e.target.value)}
|
|
104
|
+
onKeyDown={(ev) => {
|
|
105
|
+
if (ev.key === "Enter" && isValid) handleOk();
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
{validationError && (
|
|
109
|
+
<div className="mt-2 text-red-500">{validationError}</div>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
<DialogButtons>
|
|
113
|
+
<Button onClick={handleOk} label="Ok" disabled={!isValid} />
|
|
114
|
+
<Button onClick={() => props.onClose?.(null)} label="Cancel" />
|
|
115
|
+
</DialogButtons>
|
|
116
|
+
</Dialog>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { InputText } from "primereact/inputtext";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useEditContext } from "../client/editContext";
|
|
4
|
+
import { executeSearch } from "../services/aiService";
|
|
5
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
6
|
+
import { ProgressSpinner } from "primereact/progressspinner";
|
|
7
|
+
import { ItemDescriptor } from "../pageModel";
|
|
8
|
+
import { getItemDescriptor } from "../utils";
|
|
9
|
+
import { ItemList } from "./ItemList";
|
|
10
|
+
|
|
11
|
+
export type ResultItem = {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
language: string;
|
|
15
|
+
icon?: string;
|
|
16
|
+
path: string;
|
|
17
|
+
idPath?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
interface SearchProps {
|
|
21
|
+
rootItemIds?: string[];
|
|
22
|
+
setHoveredItem?: React.Dispatch<React.SetStateAction<ResultItem | undefined>>;
|
|
23
|
+
itemSelected: (
|
|
24
|
+
item: ItemDescriptor & { path?: string; idPath?: string; icon?: string },
|
|
25
|
+
) => void;
|
|
26
|
+
language?: string;
|
|
27
|
+
resultClassName?: string;
|
|
28
|
+
autoFocus?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const ItemSearch: React.FC<SearchProps> = ({
|
|
32
|
+
rootItemIds,
|
|
33
|
+
setHoveredItem,
|
|
34
|
+
itemSelected,
|
|
35
|
+
language,
|
|
36
|
+
resultClassName,
|
|
37
|
+
autoFocus = false,
|
|
38
|
+
}) => {
|
|
39
|
+
const [query, setQuery] = useState("");
|
|
40
|
+
const [results, setResults] = useState<ResultItem[]>([]);
|
|
41
|
+
const [loading, setLoading] = useState(false);
|
|
42
|
+
const editContext = useEditContext();
|
|
43
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
44
|
+
|
|
45
|
+
const handleSearch = useDebouncedCallback(async (searchPrompt: string) => {
|
|
46
|
+
if (!editContext) return;
|
|
47
|
+
|
|
48
|
+
setLoading(true);
|
|
49
|
+
const currentQuery = searchPrompt;
|
|
50
|
+
|
|
51
|
+
const guidPattern =
|
|
52
|
+
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
53
|
+
if (guidPattern.test(searchPrompt)) {
|
|
54
|
+
const item = await editContext.itemsRepository.getItem({
|
|
55
|
+
id: searchPrompt,
|
|
56
|
+
language: language || "en",
|
|
57
|
+
version: 0,
|
|
58
|
+
});
|
|
59
|
+
if (item) {
|
|
60
|
+
if (query === currentQuery) {
|
|
61
|
+
const resultItem: ResultItem = {
|
|
62
|
+
id: item.id,
|
|
63
|
+
name: item.name,
|
|
64
|
+
language: item.language || language || "en",
|
|
65
|
+
icon: item.icon,
|
|
66
|
+
path: item.path || item.name,
|
|
67
|
+
idPath: item.idPath,
|
|
68
|
+
};
|
|
69
|
+
setResults([resultItem]);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (query === currentQuery) {
|
|
73
|
+
setResults([]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
setLoading(false);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const result = await executeSearch({
|
|
81
|
+
index: "master",
|
|
82
|
+
query: searchPrompt,
|
|
83
|
+
editContext,
|
|
84
|
+
rootItemIds,
|
|
85
|
+
maxResults: 5,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (query === currentQuery) {
|
|
89
|
+
if (result.type == "success") {
|
|
90
|
+
setResults(() => result.data as ResultItem[]);
|
|
91
|
+
} else {
|
|
92
|
+
editContext.showToast({
|
|
93
|
+
severity: "error",
|
|
94
|
+
summary: "Error searching",
|
|
95
|
+
detail: result.response.statusText,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
setLoading(false);
|
|
100
|
+
}, 600);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (query) {
|
|
104
|
+
setLoading(true);
|
|
105
|
+
handleSearch(query);
|
|
106
|
+
} else {
|
|
107
|
+
setResults([]);
|
|
108
|
+
}
|
|
109
|
+
}, [query]);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (inputRef.current && autoFocus) {
|
|
113
|
+
inputRef.current.focus();
|
|
114
|
+
}
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
<div className="relative">
|
|
120
|
+
<div className="flex items-center">
|
|
121
|
+
<InputText
|
|
122
|
+
className="w-full rounded border border-gray-300 px-2 py-1 pr-6 text-xs focus:border-blue-400 focus:ring-1 focus:ring-blue-400 focus:outline-none"
|
|
123
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
124
|
+
value={query}
|
|
125
|
+
ref={inputRef}
|
|
126
|
+
/>
|
|
127
|
+
{!loading && !query && (
|
|
128
|
+
<i className="pi pi-search px-3 text-gray-500" />
|
|
129
|
+
)}
|
|
130
|
+
{!loading && query && (
|
|
131
|
+
<i
|
|
132
|
+
className="pi pi-times cursor-pointer px-3 text-gray-500"
|
|
133
|
+
onClick={() => setQuery("")}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
{loading && (
|
|
137
|
+
<ProgressSpinner
|
|
138
|
+
style={{ width: "24px", height: "24px", margin: "0 12px" }}
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
{results.length > 0 && (
|
|
144
|
+
<ItemList
|
|
145
|
+
items={results}
|
|
146
|
+
onItemHover={setHoveredItem}
|
|
147
|
+
onItemClick={itemSelected}
|
|
148
|
+
maxItems={6}
|
|
149
|
+
className={`mt-1 ${resultClassName}`}
|
|
150
|
+
/>
|
|
151
|
+
)}
|
|
152
|
+
{results.length === 0 && !loading && query && (
|
|
153
|
+
<div className="mt-1 text-xs text-gray-500">No results found</div>
|
|
154
|
+
)}
|
|
155
|
+
</>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export default ItemSearch;
|