@alpaca-editor/core 1.0.3942 → 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,68 @@
|
|
|
1
|
+
import { cn } from "../lib/utils";
|
|
2
|
+
import { MainLayoutProps } from "./MainLayout";
|
|
3
|
+
import { ViewSelector } from "./sidebar/ViewSelector";
|
|
4
|
+
import { useEditContext } from "./client/editContext";
|
|
5
|
+
import { Splitter, SplitterPanel } from "./ui/Splitter";
|
|
6
|
+
import { SidebarView } from "./sidebar/SidebarView";
|
|
7
|
+
|
|
8
|
+
export function MobileLayout(props: MainLayoutProps) {
|
|
9
|
+
const editContext = useEditContext();
|
|
10
|
+
|
|
11
|
+
if (!editContext) return null;
|
|
12
|
+
|
|
13
|
+
let className = props.className;
|
|
14
|
+
|
|
15
|
+
if (!editContext?.configuration.editor.embedded) {
|
|
16
|
+
className = cn("fixed inset-0", props.className);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const panels: SplitterPanel[] = [
|
|
20
|
+
{
|
|
21
|
+
name: "center",
|
|
22
|
+
defaultSize: "auto",
|
|
23
|
+
content: props.centerPanelView,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const viewsWithLeftSidebar = editContext.configuration.editor.views.filter(
|
|
28
|
+
(v) => v.leftSidebar,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (viewsWithLeftSidebar.length > 0) {
|
|
32
|
+
panels.push({
|
|
33
|
+
name: "sidebar",
|
|
34
|
+
hidden: !props.view.leftSidebar,
|
|
35
|
+
defaultSize: 250,
|
|
36
|
+
content: (
|
|
37
|
+
<div className="relative h-full w-full">
|
|
38
|
+
{viewsWithLeftSidebar.map((v) => (
|
|
39
|
+
<SidebarView
|
|
40
|
+
key={v.name}
|
|
41
|
+
sidebar={v.leftSidebar!}
|
|
42
|
+
editContext={editContext}
|
|
43
|
+
active={props.view.name === v.name && !!v.leftSidebar}
|
|
44
|
+
/>
|
|
45
|
+
))}
|
|
46
|
+
</div>
|
|
47
|
+
),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className={cn("flex flex-col select-none", className)}>
|
|
53
|
+
{editContext?.configuration.editor.titlebar}
|
|
54
|
+
|
|
55
|
+
<Splitter
|
|
56
|
+
panels={panels}
|
|
57
|
+
direction="vertical"
|
|
58
|
+
localStorageKey="mobile-layout-splitter"
|
|
59
|
+
/>
|
|
60
|
+
|
|
61
|
+
{!props.view.hideViewSelector && <ViewSelector />}
|
|
62
|
+
{/* <div className="text-2xs fixed right-0 bottom-0 z-50 flex flex-col rounded-tl-2xl bg-gray-50/70 px-1 pt-1 text-center font-mono text-gray-400">
|
|
63
|
+
<div title={buildDate}>{version}</div>
|
|
64
|
+
</div> */}
|
|
65
|
+
{/* Sidebars rendered above */}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import { Dialog } from "primereact/dialog";
|
|
2
|
+
import { useEditContext } from "./client/editContext";
|
|
3
|
+
import { ReactNode, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Button } from "primereact/button";
|
|
5
|
+
import DialogButtons from "./ui/DialogButtons";
|
|
6
|
+
import { Rect } from "./utils";
|
|
7
|
+
import { classNames } from "primereact/utils";
|
|
8
|
+
import {
|
|
9
|
+
PictureField,
|
|
10
|
+
PictureRawValue,
|
|
11
|
+
PictureValue,
|
|
12
|
+
PictureVariant,
|
|
13
|
+
} from "./fieldTypes";
|
|
14
|
+
|
|
15
|
+
export function PictureCropper({
|
|
16
|
+
field,
|
|
17
|
+
onClose,
|
|
18
|
+
variantName: selectedVariantName,
|
|
19
|
+
}: {
|
|
20
|
+
field: PictureField;
|
|
21
|
+
variantName: string;
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
}) {
|
|
24
|
+
const [pictureValue, setPictureValue] = useState<PictureValue>();
|
|
25
|
+
const [isValid, setIsValid] = useState<boolean>(true);
|
|
26
|
+
const [rawValue, setRawValue] = useState<PictureRawValue>();
|
|
27
|
+
const [actualImageDimensions, setActualImageDimensions] = useState<{
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
} | null>(null);
|
|
31
|
+
|
|
32
|
+
const imageRef = useRef<HTMLDivElement>(null);
|
|
33
|
+
const [rect, setRect] = useState<Rect>();
|
|
34
|
+
const rectRef = useRef(rect);
|
|
35
|
+
const movingRef = useRef(false);
|
|
36
|
+
const [startPos, setStartPos] = useState<{ x: number; y: number }>({
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
});
|
|
40
|
+
const offset = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
|
41
|
+
|
|
42
|
+
const editContext = useEditContext();
|
|
43
|
+
|
|
44
|
+
const EDGE_THRESHOLD = 10; // pixels from edge to detect resize
|
|
45
|
+
|
|
46
|
+
const [resizeEdge, setResizeEdge] = useState<string | null>(null);
|
|
47
|
+
const resizeEdgeRef = useRef<string | null>(null);
|
|
48
|
+
|
|
49
|
+
const getResizeEdge = (
|
|
50
|
+
pos: { x: number; y: number },
|
|
51
|
+
rect?: Rect,
|
|
52
|
+
bounds?: DOMRect,
|
|
53
|
+
) => {
|
|
54
|
+
if (!rect || !bounds) return null;
|
|
55
|
+
|
|
56
|
+
const x = pos.x * bounds.width;
|
|
57
|
+
const y = pos.y * bounds.height;
|
|
58
|
+
const rectX = rect.x * bounds.width;
|
|
59
|
+
const rectY = rect.y * bounds.height;
|
|
60
|
+
const rectWidth = rect.width * bounds.width;
|
|
61
|
+
const rectHeight = rect.height * bounds.height;
|
|
62
|
+
|
|
63
|
+
const isNearLeft = Math.abs(x - rectX) < EDGE_THRESHOLD;
|
|
64
|
+
const isNearRight = Math.abs(x - (rectX + rectWidth)) < EDGE_THRESHOLD;
|
|
65
|
+
const isNearTop = Math.abs(y - rectY) < EDGE_THRESHOLD;
|
|
66
|
+
const isNearBottom = Math.abs(y - (rectY + rectHeight)) < EDGE_THRESHOLD;
|
|
67
|
+
|
|
68
|
+
if (isNearLeft && isNearTop) return "nw";
|
|
69
|
+
if (isNearRight && isNearTop) return "ne";
|
|
70
|
+
if (isNearLeft && isNearBottom) return "sw";
|
|
71
|
+
if (isNearRight && isNearBottom) return "se";
|
|
72
|
+
if (isNearLeft) return "w";
|
|
73
|
+
if (isNearRight) return "e";
|
|
74
|
+
if (isNearTop) return "n";
|
|
75
|
+
if (isNearBottom) return "s";
|
|
76
|
+
|
|
77
|
+
return null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const deepCopy = JSON.parse(JSON.stringify(field.value));
|
|
82
|
+
setPictureValue(deepCopy);
|
|
83
|
+
const raw = field?.rawValue
|
|
84
|
+
? (JSON.parse(field?.rawValue) as PictureRawValue)
|
|
85
|
+
: ({ Variants: [] } as PictureRawValue);
|
|
86
|
+
setRawValue(raw);
|
|
87
|
+
}, [field]);
|
|
88
|
+
|
|
89
|
+
const selectedVariant =
|
|
90
|
+
pictureValue && pictureValue.variants
|
|
91
|
+
? pictureValue.variants?.find(
|
|
92
|
+
(x: PictureVariant) => x.name == selectedVariantName,
|
|
93
|
+
)
|
|
94
|
+
: null;
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (
|
|
98
|
+
selectedVariant?.region &&
|
|
99
|
+
(!selectedVariant.aspectRatioLock ||
|
|
100
|
+
Math.abs(
|
|
101
|
+
selectedVariant.aspectRatioLock -
|
|
102
|
+
(selectedVariant.region.width * selectedVariant.width) /
|
|
103
|
+
(selectedVariant.region.height * selectedVariant.height),
|
|
104
|
+
) < 0.1) &&
|
|
105
|
+
selectedVariant.region.width > 0 &&
|
|
106
|
+
selectedVariant.region.height > 0
|
|
107
|
+
) {
|
|
108
|
+
setRect({
|
|
109
|
+
width: selectedVariant.region.width,
|
|
110
|
+
height: selectedVariant.region.height,
|
|
111
|
+
y: selectedVariant.region.y,
|
|
112
|
+
x: selectedVariant.region.x,
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
setRect(undefined);
|
|
116
|
+
}
|
|
117
|
+
}, [selectedVariant]);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!rect) return;
|
|
121
|
+
if (
|
|
122
|
+
(selectedVariant?.minWidth && selectedVariant.minWidth > widthPx) ||
|
|
123
|
+
(selectedVariant?.minHeight && selectedVariant?.minHeight > heightPx)
|
|
124
|
+
) {
|
|
125
|
+
setIsValid(false);
|
|
126
|
+
} else setIsValid(true);
|
|
127
|
+
rectRef.current = rect;
|
|
128
|
+
}, [rect]);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!rawValue) return;
|
|
132
|
+
if (!selectedVariantName) return;
|
|
133
|
+
if (selectedVariant) {
|
|
134
|
+
let selected = rawValue.Variants?.find(
|
|
135
|
+
(x) => x.Name == selectedVariantName,
|
|
136
|
+
);
|
|
137
|
+
if (!selected) {
|
|
138
|
+
selected = {
|
|
139
|
+
Name: selectedVariantName,
|
|
140
|
+
MediaId: selectedVariant.mediaId!,
|
|
141
|
+
};
|
|
142
|
+
rawValue.Variants?.push(selected);
|
|
143
|
+
}
|
|
144
|
+
if (selected) {
|
|
145
|
+
if (rect)
|
|
146
|
+
selected.Region = {
|
|
147
|
+
X: rect.x,
|
|
148
|
+
Y: rect.y,
|
|
149
|
+
Width: rect.width,
|
|
150
|
+
Height: rect.height,
|
|
151
|
+
};
|
|
152
|
+
else selected.Region = undefined;
|
|
153
|
+
setRawValue(rawValue);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, [rect]);
|
|
157
|
+
|
|
158
|
+
const handleMouseMove = (ev: React.MouseEvent) => {
|
|
159
|
+
if (!selectedVariant) return null;
|
|
160
|
+
|
|
161
|
+
const bounds = imageRef.current?.getBoundingClientRect();
|
|
162
|
+
if (!bounds) return;
|
|
163
|
+
|
|
164
|
+
const pos = {
|
|
165
|
+
x: (ev.clientX - bounds.left) / bounds.width,
|
|
166
|
+
y: (ev.clientY - bounds.top) / bounds.height,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Update cursor on hover (when not dragging)
|
|
170
|
+
if (ev.buttons !== 1) {
|
|
171
|
+
const edge = getResizeEdge(pos, rect, bounds);
|
|
172
|
+
setResizeEdge(edge);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (ev.buttons === 1) {
|
|
177
|
+
if (!rectRef.current || !imageRef.current) return;
|
|
178
|
+
const rect = rectRef.current;
|
|
179
|
+
|
|
180
|
+
const bounds = imageRef.current.getBoundingClientRect();
|
|
181
|
+
const deltaX = ev.clientX - startPos.x;
|
|
182
|
+
const deltaY = ev.clientY - startPos.y;
|
|
183
|
+
if (resizeEdgeRef.current) {
|
|
184
|
+
const pos = {
|
|
185
|
+
x: (ev.clientX - bounds.left) / bounds.width,
|
|
186
|
+
y: (ev.clientY - bounds.top) / bounds.height,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
let newRect = { ...rect };
|
|
190
|
+
const aspectRatio = selectedVariant.aspectRatioLock;
|
|
191
|
+
const actualWidth =
|
|
192
|
+
selectedVariant.width > 0
|
|
193
|
+
? selectedVariant.width
|
|
194
|
+
: actualImageDimensions?.width || 0;
|
|
195
|
+
const actualHeight =
|
|
196
|
+
selectedVariant.height > 0
|
|
197
|
+
? selectedVariant.height
|
|
198
|
+
: actualImageDimensions?.height || 0;
|
|
199
|
+
const originalAspectRatio =
|
|
200
|
+
actualHeight > 0 ? actualWidth / actualHeight : 1;
|
|
201
|
+
|
|
202
|
+
if (resizeEdgeRef.current.includes("w")) {
|
|
203
|
+
const newWidth = rect.width + rect.x - pos.x;
|
|
204
|
+
if (newWidth > 0) {
|
|
205
|
+
newRect.width = newWidth;
|
|
206
|
+
newRect.x = pos.x;
|
|
207
|
+
if (aspectRatio) {
|
|
208
|
+
newRect.height =
|
|
209
|
+
(newRect.width / aspectRatio) * originalAspectRatio;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (resizeEdgeRef.current.includes("e")) {
|
|
214
|
+
const newWidth = pos.x - rect.x;
|
|
215
|
+
if (newWidth > 0) {
|
|
216
|
+
newRect.width = newWidth;
|
|
217
|
+
if (aspectRatio) {
|
|
218
|
+
newRect.height =
|
|
219
|
+
(newRect.width / aspectRatio) * originalAspectRatio;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (resizeEdgeRef.current.includes("n")) {
|
|
224
|
+
const newHeight = rect.height + rect.y - pos.y;
|
|
225
|
+
if (newHeight > 0) {
|
|
226
|
+
newRect.height = newHeight;
|
|
227
|
+
newRect.y = pos.y;
|
|
228
|
+
if (aspectRatio) {
|
|
229
|
+
newRect.width =
|
|
230
|
+
(newRect.height * aspectRatio) / originalAspectRatio;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (resizeEdgeRef.current.includes("s")) {
|
|
235
|
+
const newHeight = pos.y - rect.y;
|
|
236
|
+
if (newHeight > 0) {
|
|
237
|
+
newRect.height = newHeight;
|
|
238
|
+
if (aspectRatio) {
|
|
239
|
+
newRect.width =
|
|
240
|
+
(newRect.height * aspectRatio) / originalAspectRatio;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Constrain to bounds
|
|
246
|
+
if (newRect.x < 0) newRect.x = 0;
|
|
247
|
+
if (newRect.y < 0) newRect.y = 0;
|
|
248
|
+
if (newRect.x + newRect.width > 1) newRect.width = 1 - newRect.x;
|
|
249
|
+
if (newRect.y + newRect.height > 1) newRect.height = 1 - newRect.y;
|
|
250
|
+
|
|
251
|
+
setRect(newRect);
|
|
252
|
+
} else if (movingRef.current) {
|
|
253
|
+
setRect({
|
|
254
|
+
...rect,
|
|
255
|
+
x: Math.max(
|
|
256
|
+
0,
|
|
257
|
+
Math.min(
|
|
258
|
+
1 - rectRef.current.width,
|
|
259
|
+
(ev.clientX - bounds.left) / bounds.width - offset.current.x,
|
|
260
|
+
),
|
|
261
|
+
),
|
|
262
|
+
y: Math.max(
|
|
263
|
+
0,
|
|
264
|
+
Math.min(
|
|
265
|
+
1 - rectRef.current.height,
|
|
266
|
+
(ev.clientY - bounds.top) / bounds.height - offset.current.y,
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
});
|
|
270
|
+
} else {
|
|
271
|
+
const actualWidth =
|
|
272
|
+
selectedVariant.width > 0
|
|
273
|
+
? selectedVariant.width
|
|
274
|
+
: actualImageDimensions?.width || 0;
|
|
275
|
+
const actualHeight =
|
|
276
|
+
selectedVariant.height > 0
|
|
277
|
+
? selectedVariant.height
|
|
278
|
+
: actualImageDimensions?.height || 0;
|
|
279
|
+
const originalAspectRatio =
|
|
280
|
+
actualHeight > 0 ? actualWidth / actualHeight : 1;
|
|
281
|
+
|
|
282
|
+
const aspectRatio = selectedVariant.aspectRatioLock;
|
|
283
|
+
|
|
284
|
+
const currentX = (ev.clientX - bounds.left) / bounds.width;
|
|
285
|
+
const currentY = (ev.clientY - bounds.top) / bounds.height;
|
|
286
|
+
|
|
287
|
+
const minX = Math.min(rect.x, currentX);
|
|
288
|
+
const maxX = Math.max(rect.x, currentX);
|
|
289
|
+
const minY = Math.min(rect.y, currentY);
|
|
290
|
+
const maxY = Math.max(rect.y, currentY);
|
|
291
|
+
|
|
292
|
+
let width = maxX - minX;
|
|
293
|
+
let height = maxY - minY;
|
|
294
|
+
|
|
295
|
+
if (aspectRatio) {
|
|
296
|
+
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
|
297
|
+
height = (width / aspectRatio) * originalAspectRatio;
|
|
298
|
+
} else {
|
|
299
|
+
width = (height * aspectRatio) / originalAspectRatio;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (width + minX > 1) {
|
|
304
|
+
width = 1 - minX;
|
|
305
|
+
if (aspectRatio) height = (width / aspectRatio) * originalAspectRatio;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (height + minY > 1) {
|
|
309
|
+
height = 1 - minY;
|
|
310
|
+
if (aspectRatio) width = (height * aspectRatio) / originalAspectRatio;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Ensure final dimensions are non-negative
|
|
314
|
+
width = Math.max(0, width);
|
|
315
|
+
height = Math.max(0, height);
|
|
316
|
+
|
|
317
|
+
const newRect = { x: minX, y: minY, width, height };
|
|
318
|
+
setRect(newRect);
|
|
319
|
+
}
|
|
320
|
+
ev.preventDefault();
|
|
321
|
+
ev.stopPropagation();
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const handleMouseUp = () => {
|
|
326
|
+
if (!rectRef.current || !rectRef.current.width || !rectRef.current.height) {
|
|
327
|
+
setRect(undefined);
|
|
328
|
+
}
|
|
329
|
+
movingRef.current = false;
|
|
330
|
+
resizeEdgeRef.current = null;
|
|
331
|
+
setResizeEdge(null);
|
|
332
|
+
// window.removeEventListener("mousemove", handleMouseMove);
|
|
333
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const isInRect = (pos: { x: number; y: number }, rect?: Rect) => {
|
|
337
|
+
if (!rect || !selectedVariant) return false;
|
|
338
|
+
|
|
339
|
+
return (
|
|
340
|
+
pos.x >= rect.x &&
|
|
341
|
+
pos.x <= rect.x + rect.width &&
|
|
342
|
+
pos.y >= rect.y &&
|
|
343
|
+
pos.y <= rect.y + rect.height
|
|
344
|
+
);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const handleMouseDown = (ev: React.MouseEvent) => {
|
|
348
|
+
ev.preventDefault();
|
|
349
|
+
ev.stopPropagation();
|
|
350
|
+
const bounds = ev.currentTarget.getBoundingClientRect();
|
|
351
|
+
const pos = {
|
|
352
|
+
x: (ev.clientX - bounds.left) / bounds.width,
|
|
353
|
+
y: (ev.clientY - bounds.top) / bounds.height,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const edge = getResizeEdge(pos, rect, bounds);
|
|
357
|
+
if (edge) {
|
|
358
|
+
resizeEdgeRef.current = edge;
|
|
359
|
+
setResizeEdge(edge);
|
|
360
|
+
} else if (isInRect(pos, rect)) {
|
|
361
|
+
movingRef.current = true;
|
|
362
|
+
offset.current = {
|
|
363
|
+
x: pos.x - rect!.x,
|
|
364
|
+
y: pos.y - rect!.y,
|
|
365
|
+
};
|
|
366
|
+
} else {
|
|
367
|
+
setRect({
|
|
368
|
+
x: (ev.clientX - bounds.left) / bounds.width,
|
|
369
|
+
y: (ev.clientY - bounds.top) / bounds.height,
|
|
370
|
+
width: 0,
|
|
371
|
+
height: 0,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
setStartPos({ x: ev.clientX, y: ev.clientY });
|
|
376
|
+
|
|
377
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
if (!selectedVariant) return null;
|
|
381
|
+
|
|
382
|
+
const imageBounds = imageRef.current?.getBoundingClientRect();
|
|
383
|
+
const actualWidth =
|
|
384
|
+
selectedVariant.width > 0
|
|
385
|
+
? selectedVariant.width
|
|
386
|
+
: actualImageDimensions?.width || 0;
|
|
387
|
+
const actualHeight =
|
|
388
|
+
selectedVariant.height > 0
|
|
389
|
+
? selectedVariant.height
|
|
390
|
+
: actualImageDimensions?.height || 0;
|
|
391
|
+
const scale =
|
|
392
|
+
imageBounds && actualWidth > 0 ? actualWidth / imageBounds.width : 1;
|
|
393
|
+
const widthPx = rect ? Math.round(rect.width * actualWidth) : 0;
|
|
394
|
+
const heightPx = rect ? Math.round(rect.height * actualHeight) : 0;
|
|
395
|
+
|
|
396
|
+
return (
|
|
397
|
+
<>
|
|
398
|
+
<Dialog
|
|
399
|
+
header={"Crop " + field.name + " - " + selectedVariantName}
|
|
400
|
+
pt={{ content: { style: { paddingLeft: "0" } } }}
|
|
401
|
+
visible={true}
|
|
402
|
+
style={{ width: "75vw", height: "75vh" }}
|
|
403
|
+
onHide={onClose}
|
|
404
|
+
>
|
|
405
|
+
<div className="justify flex h-full flex-col gap-1">
|
|
406
|
+
<div className="flex flex-1 gap-2">
|
|
407
|
+
<div className="flex w-56 flex-col gap-3 bg-gray-100 p-4 text-sm">
|
|
408
|
+
<LabelAndValue label="Variant:" value={selectedVariantName} />
|
|
409
|
+
<LabelAndValue
|
|
410
|
+
label="Image Dimensions:"
|
|
411
|
+
value={
|
|
412
|
+
selectedVariant.width > 0 && selectedVariant.height > 0 ? (
|
|
413
|
+
<>
|
|
414
|
+
{selectedVariant.width} x {selectedVariant.height}
|
|
415
|
+
</>
|
|
416
|
+
) : actualImageDimensions ? (
|
|
417
|
+
<>
|
|
418
|
+
{actualImageDimensions.width} x{" "}
|
|
419
|
+
{actualImageDimensions.height} (actual)
|
|
420
|
+
</>
|
|
421
|
+
) : (
|
|
422
|
+
<span className="text-gray-500">Loading...</span>
|
|
423
|
+
)
|
|
424
|
+
}
|
|
425
|
+
/>
|
|
426
|
+
{selectedVariant.aspectRatioLock && (
|
|
427
|
+
<LabelAndValue
|
|
428
|
+
label="Required Aspect Ratio:"
|
|
429
|
+
value={selectedVariant.aspectRatioLockText}
|
|
430
|
+
/>
|
|
431
|
+
)}
|
|
432
|
+
{selectedVariant.minWidth && (
|
|
433
|
+
<LabelAndValue
|
|
434
|
+
label="Minimum Width:"
|
|
435
|
+
value={selectedVariant.minWidth}
|
|
436
|
+
/>
|
|
437
|
+
)}
|
|
438
|
+
{selectedVariant.minHeight && (
|
|
439
|
+
<LabelAndValue
|
|
440
|
+
label="Minimum Height:"
|
|
441
|
+
value={selectedVariant.minHeight}
|
|
442
|
+
/>
|
|
443
|
+
)}
|
|
444
|
+
{rect && (
|
|
445
|
+
<>
|
|
446
|
+
<LabelAndValue
|
|
447
|
+
label="Selection:"
|
|
448
|
+
value={
|
|
449
|
+
<>
|
|
450
|
+
{widthPx} x {heightPx}
|
|
451
|
+
</>
|
|
452
|
+
}
|
|
453
|
+
/>
|
|
454
|
+
{selectedVariant.minWidth &&
|
|
455
|
+
widthPx < selectedVariant.minWidth && (
|
|
456
|
+
<div className="text-red-500">Minimum width not met!</div>
|
|
457
|
+
)}
|
|
458
|
+
{selectedVariant.minHeight &&
|
|
459
|
+
heightPx < selectedVariant.minHeight && (
|
|
460
|
+
<div className="text-red-500">
|
|
461
|
+
Minimum height not met!
|
|
462
|
+
</div>
|
|
463
|
+
)}
|
|
464
|
+
</>
|
|
465
|
+
)}
|
|
466
|
+
</div>
|
|
467
|
+
<div className="relative flex-1 p-3">
|
|
468
|
+
<div className="absolute inset-0 top-3 flex items-center justify-center select-none">
|
|
469
|
+
<div
|
|
470
|
+
ref={imageRef}
|
|
471
|
+
className="relative max-h-full cursor-crosshair"
|
|
472
|
+
style={{
|
|
473
|
+
...(actualWidth > 0 && actualHeight > 0
|
|
474
|
+
? { aspectRatio: `${actualWidth}/${actualHeight}` }
|
|
475
|
+
: {}),
|
|
476
|
+
}}
|
|
477
|
+
onMouseDown={handleMouseDown}
|
|
478
|
+
onMouseMove={handleMouseMove}
|
|
479
|
+
>
|
|
480
|
+
<img
|
|
481
|
+
className="max-h-full max-w-full object-scale-down"
|
|
482
|
+
src={selectedVariant.originalSrc ?? selectedVariant.src}
|
|
483
|
+
onLoad={(e) => {
|
|
484
|
+
const img = e.target as HTMLImageElement;
|
|
485
|
+
setActualImageDimensions({
|
|
486
|
+
width: img.naturalWidth,
|
|
487
|
+
height: img.naturalHeight,
|
|
488
|
+
});
|
|
489
|
+
}}
|
|
490
|
+
/>
|
|
491
|
+
{rect && (
|
|
492
|
+
<div
|
|
493
|
+
className={classNames(
|
|
494
|
+
"absolute cursor-move border text-xs opacity-70",
|
|
495
|
+
isValid
|
|
496
|
+
? "border-blue-400 bg-blue-200 text-blue-500"
|
|
497
|
+
: "border-red-400 bg-red-200 text-red-500",
|
|
498
|
+
)}
|
|
499
|
+
style={{
|
|
500
|
+
left: rect.x * 100 + "%",
|
|
501
|
+
top: rect.y * 100 + "%",
|
|
502
|
+
width: widthPx / scale + "px",
|
|
503
|
+
height: heightPx / scale + "px",
|
|
504
|
+
cursor: resizeEdge
|
|
505
|
+
? resizeEdge.length === 1
|
|
506
|
+
? `${resizeEdge}-resize`
|
|
507
|
+
: `${resizeEdge}-resize`
|
|
508
|
+
: "move",
|
|
509
|
+
}}
|
|
510
|
+
>
|
|
511
|
+
{widthPx / scale > 50 && (
|
|
512
|
+
<div
|
|
513
|
+
className="absolute right-2 bottom-1 text-nowrap"
|
|
514
|
+
style={{ textShadow: "white 1px 1px" }}
|
|
515
|
+
>
|
|
516
|
+
{widthPx} x {heightPx}
|
|
517
|
+
</div>
|
|
518
|
+
)}
|
|
519
|
+
</div>
|
|
520
|
+
)}
|
|
521
|
+
</div>
|
|
522
|
+
</div>
|
|
523
|
+
</div>
|
|
524
|
+
</div>
|
|
525
|
+
<DialogButtons>
|
|
526
|
+
<Button onClick={() => setRect(undefined)}>Reset</Button>
|
|
527
|
+
<Button
|
|
528
|
+
size="small"
|
|
529
|
+
disabled={!isValid}
|
|
530
|
+
onClick={() => {
|
|
531
|
+
if (pictureValue) {
|
|
532
|
+
if (field) {
|
|
533
|
+
editContext?.operations.editField({
|
|
534
|
+
field: field.descriptor,
|
|
535
|
+
rawValue: JSON.stringify(rawValue),
|
|
536
|
+
refresh: "immediate",
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
onClose();
|
|
541
|
+
}}
|
|
542
|
+
>
|
|
543
|
+
Ok
|
|
544
|
+
</Button>
|
|
545
|
+
<Button onClick={onClose} size="small">
|
|
546
|
+
Cancel
|
|
547
|
+
</Button>
|
|
548
|
+
</DialogButtons>
|
|
549
|
+
</div>
|
|
550
|
+
</Dialog>
|
|
551
|
+
</>
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function LabelAndValue({
|
|
556
|
+
label,
|
|
557
|
+
value,
|
|
558
|
+
}: {
|
|
559
|
+
label: ReactNode;
|
|
560
|
+
value: ReactNode;
|
|
561
|
+
}) {
|
|
562
|
+
return (
|
|
563
|
+
<div>
|
|
564
|
+
<div className="font-bold">{label}</div>
|
|
565
|
+
<div>{value}</div>
|
|
566
|
+
</div>
|
|
567
|
+
);
|
|
568
|
+
}
|