@alpaca-editor/core 1.0.3942 → 1.0.3944

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.
Files changed (308) hide show
  1. package/.prettierrc +3 -0
  2. package/build.css +3 -0
  3. package/components.json +21 -0
  4. package/dist/editor/ContentTree.d.ts +2 -1
  5. package/dist/editor/ContentTree.js +23 -21
  6. package/dist/editor/ContentTree.js.map +1 -1
  7. package/dist/editor/FieldActionsOverlay.js +0 -2
  8. package/dist/editor/FieldActionsOverlay.js.map +1 -1
  9. package/dist/editor/ScrollingContentTree.js +1 -1
  10. package/dist/editor/ScrollingContentTree.js.map +1 -1
  11. package/dist/editor/Titlebar.js +1 -1
  12. package/dist/editor/Titlebar.js.map +1 -1
  13. package/dist/editor/ai/GhostWriter.js +24 -3
  14. package/dist/editor/ai/GhostWriter.js.map +1 -1
  15. package/dist/editor/client/EditorClient.js +7 -7
  16. package/dist/editor/client/EditorClient.js.map +1 -1
  17. package/dist/editor/field-types/InternalLinkFieldEditor.js +60 -10
  18. package/dist/editor/field-types/InternalLinkFieldEditor.js.map +1 -1
  19. package/dist/editor/media-selector/MediaFolderBrowser.js +48 -1
  20. package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -1
  21. package/dist/editor/menubar/PageSelector.js +116 -65
  22. package/dist/editor/menubar/PageSelector.js.map +1 -1
  23. package/dist/editor/page-viewer/EditorForm.js +5 -2
  24. package/dist/editor/page-viewer/EditorForm.js.map +1 -1
  25. package/dist/editor/ui/ItemSearch.js +14 -8
  26. package/dist/editor/ui/ItemSearch.js.map +1 -1
  27. package/dist/editor/ui/PerfectTree.d.ts +4 -2
  28. package/dist/editor/ui/PerfectTree.js +78 -4
  29. package/dist/editor/ui/PerfectTree.js.map +1 -1
  30. package/dist/editor/ui/Splitter.js +1 -1
  31. package/dist/revision.d.ts +2 -2
  32. package/dist/revision.js +2 -2
  33. package/dist/styles.css +8 -2
  34. package/eslint.config.mjs +4 -0
  35. package/images/bg-shape-black.webp +0 -0
  36. package/images/wizard-bg.png +0 -0
  37. package/images/wizard-tour.png +0 -0
  38. package/images/wizard.png +0 -0
  39. package/package.json +2 -8
  40. package/src/client-components/api.ts +6 -0
  41. package/src/client-components/index.ts +19 -0
  42. package/src/components/ActionButton.tsx +50 -0
  43. package/src/components/Error.tsx +57 -0
  44. package/src/components/ui/CardConnector.tsx +56 -0
  45. package/src/components/ui/button.tsx +62 -0
  46. package/src/components/ui/card.tsx +372 -0
  47. package/src/components/ui/context-menu.tsx +250 -0
  48. package/src/config/config.tsx +917 -0
  49. package/src/config/types.ts +286 -0
  50. package/src/editor/ComponentInfo.tsx +90 -0
  51. package/src/editor/ConfirmationDialog.tsx +103 -0
  52. package/src/editor/ContentTree.tsx +733 -0
  53. package/src/editor/ContextMenu.tsx +230 -0
  54. package/src/editor/Editor.tsx +90 -0
  55. package/src/editor/EditorWarning.tsx +34 -0
  56. package/src/editor/EditorWarnings.tsx +33 -0
  57. package/src/editor/FieldActionsOverlay.tsx +296 -0
  58. package/src/editor/FieldEditorPopup.tsx +65 -0
  59. package/src/editor/FieldHistory.tsx +75 -0
  60. package/src/editor/FieldList.tsx +190 -0
  61. package/src/editor/FieldListField.tsx +391 -0
  62. package/src/editor/FieldListFieldWithFallbacks.tsx +217 -0
  63. package/src/editor/FloatingToolbar.tsx +163 -0
  64. package/src/editor/ImageEditor.tsx +128 -0
  65. package/src/editor/ItemInfo.tsx +90 -0
  66. package/src/editor/LinkEditorDialog.tsx +196 -0
  67. package/src/editor/MainLayout.tsx +95 -0
  68. package/src/editor/MobileLayout.tsx +68 -0
  69. package/src/editor/NewEditorClient.tsx +11 -0
  70. package/src/editor/PictureCropper.tsx +568 -0
  71. package/src/editor/PictureEditor.tsx +301 -0
  72. package/src/editor/PictureEditorDialog.tsx +381 -0
  73. package/src/editor/PublishDialog.ignore +74 -0
  74. package/src/editor/ScrollingContentTree.tsx +68 -0
  75. package/src/editor/Terminal.tsx +227 -0
  76. package/src/editor/Titlebar.tsx +104 -0
  77. package/src/editor/ai/AiPopup.tsx +59 -0
  78. package/src/editor/ai/AiResponseMessage.tsx +106 -0
  79. package/src/editor/ai/AiTerminal.tsx +503 -0
  80. package/src/editor/ai/AiToolCall.tsx +61 -0
  81. package/src/editor/ai/EditorAiTerminal.tsx +20 -0
  82. package/src/editor/ai/GhostWriter.tsx +480 -0
  83. package/src/editor/ai/aiPageModel.ts +108 -0
  84. package/src/editor/ai/editorAiContext.ts +18 -0
  85. package/src/editor/client/AboutDialog.tsx +44 -0
  86. package/src/editor/client/EditorClient.tsx +2241 -0
  87. package/src/editor/client/GenericDialog.tsx +50 -0
  88. package/src/editor/client/editContext.ts +416 -0
  89. package/src/editor/client/helpers.ts +44 -0
  90. package/src/editor/client/itemsRepository.ts +574 -0
  91. package/src/editor/client/operations.ts +768 -0
  92. package/src/editor/client/pageModelBuilder.ts +219 -0
  93. package/src/editor/commands/commands.ts +22 -0
  94. package/src/editor/commands/componentCommands.tsx +431 -0
  95. package/src/editor/commands/createVersionCommand.ts +33 -0
  96. package/src/editor/commands/deleteVersionCommand.ts +71 -0
  97. package/src/editor/commands/itemCommands.tsx +351 -0
  98. package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
  99. package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +27 -0
  100. package/src/editor/commands/undo.ts +39 -0
  101. package/src/editor/component-designer/ComponentDesigner.tsx +70 -0
  102. package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +11 -0
  103. package/src/editor/component-designer/ComponentDesignerMenu.tsx +91 -0
  104. package/src/editor/component-designer/ComponentEditor.tsx +97 -0
  105. package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +31 -0
  106. package/src/editor/component-designer/ComponentRenderingEditor.tsx +104 -0
  107. package/src/editor/component-designer/ComponentsDropdown.tsx +39 -0
  108. package/src/editor/component-designer/PlaceholdersEditor.tsx +179 -0
  109. package/src/editor/component-designer/RenderingsDropdown.tsx +36 -0
  110. package/src/editor/component-designer/TemplateEditor.tsx +236 -0
  111. package/src/editor/component-designer/aiContext.ts +23 -0
  112. package/src/editor/componentTreeHelper.tsx +116 -0
  113. package/src/editor/context-menu/CopyMoveMenu.tsx +103 -0
  114. package/src/editor/context-menu/InsertMenu.tsx +347 -0
  115. package/src/editor/control-center/About.tsx +342 -0
  116. package/src/editor/control-center/ControlCenterMenu.tsx +76 -0
  117. package/src/editor/control-center/IndexOverview.tsx +50 -0
  118. package/src/editor/control-center/IndexSettings.tsx +266 -0
  119. package/src/editor/control-center/Info.tsx +104 -0
  120. package/src/editor/control-center/QuotaInfo.tsx +301 -0
  121. package/src/editor/control-center/Status.tsx +113 -0
  122. package/src/editor/control-center/WebSocketMessages.tsx +155 -0
  123. package/src/editor/editor-warnings/ItemLocked.tsx +63 -0
  124. package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +22 -0
  125. package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +23 -0
  126. package/src/editor/editor-warnings/NoWriteAccess.tsx +16 -0
  127. package/src/editor/editor-warnings/ValidationErrors.tsx +54 -0
  128. package/src/editor/field-types/AttachmentEditor.tsx +9 -0
  129. package/src/editor/field-types/CheckboxEditor.tsx +47 -0
  130. package/src/editor/field-types/DropLinkEditor.tsx +80 -0
  131. package/src/editor/field-types/DropListEditor.tsx +84 -0
  132. package/src/editor/field-types/ImageFieldEditor.tsx +65 -0
  133. package/src/editor/field-types/InternalLinkFieldEditor.tsx +188 -0
  134. package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
  135. package/src/editor/field-types/MultiLineText.tsx +82 -0
  136. package/src/editor/field-types/PictureFieldEditor.tsx +121 -0
  137. package/src/editor/field-types/RawEditor.tsx +53 -0
  138. package/src/editor/field-types/ReactQuill.tsx +580 -0
  139. package/src/editor/field-types/RichTextEditor.tsx +22 -0
  140. package/src/editor/field-types/RichTextEditorComponent.tsx +127 -0
  141. package/src/editor/field-types/SingleLineText.tsx +174 -0
  142. package/src/editor/field-types/TreeListEditor.tsx +261 -0
  143. package/src/editor/fieldTypes.ts +140 -0
  144. package/src/editor/media-selector/AiImageSearch.tsx +185 -0
  145. package/src/editor/media-selector/AiImageSearchPrompt.tsx +94 -0
  146. package/src/editor/media-selector/MediaFolderBrowser.tsx +321 -0
  147. package/src/editor/media-selector/MediaSelector.tsx +42 -0
  148. package/src/editor/media-selector/Preview.tsx +14 -0
  149. package/src/editor/media-selector/Thumbnails.tsx +48 -0
  150. package/src/editor/media-selector/TreeSelector.tsx +292 -0
  151. package/src/editor/media-selector/UploadZone.tsx +137 -0
  152. package/src/editor/media-selector/index.ts +8 -0
  153. package/src/editor/menubar/ActionsMenu.tsx +94 -0
  154. package/src/editor/menubar/ActiveUsers.tsx +17 -0
  155. package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
  156. package/src/editor/menubar/BrowseHistory.tsx +28 -0
  157. package/src/editor/menubar/ItemLanguageVersion.tsx +76 -0
  158. package/src/editor/menubar/LanguageSelector.tsx +226 -0
  159. package/src/editor/menubar/Menu.tsx +83 -0
  160. package/src/editor/menubar/NavButtons.tsx +74 -0
  161. package/src/editor/menubar/PageSelector.tsx +278 -0
  162. package/src/editor/menubar/PageViewerControls.tsx +120 -0
  163. package/src/editor/menubar/PreviewSecondaryControls.tsx +18 -0
  164. package/src/editor/menubar/SecondaryControls.tsx +45 -0
  165. package/src/editor/menubar/Separator.tsx +12 -0
  166. package/src/editor/menubar/SiteInfo.tsx +53 -0
  167. package/src/editor/menubar/User.tsx +27 -0
  168. package/src/editor/menubar/VersionSelector.tsx +142 -0
  169. package/src/editor/page-editor-chrome/CommentHighlighting.tsx +307 -0
  170. package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
  171. package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +59 -0
  172. package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +23 -0
  173. package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +64 -0
  174. package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +35 -0
  175. package/src/editor/page-editor-chrome/FrameMenu.tsx +338 -0
  176. package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
  177. package/src/editor/page-editor-chrome/InlineEditor.tsx +765 -0
  178. package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +61 -0
  179. package/src/editor/page-editor-chrome/NoLayout.tsx +36 -0
  180. package/src/editor/page-editor-chrome/PageEditorChrome.tsx +122 -0
  181. package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +161 -0
  182. package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +169 -0
  183. package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +315 -0
  184. package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +300 -0
  185. package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +40 -0
  186. package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +828 -0
  187. package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
  188. package/src/editor/page-viewer/EditorForm.tsx +262 -0
  189. package/src/editor/page-viewer/MiniMap.tsx +362 -0
  190. package/src/editor/page-viewer/PageViewer.tsx +169 -0
  191. package/src/editor/page-viewer/PageViewerFrame.tsx +1022 -0
  192. package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +412 -0
  193. package/src/editor/page-viewer/pageViewContext.ts +186 -0
  194. package/src/editor/pageModel.ts +220 -0
  195. package/src/editor/picture-shared.tsx +53 -0
  196. package/src/editor/reviews/Comment.tsx +308 -0
  197. package/src/editor/reviews/Comments.tsx +125 -0
  198. package/src/editor/reviews/DiffView.tsx +109 -0
  199. package/src/editor/reviews/PreviewInfo.tsx +35 -0
  200. package/src/editor/reviews/Reviews.tsx +280 -0
  201. package/src/editor/reviews/SuggestedEdit.tsx +316 -0
  202. package/src/editor/reviews/reviewCommands.tsx +47 -0
  203. package/src/editor/reviews/useReviews.tsx +70 -0
  204. package/src/editor/services/aiService.ts +173 -0
  205. package/src/editor/services/componentDesignerService.ts +151 -0
  206. package/src/editor/services/contentService.ts +180 -0
  207. package/src/editor/services/editService.ts +488 -0
  208. package/src/editor/services/indexService.ts +24 -0
  209. package/src/editor/services/reviewsService.ts +53 -0
  210. package/src/editor/services/serviceHelper.ts +95 -0
  211. package/src/editor/services/suggestedEditsService.ts +39 -0
  212. package/src/editor/services/systemService.ts +5 -0
  213. package/src/editor/services/translationService.ts +21 -0
  214. package/src/editor/services-server/api.ts +150 -0
  215. package/src/editor/services-server/graphQL.ts +106 -0
  216. package/src/editor/sidebar/ComponentPalette.tsx +161 -0
  217. package/src/editor/sidebar/ComponentTree.tsx +549 -0
  218. package/src/editor/sidebar/Debug.tsx +111 -0
  219. package/src/editor/sidebar/DictionaryEditor.tsx +261 -0
  220. package/src/editor/sidebar/EditHistory.tsx +134 -0
  221. package/src/editor/sidebar/GraphQL.tsx +164 -0
  222. package/src/editor/sidebar/Insert.tsx +35 -0
  223. package/src/editor/sidebar/MainContentTree.tsx +102 -0
  224. package/src/editor/sidebar/Performance.tsx +53 -0
  225. package/src/editor/sidebar/Sessions.tsx +35 -0
  226. package/src/editor/sidebar/Sidebar.tsx +20 -0
  227. package/src/editor/sidebar/SidebarView.tsx +152 -0
  228. package/src/editor/sidebar/Translations.tsx +295 -0
  229. package/src/editor/sidebar/Validation.tsx +102 -0
  230. package/src/editor/sidebar/ViewSelector.tsx +60 -0
  231. package/src/editor/sidebar/Workbox.tsx +209 -0
  232. package/src/editor/ui/CenteredMessage.tsx +7 -0
  233. package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +81 -0
  234. package/src/editor/ui/CopyToClipboardButton.tsx +24 -0
  235. package/src/editor/ui/DialogButtons.tsx +11 -0
  236. package/src/editor/ui/Icons.tsx +709 -0
  237. package/src/editor/ui/ItemList.tsx +76 -0
  238. package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
  239. package/src/editor/ui/ItemSearch.tsx +159 -0
  240. package/src/editor/ui/PerfectTree.tsx +676 -0
  241. package/src/editor/ui/Section.tsx +35 -0
  242. package/src/editor/ui/SimpleIconButton.tsx +54 -0
  243. package/src/editor/ui/SimpleMenu.tsx +40 -0
  244. package/src/editor/ui/SimpleTable.tsx +60 -0
  245. package/src/editor/ui/SimpleTabs.tsx +60 -0
  246. package/src/editor/ui/SimpleToolbar.tsx +7 -0
  247. package/src/editor/ui/Spinner.tsx +9 -0
  248. package/src/editor/ui/Splitter.tsx +420 -0
  249. package/src/editor/ui/StackedPanels.tsx +134 -0
  250. package/src/editor/ui/Toolbar.tsx +7 -0
  251. package/src/editor/utils/id-helper.ts +3 -0
  252. package/src/editor/utils/insertOptions.ts +69 -0
  253. package/src/editor/utils/itemutils.ts +29 -0
  254. package/src/editor/utils/useMemoDebug.ts +28 -0
  255. package/src/editor/utils.ts +486 -0
  256. package/src/editor/views/CompareView.tsx +245 -0
  257. package/src/editor/views/EditView.tsx +27 -0
  258. package/src/editor/views/ItemEditor.tsx +58 -0
  259. package/src/editor/views/MediaFolderEditView.tsx +66 -0
  260. package/src/editor/views/SingleEditView.tsx +57 -0
  261. package/src/fonts/Geist-Black.woff2 +0 -0
  262. package/src/fonts/Geist-Bold.woff2 +0 -0
  263. package/src/fonts/Geist-ExtraBold.woff2 +0 -0
  264. package/src/fonts/Geist-ExtraLight.woff2 +0 -0
  265. package/src/fonts/Geist-Light.woff2 +0 -0
  266. package/src/fonts/Geist-Medium.woff2 +0 -0
  267. package/src/fonts/Geist-Regular.woff2 +0 -0
  268. package/src/fonts/Geist-SemiBold.woff2 +0 -0
  269. package/src/fonts/Geist-Thin.woff2 +0 -0
  270. package/src/fonts/Geist[wght].woff2 +0 -0
  271. package/src/fonts/index.ts +10 -0
  272. package/src/index.ts +23 -0
  273. package/src/lib/safelist.tsx +16 -0
  274. package/src/lib/utils.ts +6 -0
  275. package/src/page-wizard/PageWizard.tsx +139 -0
  276. package/src/page-wizard/WizardBox.tsx +4 -0
  277. package/src/page-wizard/WizardBoxConnector.tsx +56 -0
  278. package/src/page-wizard/WizardSteps.tsx +458 -0
  279. package/src/page-wizard/service.ts +35 -0
  280. package/src/page-wizard/startPageWizardCommand.ts +26 -0
  281. package/src/page-wizard/steps/BuildPageStep.tsx +259 -0
  282. package/src/page-wizard/steps/CollectStep.tsx +296 -0
  283. package/src/page-wizard/steps/ComponentTypesSelector.tsx +454 -0
  284. package/src/page-wizard/steps/Components.tsx +193 -0
  285. package/src/page-wizard/steps/ContentStep.tsx +890 -0
  286. package/src/page-wizard/steps/EditButton.tsx +34 -0
  287. package/src/page-wizard/steps/FieldEditor.tsx +102 -0
  288. package/src/page-wizard/steps/Generate.tsx +60 -0
  289. package/src/page-wizard/steps/ImagesStep.tsx +382 -0
  290. package/src/page-wizard/steps/LayoutStep.tsx +227 -0
  291. package/src/page-wizard/steps/MetaDataStep.tsx +173 -0
  292. package/src/page-wizard/steps/SelectStep.tsx +281 -0
  293. package/src/page-wizard/steps/schema.ts +180 -0
  294. package/src/page-wizard/steps/usePageCreator.ts +325 -0
  295. package/src/page-wizard/usePageWizard.ts +79 -0
  296. package/src/revision.ts +2 -0
  297. package/src/splash-screen/NewPage.tsx +294 -0
  298. package/src/splash-screen/OpenPage.tsx +113 -0
  299. package/src/splash-screen/RecentPages.tsx +123 -0
  300. package/src/splash-screen/SectionHeadline.tsx +21 -0
  301. package/src/splash-screen/SplashScreen.tsx +195 -0
  302. package/src/tour/Tour.tsx +566 -0
  303. package/src/tour/default-tour.tsx +301 -0
  304. package/src/tour/preview-tour.tsx +128 -0
  305. package/src/types.ts +335 -0
  306. package/styles.css +765 -0
  307. package/tsconfig.build.json +31 -0
  308. package/tsconfig.json +14 -0
@@ -0,0 +1,301 @@
1
+ import {
2
+ MouseEventHandler,
3
+ useCallback,
4
+ useEffect,
5
+ useRef,
6
+ useState,
7
+ } from "react";
8
+ import { useEditContext } from "./client/editContext";
9
+ import { PictureCropper } from "./PictureCropper";
10
+ import { PictureField, PictureRawValue } from "./fieldTypes";
11
+ import { MediaSelectorMode } from "./media-selector/MediaSelector";
12
+ import { loadFieldButtons } from "./services/editService";
13
+ import { FieldButton } from "./pageModel";
14
+ import {
15
+ FieldActionsOverlay,
16
+ FieldActionsOverlayRef,
17
+ } from "./FieldActionsOverlay";
18
+
19
+ export function PictureEditor({
20
+ field,
21
+ variantName,
22
+ style,
23
+ forwardScrollevents,
24
+ isPageEditor,
25
+ }: {
26
+ field: PictureField;
27
+ variantName: string;
28
+ style?: React.CSSProperties;
29
+ forwardScrollevents?: boolean;
30
+ isPageEditor?: boolean;
31
+ }) {
32
+ const [showMenu, setShowMenu] = useState(false);
33
+ const [showCropper, setShowCropper] = useState(false);
34
+ const [fieldButtons, setFieldButtons] = useState<FieldButton[]>([]);
35
+ const fieldActionsOverlay = useRef<FieldActionsOverlayRef>(null);
36
+ const editContext = useEditContext();
37
+
38
+ // Load field buttons when component mounts
39
+ useEffect(() => {
40
+ const loadButtons = async () => {
41
+ if (field.descriptor) {
42
+ try {
43
+ const buttons = await loadFieldButtons(field.descriptor);
44
+ setFieldButtons(buttons);
45
+ } catch (error) {
46
+ console.warn("Failed to load field buttons:", error);
47
+ }
48
+ }
49
+ };
50
+ loadButtons();
51
+ }, [field.descriptor]);
52
+
53
+ // Field action handlers
54
+ const handleActionClick = useCallback(
55
+ async (action: FieldButton): Promise<void> => {
56
+ editContext?.triggerFieldAction(field.descriptor, action);
57
+ },
58
+ [editContext, field.descriptor],
59
+ );
60
+
61
+ const handleParameterizedActionExecute = useCallback(
62
+ async (
63
+ action: FieldButton,
64
+ parameters: Record<string, string>,
65
+ ): Promise<void> => {
66
+ editContext?.triggerFieldAction(field.descriptor, action, parameters);
67
+ },
68
+ [editContext, field.descriptor],
69
+ );
70
+
71
+ const variant = field.value?.variants?.find((v) => v.name === variantName);
72
+ const raw = (() => {
73
+ try {
74
+ return field?.rawValue && field?.rawValue[0] === "{"
75
+ ? (JSON.parse(field?.rawValue) as PictureRawValue)
76
+ : ({ Variants: [] } as PictureRawValue);
77
+ } catch (error) {
78
+ console.warn("Failed to parse picture field raw value:", error);
79
+ return { Variants: [] } as PictureRawValue;
80
+ }
81
+ })();
82
+
83
+ const rawVariant = raw.Variants?.find((x) => x.Name == variantName);
84
+
85
+ const reset = useCallback(() => {
86
+ raw.Variants = raw.Variants.filter((x) => x.Name !== variantName);
87
+ editContext!.operations.editField({
88
+ field: field.descriptor,
89
+ rawValue: JSON.stringify(raw),
90
+ refresh: "immediate",
91
+ });
92
+ }, [field, variant]);
93
+
94
+ const imageSelected = useCallback(
95
+ async (imageId: string) => {
96
+ const selected = raw.Variants?.find((x) => x.Name == variantName);
97
+ if (!selected) {
98
+ if (!raw.Variants) raw.Variants = [];
99
+ raw.Variants.push({
100
+ Name: variantName,
101
+ MediaId: imageId,
102
+ });
103
+ } else {
104
+ selected.MediaId = imageId;
105
+ }
106
+
107
+ editContext!.operations.editField({
108
+ field: field.descriptor,
109
+ rawValue: JSON.stringify(raw),
110
+ refresh: "immediate",
111
+ });
112
+ },
113
+ [field, variant],
114
+ );
115
+
116
+ const videoSelected = useCallback(
117
+ async (videoId: string) => {
118
+ const selected = raw.Variants?.find((x) => x.Name == variantName);
119
+ if (!selected) {
120
+ if (!raw.Variants) raw.Variants = [];
121
+ raw.Variants.push({
122
+ Name: variantName,
123
+ VideoId: videoId,
124
+ });
125
+ } else {
126
+ selected.VideoId = videoId;
127
+ }
128
+
129
+ editContext!.operations.editField({
130
+ field: field.descriptor,
131
+ rawValue: JSON.stringify(raw),
132
+ refresh: "immediate",
133
+ });
134
+ },
135
+ [field, variant],
136
+ );
137
+
138
+ async function selectMedia(mode: MediaSelectorMode) {
139
+ const selectedImageId = await editContext?.selectMedia({
140
+ selectedIdPath: variant?.idPath || "",
141
+ mode: mode,
142
+ });
143
+ if (selectedImageId) imageSelected(selectedImageId);
144
+ }
145
+
146
+ async function selectVideo() {
147
+ const selectedVideoId = await editContext?.selectMedia({
148
+ selectedIdPath: variant?.idPath || "",
149
+ mode: "video",
150
+ });
151
+ if (selectedVideoId) videoSelected(selectedVideoId);
152
+ }
153
+
154
+ const notEmpty = variant?.mediaId;
155
+
156
+ return (
157
+ <div
158
+ className="absolute inset-0 flex items-center justify-center"
159
+ onMouseEnter={() => setShowMenu(true)}
160
+ onMouseLeave={() => setShowMenu(false)}
161
+ onClick={() => {
162
+ if (!isPageEditor) return;
163
+ const itemId = field.descriptor.item?.id;
164
+ if (itemId) editContext?.select([itemId]);
165
+ }}
166
+ onWheel={(e) => {
167
+ if (forwardScrollevents)
168
+ editContext?.pageView.editorIframeRef!.current?.contentWindow?.document.documentElement?.scrollBy(
169
+ {
170
+ behavior: "instant",
171
+ left: 0,
172
+ top: e.deltaY,
173
+ },
174
+ );
175
+ editContext?.pageView.editorIframeRef!.current?.contentWindow?.document.body?.scrollBy(
176
+ {
177
+ behavior: "instant",
178
+ left: 0,
179
+ top: e.deltaY,
180
+ },
181
+ );
182
+ }}
183
+ style={style}
184
+ data-testid="select-media"
185
+ >
186
+ {showMenu && (
187
+ <div className="grid min-w-48 grid-cols-2 items-stretch justify-center gap-1.5 p-3 text-sm">
188
+ <Btn
189
+ label="Select"
190
+ icon="pi pi-image"
191
+ onClick={() => selectMedia("images")}
192
+ testId="select-media-button"
193
+ className="min-w-[80px]"
194
+ />
195
+ {field.value?.allowVideos && (
196
+ <Btn
197
+ label="Video"
198
+ icon="pi pi-video"
199
+ onClick={() => selectVideo()}
200
+ testId="video-media-button"
201
+ className="min-w-[80px]"
202
+ />
203
+ )}
204
+ {notEmpty && (
205
+ <Btn
206
+ label="Crop"
207
+ icon="pi pi-expand"
208
+ onClick={() => {
209
+ setShowCropper(true);
210
+ }}
211
+ testId="crop-media-button"
212
+ className="min-w-[80px]"
213
+ />
214
+ )}
215
+ {rawVariant && (
216
+ <Btn
217
+ label="Reset"
218
+ icon="pi pi-times"
219
+ onClick={() => reset()}
220
+ testId="reset-media-button"
221
+ className="min-w-[80px]"
222
+ />
223
+ )}
224
+ {fieldButtons.map((button) => (
225
+ <Btn
226
+ key={button.id}
227
+ label={button.label}
228
+ icon={
229
+ button.isGenerator
230
+ ? "pi pi-cog"
231
+ : button.icon && button.icon.trim() !== ""
232
+ ? button.icon
233
+ : "pi pi-bolt"
234
+ }
235
+ onClick={(e) => {
236
+ if (button.parameters && button.parameters.length > 0) {
237
+ fieldActionsOverlay.current?.show(e, button);
238
+ } else {
239
+ handleActionClick(button);
240
+ }
241
+ }}
242
+ testId={`field-action-${button.id}`}
243
+ className="min-w-[80px]"
244
+ />
245
+ ))}
246
+ </div>
247
+ )}
248
+ {showCropper && (
249
+ <PictureCropper
250
+ field={field}
251
+ onClose={() => setShowCropper(false)}
252
+ variantName={variantName}
253
+ />
254
+ )}
255
+ <FieldActionsOverlay
256
+ ref={fieldActionsOverlay}
257
+ generatorButtons={fieldButtons}
258
+ onActionClick={handleActionClick}
259
+ onParameterizedActionExecute={handleParameterizedActionExecute}
260
+ currentOverlay={editContext?.currentOverlay}
261
+ fieldId={field.id}
262
+ setCurrentOverlay={editContext?.setCurrentOverlay || (() => {})}
263
+ hideBackButton={true}
264
+ />
265
+ </div>
266
+ );
267
+ }
268
+
269
+ function Btn({
270
+ label,
271
+ icon,
272
+ onClick,
273
+ testId,
274
+ className,
275
+ }: {
276
+ label: string;
277
+ icon: string;
278
+ onClick: MouseEventHandler<HTMLButtonElement>;
279
+ testId?: string;
280
+ className?: string;
281
+ }) {
282
+ const isImageUrl =
283
+ icon.startsWith("http://") ||
284
+ icon.startsWith("https://") ||
285
+ icon.startsWith("/");
286
+
287
+ return (
288
+ <button
289
+ className={`btn flex cursor-pointer items-center gap-1.5 rounded-lg border bg-gray-500 p-1.5 text-white opacity-70 hover:opacity-85 ${className}`}
290
+ onClick={onClick}
291
+ data-testid={testId}
292
+ >
293
+ {isImageUrl ? (
294
+ <img src={icon} alt="" className="h-4 w-4" />
295
+ ) : (
296
+ <i className={icon} />
297
+ )}{" "}
298
+ {label}
299
+ </button>
300
+ );
301
+ }
@@ -0,0 +1,381 @@
1
+ import { Dialog } from "primereact/dialog";
2
+
3
+ import { useEditContext } from "./client/editContext";
4
+
5
+ import { useCallback, useEffect, useState } from "react";
6
+ import { Button } from "primereact/button";
7
+ import DialogButtons from "./ui/DialogButtons";
8
+
9
+ import { getPictureValue } from "./services/editService";
10
+ import {
11
+ PictureField,
12
+ PictureRawValue,
13
+ PictureRawVariant,
14
+ PictureValue,
15
+ } from "./fieldTypes";
16
+
17
+ import {
18
+ MediaPictureParams,
19
+ PictureParams,
20
+ getRenderedPictureVariant,
21
+ } from "./picture-shared";
22
+ import { Field } from "./pageModel";
23
+
24
+ export function PictureEditorDialog({
25
+ field,
26
+ onCancel,
27
+ onOk,
28
+ params,
29
+ }: {
30
+ field: PictureField;
31
+ onOk: (link: PictureValue) => void;
32
+ onCancel: () => void;
33
+ params?: PictureParams | MediaPictureParams;
34
+ }) {
35
+ const [selectedVariantName, setSelectedVariantName] = useState<string>();
36
+ const [pictureValue, setPictureValue] = useState<PictureValue>();
37
+ const [rawValue, setRawValue] = useState<PictureRawValue>();
38
+ const emptyRect = () => ({
39
+ width: 0,
40
+ height: 0,
41
+ top: 0,
42
+ left: 0,
43
+ });
44
+ const [rect, setRect] = useState(emptyRect());
45
+
46
+ const editContext = useEditContext();
47
+ useEffect(() => {
48
+ setSelectedVariantName(field?.value?.variants[0].name);
49
+ }, []);
50
+
51
+ useEffect(() => {
52
+ const deepCopy = JSON.parse(JSON.stringify(field.value));
53
+ setPictureValue(deepCopy);
54
+ const raw = field?.rawValue
55
+ ? (JSON.parse(field?.rawValue) as PictureRawValue)
56
+ : ({ Variants: [] } as PictureRawValue);
57
+ setRawValue(raw);
58
+ if (!field?.value?.variants[0].src)
59
+ selectMedia(field?.value?.variants[0].name, raw);
60
+ }, [field]);
61
+
62
+ async function selectMedia(variantName?: string, raw?: PictureRawValue) {
63
+ const chosenImage = await editContext?.selectMedia({
64
+ selectedIdPath: selectedVariant?.idPath || "",
65
+ mode: "images",
66
+ });
67
+ if (chosenImage)
68
+ imageSelected(
69
+ chosenImage,
70
+ variantName ?? selectedVariantName,
71
+ raw ?? rawValue
72
+ );
73
+ }
74
+
75
+ const selectedVariant =
76
+ pictureValue && pictureValue.variants
77
+ ? pictureValue.variants?.find((x) => x.name == selectedVariantName)
78
+ : null;
79
+
80
+ useEffect(() => {
81
+ if (
82
+ selectedVariant?.region &&
83
+ (!selectedVariant.aspectRatioLock ||
84
+ Math.abs(
85
+ selectedVariant.aspectRatioLock -
86
+ selectedVariant.region.width / selectedVariant.region.height
87
+ ) < 0.1)
88
+ )
89
+ setRect({
90
+ width: selectedVariant.region.width,
91
+ height: selectedVariant.region.height,
92
+ top: selectedVariant.region.y,
93
+ left: selectedVariant.region.x,
94
+ });
95
+ else {
96
+ setRect(emptyRect());
97
+ }
98
+ }, [selectedVariantName]);
99
+
100
+ const getPictureFieldValue = async (
101
+ field: Field,
102
+ rawValue: PictureRawValue
103
+ ): Promise<PictureValue | null> => {
104
+ if (!editContext?.pageView.site) return null;
105
+
106
+ return getPictureValue(
107
+ field,
108
+ rawValue,
109
+ editContext.pageView.site?.name,
110
+ editContext.sessionId
111
+ );
112
+ };
113
+
114
+ const imageSelected = useCallback(
115
+ async (
116
+ imageId: string,
117
+ variantName?: string,
118
+ rawValue?: PictureRawValue
119
+ ) => {
120
+ if (!variantName || !rawValue) return;
121
+
122
+ const selected = rawValue.Variants?.find((x) => x.Name == variantName);
123
+ if (!selected) {
124
+ if (!rawValue.Variants) rawValue.Variants = [];
125
+ rawValue.Variants.push({
126
+ Name: variantName,
127
+ MediaId: imageId,
128
+ });
129
+ } else {
130
+ selected.MediaId = imageId;
131
+ }
132
+ setRawValue(rawValue);
133
+ const newValue = await getPictureFieldValue(field, rawValue);
134
+ if (newValue) {
135
+ setPictureValue(newValue);
136
+ }
137
+ },
138
+ []
139
+ );
140
+ const updateRawValue = async (rawValue: PictureRawValue) => {
141
+ setRawValue(rawValue);
142
+ const newValue = await getPictureFieldValue(field, rawValue);
143
+ if (newValue) {
144
+ setPictureValue(newValue);
145
+ }
146
+ };
147
+
148
+ const setVariantCrop = async () => {
149
+ if (!rawValue) return;
150
+ if (!selectedVariantName) return;
151
+
152
+ if (selectedVariant) {
153
+ let selected = rawValue.Variants?.find(
154
+ (x: PictureRawVariant) => x.Name == selectedVariantName
155
+ );
156
+ if (!selected) {
157
+ selected = {
158
+ Name: selectedVariantName,
159
+ MediaId: selectedVariant.mediaId!,
160
+ };
161
+ rawValue.Variants?.push(selected);
162
+ }
163
+ if (selected) {
164
+ selected.Region = {
165
+ X: rect.left,
166
+ Y: rect.top,
167
+ Width: rect.width,
168
+ Height: rect.height,
169
+ };
170
+ await updateRawValue(rawValue);
171
+ }
172
+ }
173
+ };
174
+
175
+ const usage = getUsage(pictureValue, params);
176
+
177
+ return (
178
+ <>
179
+ <Dialog
180
+ header={"Edit " + field.name}
181
+ visible={true}
182
+ style={{ width: "70vw", height: "70vh" }}
183
+ onHide={onCancel}
184
+ >
185
+ <div className="flex gap-1 flex-col justify h-full">
186
+ <div className="flex-1 flex gap-2">
187
+ <div className=" h-full border-r pt-3 w-48 relative">
188
+ <div className="absolute inset-0 overflow-y-auto flex flex-col gap-6">
189
+ {pictureValue &&
190
+ pictureValue.variants?.map((variant) => (
191
+ <div
192
+ key={variant.name}
193
+ onClick={() => setSelectedVariantName(variant.name)}
194
+ className="text-xs flex flex-col items-center justify-center gap-1 cursor-pointer"
195
+ >
196
+ <div
197
+ className={
198
+ "flex justify-center items-center h-40 w-40 border relative" +
199
+ (selectedVariantName == variant.name
200
+ ? " shadow-xl "
201
+ : "")
202
+ }
203
+ >
204
+ {variant.src && <img src={variant.thumbSrc} />}
205
+ </div>
206
+ <div className="w-40">
207
+ <div>{variant.name}</div>
208
+ <div>{variant.aspectRatioLockText}</div>
209
+ <div>
210
+ <div className="break-all">
211
+ Name: {variant.mediaItemName}
212
+ </div>
213
+ <div>
214
+ Orig. size: {variant.width} x {variant.height}
215
+ </div>
216
+ {(variant.width < 1 || variant.height < 1) && (
217
+ <span>
218
+ {" "}
219
+ <i className="pi pi-exclamation-triangle text-red-600 "></i>
220
+ </span>
221
+ )}
222
+ </div>
223
+ </div>
224
+ </div>
225
+ ))}
226
+ </div>
227
+ {usage && <div className="text-xs">{usage}</div>}
228
+ </div>
229
+ <div className="flex-1 relative p-3">
230
+ <div className="absolute inset-0 top-3 overflow-auto select-none flex align-center justify-center">
231
+ {selectedVariant && (
232
+ <div
233
+ className="relative"
234
+ onDoubleClick={() => selectMedia()}
235
+ onMouseDown={(ev) => {
236
+ ev.preventDefault();
237
+ ev.stopPropagation();
238
+ const bounds = ev.currentTarget.getBoundingClientRect();
239
+
240
+ setRect({
241
+ left: (ev.clientX - bounds.left) / bounds.width,
242
+ top: (ev.clientY - bounds.top) / bounds.height,
243
+ width: 0,
244
+ height: 0,
245
+ });
246
+ }}
247
+ onMouseMoveCapture={(ev) => {
248
+ if (ev.buttons === 1) {
249
+ const bounds = ev.currentTarget.getBoundingClientRect();
250
+
251
+ const width =
252
+ (ev.clientX - bounds.left) / bounds.width - rect.left;
253
+
254
+ const newRect = {
255
+ ...rect,
256
+ width,
257
+ height: selectedVariant.aspectRatioLock
258
+ ? width / selectedVariant.aspectRatioLock
259
+ : (ev.clientY - bounds.top) / bounds.height -
260
+ rect.top,
261
+ };
262
+
263
+ setRect(newRect);
264
+ ev.preventDefault();
265
+ ev.stopPropagation();
266
+ }
267
+ }}
268
+ onMouseUp={() => setVariantCrop()}
269
+ >
270
+ <img
271
+ src={selectedVariant.originalSrc ?? selectedVariant.src}
272
+ className="object-contain h-full w-full"
273
+ />
274
+ <div
275
+ className="absolute bg-opacity-70 bg-gray-300"
276
+ style={{
277
+ left: rect.left * 100 + "%",
278
+ top: rect.top * 100 + "%",
279
+ width: rect.width * 100 + "%",
280
+ height: rect.height * 100 + "%",
281
+ }}
282
+ />
283
+ </div>
284
+ )}
285
+ {selectedVariant && (
286
+ <div
287
+ className="absolute top-0 right-0 cursor-pointer text-sm flex flex-col gap-1 items-center p-2 bg-gray-100 bg-opacity-70"
288
+ onClick={() => selectMedia()}
289
+ >
290
+ <i className="pi pi-pencil text-xl"></i>
291
+ Choose
292
+ </div>
293
+ )}
294
+ </div>
295
+ </div>
296
+ </div>
297
+ <DialogButtons>
298
+ <Button
299
+ size="small"
300
+ onClick={() => {
301
+ if (pictureValue) {
302
+ if (field) {
303
+ editContext?.operations.editField({
304
+ field: field.descriptor,
305
+ rawValue: JSON.stringify(rawValue),
306
+ refresh: "immediate",
307
+ });
308
+ }
309
+ onOk(pictureValue);
310
+ }
311
+ }}
312
+ >
313
+ Ok
314
+ </Button>
315
+ <Button
316
+ onClick={() => {
317
+ onCancel();
318
+ }}
319
+ size="small"
320
+ >
321
+ Cancel
322
+ </Button>
323
+ </DialogButtons>
324
+ </div>
325
+ </Dialog>
326
+ </>
327
+ );
328
+ }
329
+ function getUsage(
330
+ pictureValue: PictureValue | undefined,
331
+ params: PictureParams | MediaPictureParams | undefined
332
+ ) {
333
+ if (!params) return;
334
+ if (!pictureValue) return;
335
+ if (pictureValue.variants.length <= 1) return;
336
+ const mediaParams =
337
+ typeof params === "object" && "default" in params ? params : undefined;
338
+
339
+ if (mediaParams) {
340
+ const sources = Object.keys(mediaParams ?? {});
341
+ const variants = sources
342
+ .map((source) => ({
343
+ source,
344
+ variant: getRenderedPictureVariant(
345
+ mediaParams[source],
346
+ pictureValue.variants
347
+ ),
348
+ }))
349
+ .filter((x) => x.variant);
350
+
351
+ return (
352
+ <>
353
+ This field rendering is using these variants:
354
+ <table>
355
+ {variants.map((v) => (
356
+ <tr>
357
+ <td>{v.source}</td>
358
+ <td>
359
+ <b>{v.variant.name}</b>
360
+ </td>
361
+ </tr>
362
+ ))}
363
+ </table>
364
+ </>
365
+ );
366
+ }
367
+ return (
368
+ <>
369
+ This field rendering is using the variant{" "}
370
+ <b>
371
+ {
372
+ getRenderedPictureVariant(
373
+ params as PictureParams,
374
+ pictureValue.variants
375
+ )?.name
376
+ }
377
+ .
378
+ </b>
379
+ </>
380
+ );
381
+ }