@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.
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,61 @@
1
+ import { useEditContext } from "../client/editContext";
2
+ import { findFieldElement } from "../utils";
3
+ import { EditSession } from "../../types";
4
+
5
+ export function LockedFieldIndicator() {
6
+ const editContext = useEditContext();
7
+ if (!editContext) return;
8
+
9
+ const sessionsWithFieldLock = editContext.activeSessions.filter(
10
+ (x) => x.fieldLock && x.sessionId !== editContext.sessionId
11
+ );
12
+
13
+ return (
14
+ <>
15
+ {sessionsWithFieldLock.map((session) => {
16
+ if (!session.fieldLock) return;
17
+ const iframe = editContext.pageView.editorIframeRef.current;
18
+ if (!iframe) return;
19
+ const element = findFieldElement(iframe, session.fieldLock);
20
+ if (!element) return;
21
+
22
+ return (
23
+ <FieldLock
24
+ key={session.sessionId}
25
+ element={element}
26
+ iframe={iframe}
27
+ session={session}
28
+ />
29
+ );
30
+ })}
31
+ </>
32
+ );
33
+ }
34
+ function FieldLock({
35
+ element,
36
+ iframe,
37
+ session,
38
+ }: {
39
+ session: EditSession;
40
+ element: Element;
41
+ iframe: HTMLIFrameElement;
42
+ }) {
43
+ const rect = element.getBoundingClientRect();
44
+ const editorRect = iframe.getBoundingClientRect();
45
+
46
+ if (rect && editorRect) {
47
+ return (
48
+ <div
49
+ className="absolute text-xs text-white p-0.5 rounded hover:opacity-100 opacity-90"
50
+ style={{
51
+ left: rect.left + "px",
52
+ top: rect.top + "px",
53
+ background: session.color,
54
+ }}
55
+ >
56
+ {session.user.name}
57
+ </div>
58
+ );
59
+ }
60
+ return null;
61
+ }
@@ -0,0 +1,36 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import { FullItem } from "../pageModel";
4
+ import { useEditContext } from "../client/editContext";
5
+
6
+ export function NoLayout() {
7
+ const [lastPageItem, setLastPageItem] = useState<FullItem | null>(null);
8
+ const editContext = useEditContext();
9
+
10
+ useEffect(() => {
11
+ const updateLastPage = async () => {
12
+ if (!editContext?.pageView.pageItemDescriptor) return;
13
+
14
+ const lastPage = await editContext.itemsRepository.getItem(
15
+ editContext.pageView.pageItemDescriptor
16
+ );
17
+
18
+ if (lastPage) setLastPageItem(lastPage);
19
+ };
20
+
21
+ updateLastPage();
22
+ }, [editContext?.currentItemDescriptor]);
23
+ return (
24
+ <div className="h-full w-full flex flex-col items-center justify-center text-sm">
25
+ Item has no layout.
26
+ {lastPageItem && (
27
+ <div
28
+ className="cursor-pointer hover:underline p-2"
29
+ onClick={() => editContext?.loadItem(lastPageItem.descriptor)}
30
+ >
31
+ Load {lastPageItem?.name}?
32
+ </div>
33
+ )}
34
+ </div>
35
+ );
36
+ }
@@ -0,0 +1,122 @@
1
+ import { useEditContext, EditorMode } from "../client/editContext";
2
+ import { PageViewContext } from "../page-viewer/pageViewContext";
3
+ import { InlineEditor } from "./InlineEditor";
4
+ import { FieldActionsIndicators } from "./FieldActionIndicators";
5
+ import { PlaceholderDropZones } from "./PlaceholderDropZones";
6
+ import { PictureEditorOverlay } from "./PictureEditorOverlay";
7
+ import { useEffect, useState } from "react";
8
+ import { LockedFieldIndicator } from "./LockedFieldIndicator";
9
+ import { FrameMenus } from "./FrameMenus";
10
+ import { FieldEditedIndicators } from "./FieldEditedIndicators";
11
+ import { CommentHighlightings } from "./CommentHighlightings";
12
+ import { SuggestionHighlightings } from "./SuggestionHighlightings";
13
+ export function PageEditorChrome({
14
+ iframe,
15
+ compareView,
16
+ pageViewContext,
17
+ }: {
18
+ iframe: HTMLIFrameElement;
19
+ compareView: boolean;
20
+ pageViewContext: PageViewContext;
21
+ }) {
22
+ const editContext = useEditContext();
23
+ const [insertingStyle, setInsertingStyle] = useState<React.CSSProperties>();
24
+
25
+ if (!editContext?.pageView || !iframe?.contentDocument) return null;
26
+
27
+ useEffect(() => {
28
+ if (!editContext.inserting) setInsertingStyle(undefined);
29
+ let insertingPosition: { y: number; x: number } | undefined;
30
+ const insertingRect = editContext.inserting
31
+ ? editContext.inserting.positionElement.getBoundingClientRect()
32
+ : null;
33
+
34
+ if (insertingRect) {
35
+ if (editContext.inserting?.positionAnchor === "top")
36
+ insertingPosition = {
37
+ y: insertingRect.y,
38
+ x: insertingRect.x + insertingRect.width / 2,
39
+ };
40
+ if (editContext.inserting?.positionAnchor === "bottom")
41
+ insertingPosition = {
42
+ y: insertingRect.y + insertingRect.height,
43
+ x: insertingRect.x + insertingRect.width / 2,
44
+ };
45
+ if (editContext.inserting?.positionAnchor === "left")
46
+ insertingPosition = {
47
+ y: insertingRect.y + insertingRect.height / 2,
48
+ x: insertingRect.x,
49
+ };
50
+ if (editContext.inserting?.positionAnchor === "right")
51
+ insertingPosition = {
52
+ y: insertingRect.y + insertingRect.height / 2,
53
+ x: insertingRect.x + insertingRect.width,
54
+ };
55
+ }
56
+
57
+ const getInsertingStyle = () => {
58
+ if (!insertingPosition) return;
59
+ const scale = pageViewContext.zoom;
60
+ const x = Math.min(
61
+ pageViewContext.viewport.width - 20,
62
+ Math.max(20, insertingPosition.x * (scale || 1)),
63
+ );
64
+ const y = Math.min(
65
+ pageViewContext.viewport.height - 20,
66
+ Math.max(20, insertingPosition.y * (scale || 1)),
67
+ );
68
+
69
+ return {
70
+ top: y - 16 + "px",
71
+ left: x - 16 + "px",
72
+ zIndex: 1000,
73
+ };
74
+ };
75
+
76
+ const insertingStyle = getInsertingStyle();
77
+ setInsertingStyle(insertingStyle);
78
+ }, [editContext.inserting, pageViewContext.viewport]);
79
+
80
+ return (
81
+ <>
82
+ <FrameMenus pageViewContext={pageViewContext} compareView={compareView} />
83
+ <InlineEditor
84
+ pageViewContext={pageViewContext}
85
+ compareView={compareView}
86
+ />
87
+ <LockedFieldIndicator />
88
+ <FieldActionsIndicators />
89
+ {editContext.showComments && (
90
+ <CommentHighlightings
91
+ iframe={pageViewContext?.editorIframeRef.current!}
92
+ scale={1}
93
+ />
94
+ )}
95
+ {editContext.showSuggestedEdits && (
96
+ <SuggestionHighlightings
97
+ iframe={pageViewContext?.editorIframeRef.current!}
98
+ scale={1}
99
+ />
100
+ )}
101
+
102
+ <FieldEditedIndicators pageViewContext={pageViewContext} />
103
+
104
+ {editContext.mode === "edit" && (
105
+ <>
106
+ <PlaceholderDropZones
107
+ iframe={pageViewContext?.editorIframeRef.current}
108
+ size="large"
109
+ />
110
+ <PictureEditorOverlay />
111
+
112
+ {insertingStyle && (
113
+ <div className="absolute flex h-8 w-8" style={insertingStyle}>
114
+ <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-sky-400 opacity-75"></span>
115
+ <span className="relative inline-flex h-8 w-8 rounded-full bg-sky-500"></span>
116
+ </div>
117
+ )}
118
+ </>
119
+ )}
120
+ </>
121
+ );
122
+ }
@@ -0,0 +1,161 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { useEditContext } from "../client/editContext";
3
+
4
+ import { PictureEditor } from "../PictureEditor";
5
+ import { getComponentById } from "../componentTreeHelper";
6
+ import { PictureField } from "../fieldTypes";
7
+
8
+ export function PictureEditorOverlay() {
9
+ const editContext = useEditContext();
10
+
11
+ const pageViewContext = editContext?.pageView;
12
+ const iframe = pageViewContext?.editorIframeRef.current;
13
+
14
+ const [field, setField] = useState<PictureField>();
15
+ const [variantName, setVariantName] = useState<string>();
16
+ const [element, setElement] = useState<HTMLElement>();
17
+ const editContextRef = useRef(editContext);
18
+
19
+ useEffect(() => {
20
+ editContextRef.current = editContext;
21
+ }, [editContext]);
22
+
23
+ const onMouseEnter = useCallback(
24
+ (e: MouseEvent) => {
25
+ if (!e.target) return;
26
+
27
+ if (!("closest" in e.target)) return;
28
+
29
+ const target = e.target as HTMLElement;
30
+
31
+ const pictureElement = target.closest("picture") || target.closest("img");
32
+
33
+ setElement(pictureElement || undefined);
34
+ },
35
+ [iframe, editContext],
36
+ );
37
+
38
+ useEffect(() => {
39
+ const loadField = async () => {
40
+ if (element) {
41
+ const itemId = element.getAttribute("data-itemid");
42
+ const language = element.getAttribute("data-language");
43
+ const version = element.getAttribute("data-version");
44
+ const fieldId = element.getAttribute("data-fieldid");
45
+
46
+ if (
47
+ !itemId ||
48
+ !language ||
49
+ !version ||
50
+ !fieldId ||
51
+ !pageViewContext?.page ||
52
+ !iframe?.contentWindow
53
+ )
54
+ return;
55
+
56
+ const component = getComponentById(itemId, pageViewContext.page!);
57
+
58
+ if (component == null) return;
59
+
60
+ const item = await editContext!.itemsRepository.getItem(
61
+ component.datasourceItem!,
62
+ );
63
+
64
+ const pictureField = item?.fields.find(
65
+ (f) => f.id === fieldId,
66
+ ) as PictureField;
67
+
68
+ if (!pictureField) return;
69
+
70
+ setField(pictureField);
71
+ } else {
72
+ setField(undefined);
73
+ }
74
+ };
75
+ loadField();
76
+ }, [element, pageViewContext?.page]);
77
+
78
+ useEffect(() => {
79
+ if (!element || !iframe?.contentWindow) return;
80
+
81
+ const sourceELement = getCurrentPictureSource(
82
+ element,
83
+ iframe.contentWindow,
84
+ );
85
+
86
+ if (sourceELement) {
87
+ const variantName = sourceELement.getAttribute("data-variant");
88
+
89
+ if (variantName) {
90
+ setVariantName(variantName);
91
+ }
92
+ }
93
+ }, [pageViewContext?.viewport, element]);
94
+
95
+ const handleLoad = () => {
96
+ if (iframe?.contentDocument) {
97
+ iframe.contentDocument.addEventListener("mouseenter", onMouseEnter, true);
98
+ }
99
+ };
100
+
101
+ useEffect(() => {
102
+ if (iframe) {
103
+ // Ensure the iframe is loaded and accessible
104
+ iframe.addEventListener("load", handleLoad);
105
+
106
+ return () => {
107
+ if (iframe?.contentDocument) {
108
+ iframe?.contentDocument.removeEventListener(
109
+ "mouseenter",
110
+ onMouseEnter,
111
+ );
112
+ }
113
+
114
+ if (iframe) {
115
+ iframe.removeEventListener("load", handleLoad);
116
+ }
117
+ };
118
+ }
119
+ }, [iframe, editContext?.refreshCompletedFlag]);
120
+
121
+ if (!field || !variantName || !element) return null;
122
+
123
+ const bounds = element.getBoundingClientRect();
124
+
125
+ const style = {
126
+ left: bounds.x + "px",
127
+ top: bounds.y + "px",
128
+ width: bounds.width + "px",
129
+ height: bounds.height + "px",
130
+ };
131
+
132
+ return (
133
+ <PictureEditor
134
+ field={field}
135
+ variantName={variantName}
136
+ style={style}
137
+ forwardScrollevents={true}
138
+ isPageEditor={true}
139
+ />
140
+ );
141
+ }
142
+
143
+ function getCurrentPictureSource(
144
+ pictureElement: HTMLElement,
145
+ iframeWindow: Window,
146
+ ): HTMLElement | null {
147
+ if (pictureElement.tagName === "IMG") return pictureElement;
148
+
149
+ const sources = pictureElement.querySelectorAll("source");
150
+ let currentSrc: HTMLSourceElement | null = null;
151
+
152
+ sources.forEach((source) => {
153
+ const media = source.getAttribute("media");
154
+ if (!media) return;
155
+ if (media && iframeWindow.matchMedia(media).matches) {
156
+ currentSrc = source;
157
+ }
158
+ });
159
+
160
+ return currentSrc || pictureElement.querySelector("img") || null;
161
+ }
@@ -0,0 +1,169 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { useEditContext } from "../client/editContext";
5
+ import { classNames } from "primereact/utils";
6
+ import { MenuItem } from "primereact/menuitem";
7
+
8
+ import { getAbsoluteIconUrl } from "../utils";
9
+ import { Placeholder } from "../pageModel";
10
+
11
+ export function PlaceholderDropZone({
12
+ placeholder,
13
+ description,
14
+ index,
15
+ parentName,
16
+ spotPosition,
17
+ spotPositionElement,
18
+ spotPositionAnchor,
19
+ size,
20
+ }: {
21
+ placeholder: Placeholder;
22
+ description?: string;
23
+ index: number;
24
+ parentName?: string;
25
+ spotPosition: { x: number; y: number };
26
+ spotPositionElement: Element;
27
+ size: "large" | "small";
28
+ spotPositionAnchor: "top" | "bottom" | "left" | "right";
29
+ }) {
30
+ const [isHovering, setIsHovering] = useState(false);
31
+
32
+ const editContext = useEditContext();
33
+ if (!editContext) return;
34
+
35
+ function dragOver(ev: any) {
36
+ ev.dataTransfer.dropEffect =
37
+ editContext?.dragObject?.type == "template" ? "copy" : "move";
38
+ setIsHovering(true);
39
+ ev.preventDefault();
40
+ }
41
+
42
+ function drop(ev: any) {
43
+ ev.preventDefault();
44
+ setIsHovering(false);
45
+ editContext!.setStatusMessage("");
46
+ editContext!.droppedInPlaceholder(
47
+ placeholder.key,
48
+ index,
49
+ spotPositionElement,
50
+ spotPositionAnchor,
51
+ );
52
+ }
53
+
54
+ const overlayStyle = {
55
+ top: spotPosition.y,
56
+ left: spotPosition.x,
57
+ zIndex: isHovering ? 40 : 30,
58
+ transform: "none",
59
+ };
60
+
61
+ if (size === "small") overlayStyle.transform = "scale(0.5)";
62
+
63
+ useEffect(() => {
64
+ if (isHovering) {
65
+ editContext.setStatusMessage(
66
+ <div>
67
+ Drop into placeholder <span className="font-bold">{parentName}</span>{" "}
68
+ / <span className="font-bold">{description || placeholder.name}</span>{" "}
69
+ at position <span className="font-bold">{index + 1}</span>
70
+ </div>,
71
+ );
72
+ } else {
73
+ editContext.setStatusMessage("");
74
+ }
75
+ }, [isHovering]);
76
+
77
+ return (
78
+ <div className="absolute" style={overlayStyle}>
79
+ <div
80
+ onDragOver={dragOver}
81
+ title={(description ?? placeholder.name) + " (" + index + ")"}
82
+ data-testid="placeholder-dropzone"
83
+ data-testindex={index}
84
+ onDrop={drop}
85
+ onDragLeave={() => setIsHovering(false)}
86
+ onClick={(e) => {
87
+ //const placeholderKeyComponents = placeholder.key.split("_");
88
+ // const parentId =
89
+ // placeholderKeyComponents.length === 1
90
+ // ? undefined
91
+ // : placeholderKeyComponents[0];
92
+ const insertOption = placeholder.insertOptions.find(
93
+ (x) => x.typeId === editContext.selectedForInsertion,
94
+ );
95
+ if (insertOption) {
96
+ editContext!.droppedInPlaceholder(
97
+ placeholder.key,
98
+ index,
99
+ spotPositionElement,
100
+ spotPositionAnchor,
101
+ insertOption,
102
+ );
103
+
104
+ return;
105
+ }
106
+ const insertOptions =
107
+ placeholder.insertOptions
108
+ ?.filter((x) => !x.isHidden && !x.isInvalid)
109
+ .map((x) => ({
110
+ id: x.typeId,
111
+ icon: (
112
+ <img
113
+ src={getAbsoluteIconUrl(x.icon)}
114
+ width="16"
115
+ height="16"
116
+ className="m-1"
117
+ />
118
+ ),
119
+ label: x.name,
120
+ command: () => {
121
+ editContext.operations.addComponent(
122
+ x.typeId,
123
+ placeholder.key,
124
+ index,
125
+ editContext.currentItemDescriptor!,
126
+ );
127
+ },
128
+ })) || ([] as MenuItem[]);
129
+
130
+ if (insertOptions.length > 0)
131
+ editContext.showContextMenu(e, [
132
+ {
133
+ label: "Insert",
134
+ disabled: true,
135
+ className: "border-b border-gray-400 pb-2 pl-2",
136
+ template: () => {
137
+ return <span className="text-sm text-black">Insert</span>;
138
+ },
139
+ },
140
+ ...insertOptions,
141
+ ]);
142
+ e.preventDefault();
143
+ }}
144
+ className="placeholder placeholder-dropzone cursor-pointer"
145
+ >
146
+ <div
147
+ className={classNames(
148
+ isHovering
149
+ ? "z-30 h-20 w-20 shadow-xl shadow-black shadow-blue-500/50"
150
+ : "z-30 h-10 w-10 hover:scale-[1.1]",
151
+ "test-ph-dropzone tour-placeholder-dropzone absolute top-1/2 left-1/2 flex -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-blue-500 p-2 text-center text-sm text-white opacity-100 transition-all duration-300 ease-in-out",
152
+ )}
153
+ data-testid="placeholder-dropzone-button"
154
+ >
155
+ <i className="pi pi-plus block" />
156
+ {/* {isHovering && (
157
+ <div className="flex flex-col items-center">
158
+ {parentName}{" "}
159
+ <div className="text-xs text-gray-500">
160
+ ({description || placeholder.key} {index})
161
+ </div>
162
+ </div>
163
+ )} */}
164
+ </div>
165
+ </div>
166
+ </div>
167
+ // </div>
168
+ );
169
+ }