@alpaca-editor/core 1.0.3941 → 1.0.3943

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,315 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useEditContext } from "../client/editContext";
3
+
4
+ import { getAllPlaceholders } from "../componentTreeHelper";
5
+ import { findComponentRect } from "../utils";
6
+ import { PlaceholderDropZone } from "./PlaceholderDropZone";
7
+ import { Placeholder, Component } from "../pageModel";
8
+
9
+ export function PlaceholderDropZones({
10
+ scale,
11
+ iframe,
12
+ size,
13
+ }: {
14
+ scale?: number;
15
+ iframe?: HTMLIFrameElement | null;
16
+ size: "large" | "small";
17
+ }) {
18
+ const [placeholders, setPlaceholders] = useState<Placeholder[]>([]);
19
+ const editContext = useEditContext();
20
+ const pageViewContext = editContext?.pageView;
21
+
22
+ useEffect(() => {
23
+ if (!pageViewContext?.page) return;
24
+ setPlaceholders(getAllPlaceholders(pageViewContext.page!));
25
+ }, [pageViewContext?.page]);
26
+
27
+ if (
28
+ !pageViewContext ||
29
+ (!editContext?.dragObject && !editContext.selectedForInsertion) ||
30
+ !placeholders
31
+ )
32
+ return null;
33
+
34
+ const matchingPlaceholders = placeholders.filter(
35
+ (x) =>
36
+ x.parentComponent?.id === editContext.selectedForInsertion ||
37
+ x.insertOptions?.find(
38
+ (y) =>
39
+ y.typeId === editContext.selectedForInsertion ||
40
+ y.typeId === editContext.dragObject?.typeId ||
41
+ y.typeId === editContext.dragObject?.templateId ||
42
+ y.compatibleTypeIds?.find(
43
+ (z) => z == editContext.dragObject?.typeId,
44
+ ) !== undefined ||
45
+ y.typeId === editContext.dragObject?.templateId ||
46
+ y.compatibleTypeIds?.find(
47
+ (z) => z == editContext.dragObject?.templateId,
48
+ ) !== undefined,
49
+ ),
50
+ );
51
+
52
+ if (!iframe) return;
53
+
54
+ const zones: {
55
+ placeholder: Placeholder;
56
+ position: { x: number; y: number };
57
+ index: number;
58
+ element: Element;
59
+ anchor: "top" | "bottom" | "left" | "right";
60
+ description?: string | null;
61
+ }[] = [];
62
+
63
+ const scrollHeight =
64
+ editContext.pageView.editorIframeRef?.current?.contentWindow?.document
65
+ .documentElement.scrollHeight || 0;
66
+
67
+ matchingPlaceholders.forEach((placeholder) => {
68
+ let placeholderElement = iframe!.contentWindow?.document.body.querySelector(
69
+ "[data-placeholder-start='" + placeholder.key + "']",
70
+ );
71
+
72
+ if (!placeholderElement && placeholder.components.length > 0) {
73
+ placeholderElement = placeholder.components[0]?.firstDOMElement;
74
+ }
75
+
76
+ if (!placeholderElement) return;
77
+
78
+ const prev = getPreviousElement(placeholderElement);
79
+
80
+ const nextOrParent =
81
+ getNextElement(placeholderElement) || placeholderElement.parentElement;
82
+
83
+ let orientation = placeholderElement?.getAttribute("data-orientation");
84
+
85
+ if (!orientation)
86
+ orientation = detectOrientation(
87
+ placeholderElement,
88
+ placeholder.components,
89
+ );
90
+
91
+ const rect = (prev ?? nextOrParent)!.getBoundingClientRect();
92
+ const zoom = pageViewContext.zoom;
93
+
94
+ const position =
95
+ orientation === "horizontal"
96
+ ? {
97
+ x: (prev ? rect.x + rect.width : rect.x) * zoom,
98
+ y: (rect.y + rect.height / 2) * zoom,
99
+ }
100
+ : {
101
+ x: (rect.x + rect.width / 2) * zoom,
102
+ y: (prev ? rect.y + rect.height : rect.y) * zoom,
103
+ };
104
+
105
+ let index = 0;
106
+
107
+ const description = placeholderElement.getAttribute("data-description");
108
+
109
+ let anchor: "top" | "bottom" | "left" | "right" = "top";
110
+
111
+ if (prev && orientation === "horizontal") {
112
+ anchor = "right";
113
+ }
114
+ if (prev && orientation !== "horizontal") {
115
+ anchor = "bottom";
116
+ }
117
+ if (!prev && orientation === "horizontal") {
118
+ anchor = "left";
119
+ }
120
+ if (!prev && orientation !== "horizontal") {
121
+ anchor = "top";
122
+ }
123
+
124
+ zones.push({
125
+ placeholder,
126
+ position,
127
+ index,
128
+ element: prev ?? nextOrParent!,
129
+ anchor,
130
+ description,
131
+ });
132
+
133
+ placeholder.components.forEach((component) => {
134
+ const componentRect = findComponentRect(iframe, component);
135
+ if (!componentRect) return;
136
+
137
+ const position = getPositionFromRect(
138
+ componentRect.rect,
139
+ pageViewContext.zoom,
140
+ orientation,
141
+ );
142
+
143
+ index++;
144
+
145
+ zones.push({
146
+ placeholder,
147
+ position,
148
+ index,
149
+ anchor: orientation === "horizontal" ? "right" : "bottom",
150
+ element: componentRect.elements[componentRect.elements.length - 1]!,
151
+ });
152
+ });
153
+
154
+ // let nextElement = placeholderElement?.nextElementSibling;
155
+ // while (nextElement) {
156
+ // nextElement = nextElement?.nextElementSibling;
157
+ // if (nextElement) {
158
+ // if (
159
+ // nextElement.getAttribute("data-placeholder-end") === placeholder.key
160
+ // ) {
161
+ // break;
162
+ // }
163
+
164
+ // if (nextElement.getAttribute("data-component-end")) {
165
+ // const componentRect = findComponentRect(
166
+ // iframe,
167
+ // (nextElement.getAttribute("data-component-end") ||
168
+ // nextElement.getAttribute("data-dropzone"))!,
169
+ // );
170
+ // if (!componentRect) continue;
171
+ // const position = getPositionFromRect(
172
+ // componentRect.rect,
173
+ // pageViewContext.zoom,
174
+ // orientation,
175
+ // );
176
+ // index++;
177
+ // zones.push({
178
+ // placeholder,
179
+ // position,
180
+ // index,
181
+ // anchor: orientation === "horizontal" ? "right" : "bottom",
182
+ // element: componentRect.elements[componentRect.elements.length - 1]!,
183
+ // });
184
+ // } else if (nextElement.getAttribute("data-dropzone")) {
185
+ // const rect = nextElement.getBoundingClientRect();
186
+ // const position = getPositionFromRect(rect, pageViewContext.zoom);
187
+ // index++;
188
+ // zones.push({
189
+ // placeholder,
190
+ // position,
191
+ // index,
192
+ // anchor: orientation === "horizontal" ? "left" : "top",
193
+ // element: nextElement,
194
+ // });
195
+ // }
196
+ // }
197
+ // }
198
+ });
199
+
200
+ return zones.map((zone, index) => {
201
+ const x = Math.min(
202
+ pageViewContext.viewport.width - 20,
203
+ Math.max(20, zone.position.x * (scale || 1)),
204
+ );
205
+ const y = Math.min(
206
+ scrollHeight - 20,
207
+ Math.max(20 - pageViewContext.scroll, zone.position.y * (scale || 1)),
208
+ );
209
+
210
+ return (
211
+ <PlaceholderDropZone
212
+ key={index}
213
+ placeholder={zone.placeholder}
214
+ spotPosition={{
215
+ x,
216
+ y,
217
+ }}
218
+ index={zone.index}
219
+ size={size}
220
+ spotPositionElement={zone.element}
221
+ spotPositionAnchor={zone.anchor}
222
+ parentName={zone.placeholder.parentComponent?.name}
223
+ description={zone.description || undefined}
224
+ />
225
+ );
226
+ });
227
+ }
228
+
229
+ function getPreviousElement(element: Element): Element | null {
230
+ let prev = element.previousElementSibling;
231
+ while (prev && prev.tagName === "SCRIPT") {
232
+ prev = prev.previousElementSibling;
233
+ }
234
+ return prev;
235
+ }
236
+
237
+ function getNextElement(element: Element): Element | null {
238
+ let next = element.nextElementSibling;
239
+
240
+ while (next && next.tagName === "SCRIPT") {
241
+ next = next.nextElementSibling;
242
+ }
243
+ return next;
244
+ }
245
+
246
+ function getPositionFromRect(
247
+ rect: { x: number; y: number; width: number; height: number },
248
+ zoom: number,
249
+ orientation?: string | null,
250
+ ) {
251
+ const position =
252
+ orientation === "horizontal"
253
+ ? {
254
+ x: rect.x + rect.width * zoom,
255
+ y: (rect.y + rect.height / 2) * zoom,
256
+ }
257
+ : {
258
+ x: (rect.x + rect.width / 2) * zoom,
259
+ y: rect.y + rect.height * zoom,
260
+ };
261
+
262
+ return position;
263
+ }
264
+
265
+ function detectOrientation(
266
+ placeholderElement: Element,
267
+ components: Component[],
268
+ ): "horizontal" | "vertical" {
269
+ // Check parent element for flex/grid direction
270
+ const parentElement = placeholderElement.parentElement;
271
+ if (parentElement) {
272
+ const parentStyle = window.getComputedStyle(parentElement);
273
+ const display = parentStyle.getPropertyValue("display");
274
+
275
+ // Check for flex direction
276
+ if (display === "flex" || display === "inline-flex") {
277
+ const flexDirection = parentStyle.getPropertyValue("flex-direction");
278
+ if (flexDirection === "row" || "row-reverse") {
279
+ return "horizontal";
280
+ }
281
+ if (flexDirection === "column" || "column-reverse") {
282
+ return "vertical";
283
+ }
284
+ }
285
+
286
+ // Check for grid layout
287
+ if (display === "grid" || display === "inline-grid") {
288
+ const gridAutoFlow = parentStyle.getPropertyValue("grid-auto-flow");
289
+ if (gridAutoFlow.includes("column")) {
290
+ return "horizontal";
291
+ }
292
+ if (gridAutoFlow.includes("row")) {
293
+ return "vertical";
294
+ }
295
+ }
296
+ }
297
+
298
+ // Analyze sibling positions if available
299
+ if (components.length > 1) {
300
+ const prevRect = components[0]?.firstDOMElement?.getBoundingClientRect();
301
+ const nextRect = components[1]?.firstDOMElement?.getBoundingClientRect();
302
+
303
+ if (!prevRect || !nextRect) return "horizontal";
304
+
305
+ // Compare the position differences
306
+ const horizontalDiff = Math.abs(nextRect.x - prevRect.x);
307
+ const verticalDiff = Math.abs(nextRect.y - prevRect.y);
308
+
309
+ // If horizontal difference is greater, it's likely a horizontal layout
310
+ return horizontalDiff > verticalDiff ? "horizontal" : "vertical";
311
+ }
312
+
313
+ // Default to vertical if we can't determine
314
+ return "vertical";
315
+ }
@@ -0,0 +1,300 @@
1
+ import {
2
+ useEditContext,
3
+ useModifiedFieldsContext,
4
+ } from "../client/editContext";
5
+ import { findFieldElement } from "../utils";
6
+ import { SuggestedEdit } from "../../types";
7
+ import { useState } from "react";
8
+ import { useEffect } from "react";
9
+ import { classNames } from "primereact/utils";
10
+ import { UserRoundPen } from "lucide-react";
11
+ import * as DiffLib from "diff";
12
+
13
+ export function SuggestionHighlighting({
14
+ suggestion,
15
+ scale,
16
+ iframe,
17
+ }: {
18
+ suggestion: SuggestedEdit;
19
+ scale: number;
20
+ iframe: HTMLIFrameElement;
21
+ }) {
22
+ const editContext = useEditContext();
23
+ const modifiedFields = useModifiedFieldsContext();
24
+ const [ranges, setRanges] = useState<Array<[number, number]>>([]);
25
+ const [textContent, setTextContent] = useState<string>("");
26
+
27
+ useEffect(() => {
28
+ const findRanges = async () => {
29
+ if (!editContext) return;
30
+
31
+ const field = await editContext.itemsRepository.getField({
32
+ item: {
33
+ id: suggestion.itemId,
34
+ language: suggestion.mainItemLanguage,
35
+ version: suggestion.mainItemVersion,
36
+ },
37
+ fieldId: suggestion.fieldId,
38
+ });
39
+
40
+ const modifiedField = modifiedFields?.modifiedFields.find(
41
+ (x) =>
42
+ x.fieldId === field?.id &&
43
+ x.item.id === suggestion.itemId &&
44
+ x.item.language === suggestion.mainItemLanguage &&
45
+ x.item.version === suggestion.mainItemVersion,
46
+ );
47
+
48
+ // Calculate the actual differences between oldValue and newValue
49
+ const oldValue = suggestion.oldValue || field?.rawValue || "";
50
+ const newValue = modifiedField?.value || suggestion.newValue || "";
51
+
52
+ // If values are identical, no need to highlight
53
+ if (oldValue === newValue) {
54
+ setRanges([]);
55
+ return;
56
+ }
57
+
58
+ // Save oldValue for use in the component
59
+ setTextContent(oldValue);
60
+
61
+ // Use the diff library to find the changed parts - using diffChars for more precise matching
62
+ const diffResult = DiffLib.diffChars(oldValue, newValue);
63
+
64
+ const changeRanges: Array<[number, number]> = [];
65
+ let positionInOld = 0;
66
+
67
+ // Process the diff result to find all change ranges
68
+ for (const part of diffResult) {
69
+ if (part.removed) {
70
+ // If a part is removed, highlight it in the original text
71
+ changeRanges.push([positionInOld, positionInOld + part.value.length]);
72
+ positionInOld += part.value.length;
73
+ } else if (part.added) {
74
+ // For added parts, mark the insertion point
75
+ if (changeRanges.length > 0) {
76
+ const lastRange = changeRanges[changeRanges.length - 1];
77
+ if (lastRange && lastRange[1] === positionInOld) {
78
+ // If this addition comes right after a removal, the previous range already covers the position
79
+ continue;
80
+ }
81
+ }
82
+ // Mark the insertion point for new content
83
+ changeRanges.push([positionInOld, positionInOld]);
84
+ } else {
85
+ // Unchanged part, just advance the position
86
+ positionInOld += part.value.length;
87
+ }
88
+ }
89
+
90
+ // Merge adjacent or overlapping ranges
91
+ const mergedRanges: Array<[number, number]> = [];
92
+
93
+ if (changeRanges.length > 0) {
94
+ changeRanges.sort((a, b) => a[0] - b[0]);
95
+
96
+ // Start with the first range
97
+ const firstRange = changeRanges[0];
98
+ if (!firstRange) {
99
+ setRanges([]);
100
+ return;
101
+ }
102
+
103
+ let currentRange: [number, number] = [...firstRange];
104
+
105
+ // Process the rest of the ranges
106
+ for (let i = 1; i < changeRanges.length; i++) {
107
+ const nextRange = changeRanges[i];
108
+
109
+ // Skip undefined ranges
110
+ if (!nextRange) continue;
111
+
112
+ // If the next range starts very close to the end of the current range, merge them
113
+ if (nextRange[0] <= currentRange[1] + 3) {
114
+ // Allow slightly larger gaps (3 chars) for better highlighting
115
+ // Extend the current range
116
+ currentRange[1] = Math.max(currentRange[1], nextRange[1]);
117
+ } else {
118
+ // Save the current range and start a new one
119
+ mergedRanges.push([currentRange[0], currentRange[1]]);
120
+ currentRange = [...nextRange];
121
+ }
122
+ }
123
+
124
+ // Add the last range
125
+ mergedRanges.push([currentRange[0], currentRange[1]]);
126
+ }
127
+
128
+ // Set ranges to highlight the changed parts
129
+ setRanges(mergedRanges);
130
+ };
131
+
132
+ findRanges();
133
+ }, [editContext, modifiedFields?.modifiedFields, suggestion]);
134
+
135
+ if (!editContext) return null;
136
+
137
+ if (!suggestion.fieldId) return null;
138
+
139
+ const fieldElement = findFieldElement(iframe, {
140
+ item: {
141
+ id: suggestion.itemId,
142
+ language: suggestion.mainItemLanguage,
143
+ version: suggestion.mainItemVersion,
144
+ },
145
+ fieldId: suggestion.fieldId,
146
+ });
147
+
148
+ if (!fieldElement) return null;
149
+
150
+ // Process each range and collect all DOM rectangles
151
+ const allRects: Array<DOMRect> = [];
152
+
153
+ ranges.forEach((range) => {
154
+ if (range[0] !== undefined && range[1] !== undefined) {
155
+ // For insertion points (zero-length ranges), expand to include at least one character
156
+ // to make it visible
157
+ const start = range[0];
158
+ const end =
159
+ range[0] === range[1]
160
+ ? Math.min(range[0] + 1, textContent.length)
161
+ : range[1];
162
+
163
+ if (start < end) {
164
+ const startData = getTextNodeAtPosition(fieldElement, start);
165
+ const endData = getTextNodeAtPosition(fieldElement, end);
166
+
167
+ if (startData && endData) {
168
+ try {
169
+ const textRange = document.createRange();
170
+ textRange.setStart(startData.node, startData.offset);
171
+ textRange.setEnd(endData.node, endData.offset);
172
+
173
+ const rangeRects = textRange.getClientRects();
174
+ // Convert DOMRectList to Array
175
+ for (let i = 0; i < rangeRects.length; i++) {
176
+ const rect = rangeRects[i];
177
+ if (rect) {
178
+ allRects.push(rect);
179
+ }
180
+ }
181
+ } catch (e) {
182
+ console.error("Error creating range", e);
183
+ }
184
+ }
185
+ }
186
+ }
187
+ });
188
+
189
+ // If no rects were found, fall back to highlighting the entire field
190
+ if (allRects.length === 0 && ranges.length > 0) {
191
+ const fallbackRect = fieldElement.getBoundingClientRect();
192
+ allRects.push(fallbackRect);
193
+ }
194
+
195
+ const iframeRect = iframe.getBoundingClientRect();
196
+
197
+ return (
198
+ <>
199
+ {allRects.map((rect, index) => (
200
+ <div
201
+ key={index}
202
+ style={{
203
+ position: "absolute",
204
+ top: rect.top * scale,
205
+ left: rect.left * scale,
206
+ width: rect.width * scale,
207
+ height: rect.height * scale,
208
+ pointerEvents: "none",
209
+ }}
210
+ >
211
+ {index === 0 && (
212
+ <div
213
+ className={classNames(
214
+ "pointer-events-auto absolute h-5 w-5 cursor-pointer",
215
+ rect.top * scale < 18 ? "top-0" : "top-[-18px]",
216
+ (rect.left + rect.width) * scale > iframeRect.width - 18
217
+ ? "right-0"
218
+ : "right-[-18px]",
219
+ )}
220
+ onClick={() => {
221
+ editContext.select([suggestion.itemId]);
222
+ editContext.setFocusedField(
223
+ {
224
+ item: {
225
+ id: suggestion.itemId,
226
+ language: suggestion.mainItemLanguage,
227
+ version: suggestion.mainItemVersion,
228
+ },
229
+ fieldId: suggestion.fieldId,
230
+ },
231
+ true,
232
+ );
233
+ }}
234
+ >
235
+ <UserRoundPen
236
+ className="rounded-full bg-emerald-400/70 p-1 text-white"
237
+ size={20}
238
+ />
239
+ </div>
240
+ )}
241
+ {/* <div
242
+ className="bg-emerald-400/30"
243
+ style={{
244
+ width: "100%",
245
+ height: "100%",
246
+ }}
247
+ ></div> */}
248
+ </div>
249
+ ))}
250
+ </>
251
+ );
252
+ }
253
+
254
+ // Improved function to find text node at a given character position
255
+ function getTextNodeAtPosition(
256
+ root: Node,
257
+ targetOffset: number,
258
+ ): { node: Text; offset: number } | null {
259
+ // Handle edge cases
260
+ if (targetOffset < 0) return null;
261
+
262
+ // Get all text nodes in order
263
+ const textNodes: Text[] = [];
264
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
265
+
266
+ let node: Text | null;
267
+ while ((node = walker.nextNode() as Text | null)) {
268
+ if (node) textNodes.push(node);
269
+ }
270
+
271
+ let currentOffset = 0;
272
+ // Walk through all text nodes to find the one containing our target position
273
+ for (const node of textNodes) {
274
+ const nodeLength = node.textContent?.length || 0;
275
+
276
+ // If this node contains our target position
277
+ if (currentOffset + nodeLength >= targetOffset) {
278
+ return {
279
+ node: node,
280
+ offset: targetOffset - currentOffset,
281
+ };
282
+ }
283
+
284
+ currentOffset += nodeLength;
285
+ }
286
+
287
+ // If we've gone through all nodes and haven't found the position
288
+ // Return the last position in the last text node
289
+ if (textNodes.length > 0) {
290
+ const lastNode = textNodes[textNodes.length - 1];
291
+ if (lastNode) {
292
+ return {
293
+ node: lastNode,
294
+ offset: lastNode.textContent?.length || 0,
295
+ };
296
+ }
297
+ }
298
+
299
+ return null;
300
+ }
@@ -0,0 +1,40 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useEditContext } from "../client/editContext";
3
+
4
+ import { SuggestionHighlighting } from "./SuggestionHighlighting";
5
+
6
+ import { SuggestedEdit } from "../../types";
7
+
8
+ export function SuggestionHighlightings({
9
+ scale,
10
+ iframe,
11
+ }: {
12
+ scale: number;
13
+ iframe: HTMLIFrameElement;
14
+ }) {
15
+ const editContext = useEditContext();
16
+
17
+ const [suggestions, setSuggestions] = useState<SuggestedEdit[]>([]);
18
+
19
+ useEffect(() => {
20
+ setSuggestions(
21
+ editContext?.suggestedEdits.filter((x) => x.status === "Pending") || [],
22
+ );
23
+ }, [editContext?.comments, editContext?.suggestedEdits]);
24
+
25
+ return (
26
+ <>
27
+ {editContext?.showSuggestedEdits &&
28
+ suggestions
29
+ .filter((x) => x.status !== "approved" && x.status !== "rejected")
30
+ .map((suggestion) => (
31
+ <SuggestionHighlighting
32
+ iframe={iframe}
33
+ scale={scale}
34
+ key={suggestion.id}
35
+ suggestion={suggestion}
36
+ />
37
+ ))}
38
+ </>
39
+ );
40
+ }