@alpaca-editor/core 1.0.3938 → 1.0.3941

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 (357) hide show
  1. package/dist/components/ActionButton.d.ts +1 -0
  2. package/dist/components/ActionButton.js +2 -2
  3. package/dist/components/ActionButton.js.map +1 -1
  4. package/dist/editor/ContentTree.js +12 -8
  5. package/dist/editor/ContentTree.js.map +1 -1
  6. package/dist/editor/ContextMenu.d.ts +1 -1
  7. package/dist/editor/ContextMenu.js +17 -3
  8. package/dist/editor/ContextMenu.js.map +1 -1
  9. package/dist/editor/FieldActionsOverlay.d.ts +18 -0
  10. package/dist/editor/FieldActionsOverlay.js +139 -0
  11. package/dist/editor/FieldActionsOverlay.js.map +1 -0
  12. package/dist/editor/FieldHistory.d.ts +2 -1
  13. package/dist/editor/FieldHistory.js +11 -8
  14. package/dist/editor/FieldHistory.js.map +1 -1
  15. package/dist/editor/FieldListField.js +14 -17
  16. package/dist/editor/FieldListField.js.map +1 -1
  17. package/dist/editor/PictureCropper.js +65 -23
  18. package/dist/editor/PictureCropper.js.map +1 -1
  19. package/dist/editor/PictureEditor.js +43 -3
  20. package/dist/editor/PictureEditor.js.map +1 -1
  21. package/dist/editor/Titlebar.js +19 -10
  22. package/dist/editor/Titlebar.js.map +1 -1
  23. package/dist/editor/ai/AiTerminal.js +27 -41
  24. package/dist/editor/ai/AiTerminal.js.map +1 -1
  25. package/dist/editor/ai/GhostWriter.js +21 -2
  26. package/dist/editor/ai/GhostWriter.js.map +1 -1
  27. package/dist/editor/client/EditorClient.js +48 -18
  28. package/dist/editor/client/EditorClient.js.map +1 -1
  29. package/dist/editor/client/editContext.d.ts +1 -1
  30. package/dist/editor/client/editContext.js.map +1 -1
  31. package/dist/editor/client/itemsRepository.js +126 -90
  32. package/dist/editor/client/itemsRepository.js.map +1 -1
  33. package/dist/editor/commands/componentCommands.js +7 -3
  34. package/dist/editor/commands/componentCommands.js.map +1 -1
  35. package/dist/editor/media-selector/MediaFolderBrowser.d.ts +5 -0
  36. package/dist/editor/media-selector/MediaFolderBrowser.js +77 -0
  37. package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -0
  38. package/dist/editor/media-selector/MediaSelector.js +1 -1
  39. package/dist/editor/media-selector/MediaSelector.js.map +1 -1
  40. package/dist/editor/media-selector/Thumbnails.js +2 -2
  41. package/dist/editor/media-selector/index.d.ts +8 -0
  42. package/dist/editor/media-selector/index.js +9 -0
  43. package/dist/editor/media-selector/index.js.map +1 -0
  44. package/dist/editor/menubar/BrowseHistory.js +3 -4
  45. package/dist/editor/menubar/BrowseHistory.js.map +1 -1
  46. package/dist/editor/menubar/PageSelector.js +62 -10
  47. package/dist/editor/menubar/PageSelector.js.map +1 -1
  48. package/dist/editor/page-editor-chrome/FieldActionIndicator.js +1 -1
  49. package/dist/editor/page-editor-chrome/FieldActionIndicator.js.map +1 -1
  50. package/dist/editor/page-editor-chrome/useInlineAICompletion.js +37 -11
  51. package/dist/editor/page-editor-chrome/useInlineAICompletion.js.map +1 -1
  52. package/dist/editor/page-viewer/PageViewerFrame.js +98 -2
  53. package/dist/editor/page-viewer/PageViewerFrame.js.map +1 -1
  54. package/dist/editor/pageModel.d.ts +14 -0
  55. package/dist/editor/reviews/Comment.js +3 -2
  56. package/dist/editor/reviews/Comment.js.map +1 -1
  57. package/dist/editor/services/aiService.js +0 -1
  58. package/dist/editor/services/aiService.js.map +1 -1
  59. package/dist/editor/services/editService.d.ts +1 -1
  60. package/dist/editor/services/editService.js +2 -1
  61. package/dist/editor/services/editService.js.map +1 -1
  62. package/dist/editor/sidebar/ComponentTree.js +3 -4
  63. package/dist/editor/sidebar/ComponentTree.js.map +1 -1
  64. package/dist/editor/ui/Icons.js +1 -1
  65. package/dist/editor/ui/Icons.js.map +1 -1
  66. package/dist/editor/ui/ItemList.d.ts +16 -0
  67. package/dist/editor/ui/ItemList.js +19 -0
  68. package/dist/editor/ui/ItemList.js.map +1 -0
  69. package/dist/editor/ui/ItemSearch.js +2 -12
  70. package/dist/editor/ui/ItemSearch.js.map +1 -1
  71. package/dist/editor/ui/SimpleTabs.d.ts +1 -0
  72. package/dist/editor/ui/SimpleTabs.js +3 -3
  73. package/dist/editor/ui/SimpleTabs.js.map +1 -1
  74. package/dist/editor/ui/Splitter.js +61 -6
  75. package/dist/editor/ui/Splitter.js.map +1 -1
  76. package/dist/editor/views/MediaFolderEditView.d.ts +4 -0
  77. package/dist/editor/views/MediaFolderEditView.js +40 -0
  78. package/dist/editor/views/MediaFolderEditView.js.map +1 -0
  79. package/dist/editor/views/SingleEditView.js +9 -1
  80. package/dist/editor/views/SingleEditView.js.map +1 -1
  81. package/dist/revision.d.ts +2 -2
  82. package/dist/revision.js +2 -2
  83. package/dist/styles.css +64 -13
  84. package/package.json +8 -2
  85. package/.prettierrc +0 -3
  86. package/build.css +0 -3
  87. package/components.json +0 -21
  88. package/eslint.config.mjs +0 -4
  89. package/images/bg-shape-black.webp +0 -0
  90. package/images/wizard-bg.png +0 -0
  91. package/images/wizard-tour.png +0 -0
  92. package/images/wizard.png +0 -0
  93. package/src/client-components/api.ts +0 -6
  94. package/src/client-components/index.ts +0 -19
  95. package/src/components/ActionButton.tsx +0 -41
  96. package/src/components/Error.tsx +0 -57
  97. package/src/components/ui/CardConnector.tsx +0 -56
  98. package/src/components/ui/button.tsx +0 -62
  99. package/src/components/ui/card.tsx +0 -372
  100. package/src/components/ui/context-menu.tsx +0 -250
  101. package/src/config/config.tsx +0 -917
  102. package/src/config/types.ts +0 -286
  103. package/src/editor/ComponentInfo.tsx +0 -90
  104. package/src/editor/ConfirmationDialog.tsx +0 -103
  105. package/src/editor/ContentTree.tsx +0 -727
  106. package/src/editor/ContextMenu.tsx +0 -212
  107. package/src/editor/Editor.tsx +0 -90
  108. package/src/editor/EditorWarning.tsx +0 -34
  109. package/src/editor/EditorWarnings.tsx +0 -33
  110. package/src/editor/FieldEditorPopup.tsx +0 -65
  111. package/src/editor/FieldHistory.tsx +0 -74
  112. package/src/editor/FieldList.tsx +0 -190
  113. package/src/editor/FieldListField.tsx +0 -391
  114. package/src/editor/FieldListFieldWithFallbacks.tsx +0 -217
  115. package/src/editor/FloatingToolbar.tsx +0 -163
  116. package/src/editor/ImageEditor.tsx +0 -128
  117. package/src/editor/ItemInfo.tsx +0 -90
  118. package/src/editor/LinkEditorDialog.tsx +0 -196
  119. package/src/editor/MainLayout.tsx +0 -95
  120. package/src/editor/MobileLayout.tsx +0 -68
  121. package/src/editor/NewEditorClient.tsx +0 -11
  122. package/src/editor/PictureCropper.tsx +0 -503
  123. package/src/editor/PictureEditor.tsx +0 -212
  124. package/src/editor/PictureEditorDialog.tsx +0 -381
  125. package/src/editor/PublishDialog.ignore +0 -74
  126. package/src/editor/ScrollingContentTree.tsx +0 -67
  127. package/src/editor/Terminal.tsx +0 -227
  128. package/src/editor/Titlebar.tsx +0 -93
  129. package/src/editor/ai/AiPopup.tsx +0 -59
  130. package/src/editor/ai/AiResponseMessage.tsx +0 -106
  131. package/src/editor/ai/AiTerminal.tsx +0 -514
  132. package/src/editor/ai/AiToolCall.tsx +0 -61
  133. package/src/editor/ai/EditorAiTerminal.tsx +0 -20
  134. package/src/editor/ai/GhostWriter.tsx +0 -432
  135. package/src/editor/ai/aiPageModel.ts +0 -108
  136. package/src/editor/ai/editorAiContext.ts +0 -18
  137. package/src/editor/client/AboutDialog.tsx +0 -44
  138. package/src/editor/client/EditorClient.tsx +0 -2197
  139. package/src/editor/client/GenericDialog.tsx +0 -50
  140. package/src/editor/client/editContext.ts +0 -412
  141. package/src/editor/client/helpers.ts +0 -44
  142. package/src/editor/client/itemsRepository.ts +0 -538
  143. package/src/editor/client/operations.ts +0 -768
  144. package/src/editor/client/pageModelBuilder.ts +0 -219
  145. package/src/editor/commands/commands.ts +0 -22
  146. package/src/editor/commands/componentCommands.tsx +0 -424
  147. package/src/editor/commands/createVersionCommand.ts +0 -33
  148. package/src/editor/commands/deleteVersionCommand.ts +0 -71
  149. package/src/editor/commands/itemCommands.tsx +0 -351
  150. package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +0 -201
  151. package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +0 -27
  152. package/src/editor/commands/undo.ts +0 -39
  153. package/src/editor/component-designer/ComponentDesigner.tsx +0 -70
  154. package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +0 -11
  155. package/src/editor/component-designer/ComponentDesignerMenu.tsx +0 -91
  156. package/src/editor/component-designer/ComponentEditor.tsx +0 -97
  157. package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +0 -31
  158. package/src/editor/component-designer/ComponentRenderingEditor.tsx +0 -104
  159. package/src/editor/component-designer/ComponentsDropdown.tsx +0 -39
  160. package/src/editor/component-designer/PlaceholdersEditor.tsx +0 -179
  161. package/src/editor/component-designer/RenderingsDropdown.tsx +0 -36
  162. package/src/editor/component-designer/TemplateEditor.tsx +0 -236
  163. package/src/editor/component-designer/aiContext.ts +0 -23
  164. package/src/editor/componentTreeHelper.tsx +0 -116
  165. package/src/editor/context-menu/CopyMoveMenu.tsx +0 -103
  166. package/src/editor/context-menu/InsertMenu.tsx +0 -347
  167. package/src/editor/control-center/About.tsx +0 -342
  168. package/src/editor/control-center/ControlCenterMenu.tsx +0 -76
  169. package/src/editor/control-center/IndexOverview.tsx +0 -50
  170. package/src/editor/control-center/IndexSettings.tsx +0 -266
  171. package/src/editor/control-center/Info.tsx +0 -104
  172. package/src/editor/control-center/QuotaInfo.tsx +0 -301
  173. package/src/editor/control-center/Status.tsx +0 -113
  174. package/src/editor/control-center/WebSocketMessages.tsx +0 -155
  175. package/src/editor/editor-warnings/ItemLocked.tsx +0 -63
  176. package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +0 -22
  177. package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +0 -23
  178. package/src/editor/editor-warnings/NoWriteAccess.tsx +0 -16
  179. package/src/editor/editor-warnings/ValidationErrors.tsx +0 -54
  180. package/src/editor/field-types/AttachmentEditor.tsx +0 -9
  181. package/src/editor/field-types/CheckboxEditor.tsx +0 -47
  182. package/src/editor/field-types/DropLinkEditor.tsx +0 -80
  183. package/src/editor/field-types/DropListEditor.tsx +0 -84
  184. package/src/editor/field-types/ImageFieldEditor.tsx +0 -65
  185. package/src/editor/field-types/InternalLinkFieldEditor.tsx +0 -117
  186. package/src/editor/field-types/LinkFieldEditor.tsx +0 -85
  187. package/src/editor/field-types/MultiLineText.tsx +0 -82
  188. package/src/editor/field-types/PictureFieldEditor.tsx +0 -121
  189. package/src/editor/field-types/RawEditor.tsx +0 -53
  190. package/src/editor/field-types/ReactQuill.tsx +0 -580
  191. package/src/editor/field-types/RichTextEditor.tsx +0 -22
  192. package/src/editor/field-types/RichTextEditorComponent.tsx +0 -127
  193. package/src/editor/field-types/SingleLineText.tsx +0 -174
  194. package/src/editor/field-types/TreeListEditor.tsx +0 -261
  195. package/src/editor/fieldTypes.ts +0 -140
  196. package/src/editor/media-selector/AiImageSearch.tsx +0 -185
  197. package/src/editor/media-selector/AiImageSearchPrompt.tsx +0 -94
  198. package/src/editor/media-selector/MediaSelector.tsx +0 -42
  199. package/src/editor/media-selector/Preview.tsx +0 -14
  200. package/src/editor/media-selector/Thumbnails.tsx +0 -48
  201. package/src/editor/media-selector/TreeSelector.tsx +0 -292
  202. package/src/editor/media-selector/UploadZone.tsx +0 -137
  203. package/src/editor/menubar/ActionsMenu.tsx +0 -94
  204. package/src/editor/menubar/ActiveUsers.tsx +0 -17
  205. package/src/editor/menubar/ApproveAndPublish.tsx +0 -18
  206. package/src/editor/menubar/BrowseHistory.tsx +0 -37
  207. package/src/editor/menubar/ItemLanguageVersion.tsx +0 -76
  208. package/src/editor/menubar/LanguageSelector.tsx +0 -226
  209. package/src/editor/menubar/Menu.tsx +0 -83
  210. package/src/editor/menubar/NavButtons.tsx +0 -74
  211. package/src/editor/menubar/PageSelector.tsx +0 -141
  212. package/src/editor/menubar/PageViewerControls.tsx +0 -120
  213. package/src/editor/menubar/PreviewSecondaryControls.tsx +0 -18
  214. package/src/editor/menubar/SecondaryControls.tsx +0 -45
  215. package/src/editor/menubar/Separator.tsx +0 -12
  216. package/src/editor/menubar/SiteInfo.tsx +0 -53
  217. package/src/editor/menubar/User.tsx +0 -27
  218. package/src/editor/menubar/VersionSelector.tsx +0 -142
  219. package/src/editor/page-editor-chrome/CommentHighlighting.tsx +0 -307
  220. package/src/editor/page-editor-chrome/CommentHighlightings.tsx +0 -35
  221. package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +0 -59
  222. package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +0 -23
  223. package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +0 -64
  224. package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +0 -35
  225. package/src/editor/page-editor-chrome/FrameMenu.tsx +0 -338
  226. package/src/editor/page-editor-chrome/FrameMenus.tsx +0 -48
  227. package/src/editor/page-editor-chrome/InlineEditor.tsx +0 -765
  228. package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +0 -61
  229. package/src/editor/page-editor-chrome/NoLayout.tsx +0 -36
  230. package/src/editor/page-editor-chrome/PageEditorChrome.tsx +0 -122
  231. package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +0 -161
  232. package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +0 -169
  233. package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +0 -315
  234. package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +0 -300
  235. package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +0 -40
  236. package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +0 -791
  237. package/src/editor/page-viewer/DeviceToolbar.tsx +0 -70
  238. package/src/editor/page-viewer/EditorForm.tsx +0 -258
  239. package/src/editor/page-viewer/MiniMap.tsx +0 -362
  240. package/src/editor/page-viewer/PageViewer.tsx +0 -169
  241. package/src/editor/page-viewer/PageViewerFrame.tsx +0 -879
  242. package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +0 -412
  243. package/src/editor/page-viewer/pageViewContext.ts +0 -186
  244. package/src/editor/pageModel.ts +0 -208
  245. package/src/editor/picture-shared.tsx +0 -53
  246. package/src/editor/reviews/Comment.tsx +0 -308
  247. package/src/editor/reviews/Comments.tsx +0 -125
  248. package/src/editor/reviews/DiffView.tsx +0 -109
  249. package/src/editor/reviews/PreviewInfo.tsx +0 -35
  250. package/src/editor/reviews/Reviews.tsx +0 -280
  251. package/src/editor/reviews/SuggestedEdit.tsx +0 -316
  252. package/src/editor/reviews/reviewCommands.tsx +0 -47
  253. package/src/editor/reviews/useReviews.tsx +0 -70
  254. package/src/editor/services/aiService.ts +0 -174
  255. package/src/editor/services/componentDesignerService.ts +0 -151
  256. package/src/editor/services/contentService.ts +0 -180
  257. package/src/editor/services/editService.ts +0 -486
  258. package/src/editor/services/indexService.ts +0 -24
  259. package/src/editor/services/reviewsService.ts +0 -53
  260. package/src/editor/services/serviceHelper.ts +0 -95
  261. package/src/editor/services/suggestedEditsService.ts +0 -39
  262. package/src/editor/services/systemService.ts +0 -5
  263. package/src/editor/services/translationService.ts +0 -21
  264. package/src/editor/services-server/api.ts +0 -150
  265. package/src/editor/services-server/graphQL.ts +0 -106
  266. package/src/editor/sidebar/ComponentPalette.tsx +0 -161
  267. package/src/editor/sidebar/ComponentTree.tsx +0 -548
  268. package/src/editor/sidebar/ComponentTree2.tsxx +0 -490
  269. package/src/editor/sidebar/Debug.tsx +0 -111
  270. package/src/editor/sidebar/DictionaryEditor.tsx +0 -261
  271. package/src/editor/sidebar/EditHistory.tsx +0 -134
  272. package/src/editor/sidebar/GraphQL.tsx +0 -164
  273. package/src/editor/sidebar/Insert.tsx +0 -35
  274. package/src/editor/sidebar/MainContentTree.tsx +0 -102
  275. package/src/editor/sidebar/Performance.tsx +0 -53
  276. package/src/editor/sidebar/Sessions.tsx +0 -35
  277. package/src/editor/sidebar/Sidebar.tsx +0 -20
  278. package/src/editor/sidebar/SidebarView.tsx +0 -152
  279. package/src/editor/sidebar/Translations.tsx +0 -295
  280. package/src/editor/sidebar/Validation.tsx +0 -102
  281. package/src/editor/sidebar/ViewSelector.tsx +0 -60
  282. package/src/editor/sidebar/Workbox.tsx +0 -209
  283. package/src/editor/ui/CenteredMessage.tsx +0 -7
  284. package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +0 -81
  285. package/src/editor/ui/CopyToClipboardButton.tsx +0 -24
  286. package/src/editor/ui/DialogButtons.tsx +0 -11
  287. package/src/editor/ui/Icons.tsx +0 -708
  288. package/src/editor/ui/ItemNameDialogNew.tsx +0 -118
  289. package/src/editor/ui/ItemSearch.tsx +0 -190
  290. package/src/editor/ui/PerfectTree.tsx +0 -571
  291. package/src/editor/ui/Section.tsx +0 -35
  292. package/src/editor/ui/SimpleIconButton.tsx +0 -54
  293. package/src/editor/ui/SimpleMenu.tsx +0 -40
  294. package/src/editor/ui/SimpleTable.tsx +0 -60
  295. package/src/editor/ui/SimpleTabs.tsx +0 -55
  296. package/src/editor/ui/SimpleToolbar.tsx +0 -7
  297. package/src/editor/ui/Spinner.tsx +0 -9
  298. package/src/editor/ui/Splitter.tsx +0 -314
  299. package/src/editor/ui/StackedPanels.tsx +0 -134
  300. package/src/editor/ui/Toolbar.tsx +0 -7
  301. package/src/editor/utils/id-helper.ts +0 -3
  302. package/src/editor/utils/insertOptions.ts +0 -69
  303. package/src/editor/utils/itemutils.ts +0 -29
  304. package/src/editor/utils/useMemoDebug.ts +0 -28
  305. package/src/editor/utils.ts +0 -486
  306. package/src/editor/views/CompareView.tsx +0 -245
  307. package/src/editor/views/EditView.tsx +0 -27
  308. package/src/editor/views/ItemEditor.tsx +0 -58
  309. package/src/editor/views/SingleEditView.tsx +0 -46
  310. package/src/fonts/Geist-Black.woff2 +0 -0
  311. package/src/fonts/Geist-Bold.woff2 +0 -0
  312. package/src/fonts/Geist-ExtraBold.woff2 +0 -0
  313. package/src/fonts/Geist-ExtraLight.woff2 +0 -0
  314. package/src/fonts/Geist-Light.woff2 +0 -0
  315. package/src/fonts/Geist-Medium.woff2 +0 -0
  316. package/src/fonts/Geist-Regular.woff2 +0 -0
  317. package/src/fonts/Geist-SemiBold.woff2 +0 -0
  318. package/src/fonts/Geist-Thin.woff2 +0 -0
  319. package/src/fonts/Geist[wght].woff2 +0 -0
  320. package/src/fonts/index.ts +0 -10
  321. package/src/index.ts +0 -23
  322. package/src/lib/safelist.tsx +0 -16
  323. package/src/lib/utils.ts +0 -6
  324. package/src/page-wizard/PageWizard.tsx +0 -139
  325. package/src/page-wizard/WizardBox.tsx +0 -4
  326. package/src/page-wizard/WizardBoxConnector.tsx +0 -56
  327. package/src/page-wizard/WizardSteps.tsx +0 -458
  328. package/src/page-wizard/service.ts +0 -35
  329. package/src/page-wizard/startPageWizardCommand.ts +0 -26
  330. package/src/page-wizard/steps/BuildPageStep.tsx +0 -259
  331. package/src/page-wizard/steps/CollectStep.tsx +0 -296
  332. package/src/page-wizard/steps/ComponentTypesSelector.tsx +0 -454
  333. package/src/page-wizard/steps/Components.tsx +0 -193
  334. package/src/page-wizard/steps/ContentStep.tsx +0 -890
  335. package/src/page-wizard/steps/EditButton.tsx +0 -34
  336. package/src/page-wizard/steps/FieldEditor.tsx +0 -102
  337. package/src/page-wizard/steps/Generate.tsx +0 -60
  338. package/src/page-wizard/steps/ImagesStep.tsx +0 -382
  339. package/src/page-wizard/steps/LayoutStep.tsx +0 -227
  340. package/src/page-wizard/steps/MetaDataStep.tsx +0 -173
  341. package/src/page-wizard/steps/SelectStep.tsx +0 -281
  342. package/src/page-wizard/steps/schema.ts +0 -180
  343. package/src/page-wizard/steps/usePageCreator.ts +0 -325
  344. package/src/page-wizard/usePageWizard.ts +0 -79
  345. package/src/revision.ts +0 -2
  346. package/src/splash-screen/NewPage.tsx +0 -294
  347. package/src/splash-screen/OpenPage.tsx +0 -113
  348. package/src/splash-screen/RecentPages.tsx +0 -123
  349. package/src/splash-screen/SectionHeadline.tsx +0 -21
  350. package/src/splash-screen/SplashScreen.tsx +0 -195
  351. package/src/tour/Tour.tsx +0 -566
  352. package/src/tour/default-tour.tsx +0 -301
  353. package/src/tour/preview-tour.tsx +0 -128
  354. package/src/types.ts +0 -335
  355. package/styles.css +0 -765
  356. package/tsconfig.build.json +0 -31
  357. package/tsconfig.json +0 -14
@@ -1,879 +0,0 @@
1
- import { useEffect, useRef, useState } from "react";
2
- import { MiniMap } from "./MiniMap";
3
- import { useEditContext, useEditContextRef } from "../client/editContext";
4
- import { useDebouncedCallback, useThrottledCallback } from "use-debounce";
5
- import { PageEditorChrome } from "../page-editor-chrome/PageEditorChrome";
6
- import { PageViewContext } from "./pageViewContext";
7
- import morphdom from "morphdom";
8
- import uuid from "react-uuid";
9
-
10
- import {
11
- findComponentRect,
12
- findFieldElement,
13
- findNearestComponentId,
14
- findParentComponentId,
15
- findParentWithAttribute,
16
- getAbsolutePosition,
17
- getFieldDescriptorFromElement,
18
- findClosestFieldElement,
19
- } from "../utils";
20
-
21
- import { getComponentById } from "../componentTreeHelper";
22
- import { showComponentContextMenu } from "../ContextMenu";
23
- import { loadFieldButtons } from "../services/editService";
24
- import { usePathname } from "next/navigation";
25
- import { EditorWarnings } from "../EditorWarnings";
26
-
27
- import { Component, ItemDescriptor } from "../pageModel";
28
- import { NoLayout } from "../page-editor-chrome/NoLayout";
29
- import { Spinner } from "../ui/Spinner";
30
- import { DeviceToolbar } from "./DeviceToolbar";
31
- import { buildPageModelSkeleton } from "./pageModelSkeletonBuilder";
32
- declare global {
33
- interface Window {
34
- requestRefresh?: (newUri?: string) => boolean;
35
- }
36
- }
37
-
38
- export function PageViewerFrame({
39
- compareView,
40
- pageViewContext,
41
- }: {
42
- compareView: boolean;
43
- pageViewContext?: PageViewContext;
44
- }) {
45
- const editContext = useEditContext();
46
-
47
- const pathname = usePathname();
48
-
49
- const pageViewContextRef = useRef<PageViewContext | undefined>(undefined);
50
-
51
- if (!editContext || !pageViewContext) return null;
52
-
53
- useEffect(() => {
54
- pageViewContextRef.current = pageViewContext;
55
- }, [pageViewContext]);
56
-
57
- const editContextRef = useEditContextRef();
58
-
59
- const iframeRef = pageViewContext.editorIframeRef;
60
-
61
- const [showSpinner, setShowSpinner] = useState(false);
62
- const [scroll, setScroll] = useState(0);
63
- const [showMiniMap, setShowMiniMap] = useState(false);
64
-
65
- const zoom = pageViewContext.zoom;
66
- const blockBlurEventRef = useRef(0);
67
- const [currentItemDescriptor, setCurrentItemDescriptor] = useState<
68
- ItemDescriptor | undefined
69
- >(undefined);
70
-
71
- const pageItemDescriptor = pageViewContext.pageItemDescriptor;
72
-
73
- useEffect(() => {
74
- //Workaround for iframeref updates not propagating to usePageViewContext
75
- pageViewContext.setWorkaround((x) => !x);
76
- }, [iframeRef.current]);
77
-
78
- const updateMiniMapVisibility = useDebouncedCallback(() => {
79
- if (!iframeRef.current) return;
80
- const iframe = iframeRef.current;
81
- const doc = iframe.contentDocument;
82
- if (!doc?.documentElement) return;
83
- const scrollContainer = doc.scrollingElement || doc.body;
84
- if (!scrollContainer) return;
85
-
86
- const contentHeight = scrollContainer.scrollHeight;
87
- const clientHeight = iframe.clientHeight;
88
-
89
- const upperThreshold = clientHeight + 100; // show minimap if content exceeds this height
90
- const lowerThreshold = clientHeight; // hide minimap if content falls below this
91
-
92
- if (showMiniMap) {
93
- if (contentHeight <= lowerThreshold) {
94
- setShowMiniMap(false);
95
- }
96
- } else {
97
- if (contentHeight > upperThreshold) {
98
- setShowMiniMap(true);
99
- }
100
- }
101
- }, 100);
102
-
103
- updateMiniMapVisibility();
104
-
105
- const buildPageModelThrottled = useThrottledCallback(
106
- buildPageModelSkeleton,
107
- 500,
108
- {
109
- leading: false,
110
- trailing: true,
111
- },
112
- );
113
-
114
- const [iframeSrc, setIframeSrc] = useState<string>();
115
-
116
- useEffect(() => {
117
- const isHeadless = pageViewContext.isHeadless;
118
- if (!pageItemDescriptor || isHeadless === undefined) return;
119
-
120
- let renderUrl: URL;
121
- if (!isHeadless) {
122
- // Sitecore MVC rendering
123
- renderUrl = new URL(window.location.href);
124
- renderUrl.pathname = "/";
125
-
126
- renderUrl.searchParams.set("sc_itemid", pageItemDescriptor.id);
127
- renderUrl.searchParams.set("sc_lang", pageItemDescriptor.language);
128
- renderUrl.searchParams.set(
129
- "sc_version",
130
- pageItemDescriptor.version.toString(),
131
- );
132
- if (editContext.mode === "preview") {
133
- renderUrl.searchParams.set("alpaca_preview", "1");
134
- } else {
135
- renderUrl.searchParams.set("alpaca_editor", "1");
136
- }
137
- renderUrl.searchParams.set("sc_mode", "edit");
138
- renderUrl.searchParams.set("alpaca_editor", "1");
139
- renderUrl.searchParams.set("sc_database", "master");
140
- //renderUrl.searchParams.set(
141
- // "sc_site",
142
- // editContext.site?.name || "website"
143
- // );
144
- } else {
145
- // Headless rendering
146
- console.log("Headless rendering", pageItemDescriptor);
147
- renderUrl = new URL(window.location.href);
148
- if (editContext.configuration.services.renderService.path)
149
- renderUrl.pathname =
150
- editContext.configuration.services.renderService.path;
151
-
152
- renderUrl.searchParams.set("itemid", pageItemDescriptor.id);
153
- renderUrl.searchParams.set("lang", pageItemDescriptor.language);
154
- renderUrl.searchParams.set(
155
- "version",
156
- pageItemDescriptor.version.toString(),
157
- );
158
-
159
- renderUrl.searchParams.set(
160
- "site",
161
- editContext.pageView.site?.name || "website",
162
- );
163
- renderUrl.searchParams.set(
164
- "mode",
165
- editContext.mode === "preview" ? "preview" : "edit",
166
- );
167
- }
168
-
169
- renderUrl.searchParams.set("edit_rev", editContext.revision ?? uuid());
170
-
171
- if (iframeRef.current?.contentWindow?.requestRefresh) {
172
- console.log("Integration - requesting refresh");
173
- iframeRef.current?.contentWindow.requestRefresh(renderUrl.toString());
174
- } else {
175
- setShowSpinner(true);
176
- console.log("No integration - reloading frame");
177
- if (isHeadless) {
178
- console.log("Setting iframe src", renderUrl.toString());
179
- setIframeSrc(renderUrl.toString());
180
- } else {
181
- const initialLoad =
182
- currentItemDescriptor?.id !== pageItemDescriptor.id ||
183
- currentItemDescriptor?.language !== pageItemDescriptor.language ||
184
- currentItemDescriptor?.version !== pageItemDescriptor.version;
185
-
186
- loadContent(renderUrl.toString(), initialLoad);
187
- }
188
- }
189
-
190
- setCurrentItemDescriptor(pageItemDescriptor);
191
- }, [
192
- pathname,
193
- editContext.revision,
194
- pageItemDescriptor,
195
- pageViewContext.isHeadless,
196
- editContext.mode,
197
- ]);
198
-
199
- useEffect(() => {
200
- if (editContext.focusedField) {
201
- if (
202
- editContext.selection.length > 0 &&
203
- editContext.focusedField.item.id !== editContext.selection[0]
204
- )
205
- return;
206
-
207
- const fieldElement = findFieldElement(
208
- iframeRef.current!,
209
- editContext.focusedField,
210
- );
211
- if (fieldElement) {
212
- const rect = getAbsolutePosition(
213
- fieldElement as HTMLElement,
214
- iframeRef.current!,
215
- );
216
-
217
- const scrollTop = iframeRef.current?.contentWindow?.scrollY || 0;
218
- const iframeHeight = iframeRef.current?.getBoundingClientRect().height;
219
-
220
- const isInViewport =
221
- rect.y >= scrollTop && rect.y <= scrollTop + (iframeHeight || 0);
222
-
223
- if (!isInViewport) {
224
- iframeRef.current?.contentWindow?.scrollTo({
225
- top: rect.y,
226
- behavior: "smooth",
227
- });
228
- }
229
- }
230
- }
231
- }, [editContext.focusedField]);
232
-
233
- useEffect(() => {
234
- if (!editContext.focusedField && editContext.selection.length > 0) {
235
- const lastSelectedComponent = getComponentById(
236
- editContext.selection[editContext.selection.length - 1]!,
237
- pageViewContextRef.current!.page!,
238
- );
239
- if (lastSelectedComponent) {
240
- editContext.setScrollIntoView(lastSelectedComponent.id);
241
- }
242
- }
243
- }, [editContext.selection]);
244
-
245
- const loadContent = async (href: string, initialLoad: boolean) => {
246
- console.log("Loading content:", href);
247
- const start = performance.now();
248
- if (!href) return;
249
- const content = await fetch(href);
250
- const text = await content.text();
251
- console.log("Content loaded in " + (performance.now() - start) + " ms");
252
- const doc = iframeRef.current?.contentDocument;
253
-
254
- if (doc) {
255
- if (initialLoad) {
256
- doc.open();
257
- doc.write(text);
258
- doc.close();
259
- } else {
260
- const parser = new DOMParser();
261
- const newDoc = parser.parseFromString(text, "text/html");
262
- morphdom(doc.documentElement, newDoc.documentElement);
263
- if ((iframeRef.current!.contentWindow as any).XA) {
264
- console.log("init XA");
265
- (iframeRef.current!.contentWindow as any).XA.init();
266
- }
267
- setShowSpinner(false);
268
- }
269
-
270
- injectEditorCSS(doc, editContext.mode !== "preview");
271
-
272
- setTimeout(() => {
273
- injectSXAScripts(iframeRef.current!);
274
- }, 1000);
275
-
276
- buildPageModelThrottled(doc, editContextRef, pageViewContextRef);
277
- }
278
- };
279
-
280
- useEffect(() => {
281
- if (
282
- !editContext.scrollIntoView ||
283
- !iframeRef.current?.contentDocument?.documentElement
284
- )
285
- return;
286
-
287
- const component = getComponentById(
288
- editContext.scrollIntoView,
289
- pageViewContextRef.current!.page!,
290
- );
291
-
292
- if (!component) return;
293
-
294
- const rect = findComponentRect(iframeRef.current!, component, true);
295
-
296
- if (!rect) return;
297
-
298
- // Check if element is already in viewport
299
- const iframeHeight = iframeRef.current.getBoundingClientRect().height;
300
-
301
- const scrollTop = iframeRef.current?.contentWindow?.scrollY || 0;
302
- const elementTop = rect.rect.y;
303
-
304
- const isInViewport =
305
- elementTop >= scrollTop && elementTop <= scrollTop + iframeHeight;
306
-
307
- // If already in viewport, no need to scroll
308
- if (isInViewport) {
309
- editContext.setScrollIntoView(undefined);
310
- return;
311
- }
312
-
313
- const scrollPosition =
314
- rect.rect.y - iframeHeight / 2 + rect.rect.height / 2;
315
-
316
- iframeRef.current?.contentWindow?.scrollTo({
317
- top: scrollPosition,
318
- behavior: "smooth",
319
- });
320
-
321
- editContext.setScrollIntoView(undefined);
322
- }, [editContext.scrollIntoView, pageViewContext.page]);
323
-
324
- useEffect(() => {
325
- const handleMessage = (message: MessageEvent) => {
326
- if (message.data.type === "editor-exitFullscreen") {
327
- editContext.pageView.setFullscreen(false);
328
- }
329
- if (message.data.type === "editor-timings") {
330
- editContext.setTimings(message.data.timings);
331
- }
332
- };
333
- window.addEventListener("message", handleMessage);
334
-
335
- return () => {
336
- window.removeEventListener("message", handleMessage);
337
- };
338
- }, []);
339
-
340
- const selecionChangeHandler = useThrottledCallback(() => {
341
- const sel = iframeRef.current?.contentDocument?.getSelection();
342
-
343
- if (sel && sel.rangeCount > 0) {
344
- // Find the field element containing the selection
345
- const fieldElement = findClosestFieldElement(sel.anchorNode);
346
-
347
- if (!fieldElement) return;
348
-
349
- const fieldId = fieldElement.getAttribute("data-fieldid");
350
- if (!fieldId) return;
351
-
352
- const range = sel.getRangeAt(0);
353
-
354
- editContextRef.current?.setFocusedField(
355
- {
356
- fieldId: fieldId,
357
- item: {
358
- id: fieldElement.getAttribute("data-itemid") || "",
359
- language: fieldElement.getAttribute("data-language") || "",
360
- version: parseInt(fieldElement.getAttribute("data-version") || "0"),
361
- },
362
- },
363
- editContext.mode === "edit",
364
- );
365
-
366
- // Compute the global offsets relative to the field element.
367
- const globalStartOffset = getGlobalTextOffset(
368
- fieldElement,
369
- range.startContainer,
370
- range.startOffset,
371
- );
372
- const globalEndOffset = getGlobalTextOffset(
373
- fieldElement,
374
- range.endContainer,
375
- range.endOffset,
376
- );
377
-
378
- editContextRef.current?.setSelectedRange({
379
- itemId: fieldElement.getAttribute("data-itemid") || "",
380
- fieldId: fieldId,
381
- startOffset: globalStartOffset,
382
- endOffset: globalEndOffset,
383
- text: range.toString(),
384
- });
385
- }
386
- }, 100);
387
-
388
- useEffect(() => {
389
- const iframe = iframeRef.current;
390
- if (!iframe) return;
391
-
392
- const handleIframeMouseDown = async (event: any) => {
393
- const target = event.target;
394
-
395
- if (editContextRef.current?.isRefreshing) return;
396
-
397
- const componentId = findParentComponentId(target);
398
- if (editContextRef.current?.currentOverlay)
399
- editContextRef.current?.setCurrentOverlay(undefined);
400
-
401
- if (componentId) {
402
- if (event.ctrlKey) {
403
- const currentSelection = editContextRef.current?.selection || [];
404
- if (currentSelection.indexOf(componentId) === -1)
405
- editContextRef.current?.select([...currentSelection, componentId]);
406
- } else {
407
- if (editContextRef.current?.selection.indexOf(componentId) === -1) {
408
- editContextRef.current?.select([componentId]);
409
- }
410
- }
411
-
412
- // if (mode !== "edit") {
413
- //editContextRef.current?.setScrollIntoView(componentId);
414
- //}
415
- } else editContextRef.current?.select([]);
416
-
417
- if (
418
- (editContext.mode === "edit" &&
419
- pageViewContextRef.current?.page?.item.canWriteItem) ||
420
- editContext.mode === "suggestions"
421
- ) {
422
- const fieldElement = findParentWithAttribute(target, "data-fieldid");
423
- if (fieldElement?.hasAttribute("data-itemid")) {
424
- blockBlurEventRef.current = Date.now() + 500;
425
-
426
- const hasLock =
427
- editContext.mode === "suggestions" ||
428
- (await editContextRef.current?.setFocusedField(
429
- getFieldDescriptorFromElement(fieldElement),
430
- true,
431
- ));
432
-
433
- if (
434
- hasLock &&
435
- editContextRef.current?.inlineEditingFieldElement !== fieldElement
436
- ) {
437
- editContextRef.current?.setInlineEditingFieldElement(fieldElement);
438
- // Don't prevent default - we want the browser's natural cursor positioning
439
- }
440
- }
441
- }
442
- //Forward events so primereact overlays can close
443
- const clickEvent = new MouseEvent("click", {
444
- view: window,
445
- bubbles: true,
446
- cancelable: true,
447
- clientX: event.clientX,
448
- clientY: event.clientY,
449
- });
450
-
451
- document.dispatchEvent(clickEvent);
452
- };
453
-
454
- const handleIframeClick = async (event: any) => {
455
- const target = event.target;
456
- // Check if the click target is a link (anchor tag)
457
- const anchor =
458
- target.tagName.toLowerCase() === "a" ? target : target.closest("a");
459
- if (anchor) {
460
- const href = (anchor as HTMLAnchorElement).href;
461
-
462
- // Block only navigation links, allow anchor links and javascript links
463
- if (href && !href.startsWith("#") && !href.startsWith("javascript:")) {
464
- event.preventDefault();
465
- }
466
- }
467
- };
468
-
469
- const handleContextMenu = async (event: MouseEvent) => {
470
- if (editContextRef.current?.isRefreshing) return;
471
- const target = event.target;
472
- if (!target) return;
473
-
474
- if (event.ctrlKey) return;
475
-
476
- event.preventDefault();
477
- event.stopPropagation();
478
-
479
- const componentId = findNearestComponentId(target as HTMLElement);
480
-
481
- if (componentId) {
482
- if (!editContextRef.current?.selection.includes(componentId)) {
483
- editContextRef.current!.select([componentId]);
484
- }
485
- }
486
-
487
- const fieldElement = findParentWithAttribute(
488
- target as HTMLElement,
489
- "data-fieldid",
490
- );
491
-
492
- const selectedComponents = editContextRef.current?.selection
493
- .map((id) => getComponentById(id, pageViewContextRef.current!.page!))
494
- .filter((x) => x) as Component[];
495
-
496
- const iframeRect = iframe.getBoundingClientRect();
497
- const adjustedEvent = new MouseEvent("contextmenu", {
498
- bubbles: true,
499
- cancelable: true,
500
- shiftKey: event.shiftKey,
501
- altKey: event.altKey,
502
- ctrlKey: event.ctrlKey,
503
- view: window,
504
- clientX: event.clientX + iframeRect.x,
505
- clientY: event.clientY + iframeRect.y,
506
- });
507
-
508
- const field = fieldElement
509
- ? getFieldDescriptorFromElement(fieldElement)
510
- : undefined;
511
-
512
- const fieldButtons = field ? await loadFieldButtons(field) : [];
513
-
514
- const showMenu = await showComponentContextMenu(
515
- selectedComponents,
516
- editContextRef.current!,
517
- field,
518
- fieldButtons,
519
- );
520
- if (showMenu) showMenu(adjustedEvent);
521
- };
522
-
523
- const handleLoad = () => {
524
- setShowSpinner(false);
525
- const iframeDocument =
526
- iframe!.contentDocument || iframe!.contentWindow?.document;
527
- if (iframeDocument) {
528
- iframeDocument.documentElement.addEventListener(
529
- "mousedown",
530
- handleIframeMouseDown,
531
- );
532
- iframeDocument.documentElement.addEventListener(
533
- "click",
534
- handleIframeClick,
535
- );
536
- iframe.contentWindow?.addEventListener(
537
- "contextmenu",
538
- handleContextMenu,
539
- true,
540
- );
541
-
542
- const scrollContainer =
543
- iframe.contentWindow?.document.scrollingElement ||
544
- iframe.contentWindow?.document.body;
545
- scrollContainer?.addEventListener("scroll", () => {
546
- const scrollTop = scrollContainer.scrollTop || 0;
547
- scrollHandler(scrollTop);
548
- });
549
- iframe.contentWindow?.addEventListener("scroll", () => {
550
- const scrollTop = scrollContainer?.scrollTop || 0;
551
- scrollHandler(scrollTop);
552
- });
553
-
554
- iframeDocument.addEventListener(
555
- "selectionchange",
556
- selecionChangeHandler,
557
- );
558
-
559
- iframeDocument.addEventListener("keydown", (event: KeyboardEvent) => {
560
- editContextRef.current?.handleKeyDown(event);
561
- });
562
-
563
- iframeDocument.documentElement?.addEventListener(
564
- "blur",
565
- () => {
566
- // Block blur event if it was triggered by clicking on a field
567
- if (blockBlurEventRef.current < Date.now()) {
568
- //editContext.setFocusedField(undefined, false);
569
- editContext.setInlineEditingFieldElement(undefined);
570
- } else {
571
- blockBlurEventRef.current = 0;
572
- }
573
- },
574
- true,
575
- );
576
-
577
- const observer = new MutationObserver((records) => {
578
- // Ignore all text field edits
579
- if (
580
- records.some(
581
- (x) =>
582
- !(
583
- x &&
584
- "getAttribute" in x.target &&
585
- (x.target as Element).getAttribute("data-fieldid") &&
586
- (x.target as Element).getAttribute("data-itemid")
587
- ),
588
- )
589
- ) {
590
- buildPageModelThrottled(
591
- iframeDocument,
592
- editContextRef,
593
- pageViewContextRef,
594
- );
595
- }
596
- });
597
-
598
- observer.observe(iframeDocument!, {
599
- childList: true, // observe direct children changes
600
- subtree: true, // observe all descendants changes
601
- characterData: false, // observe text changes
602
-
603
- //attributes: true, // observe attribute changes (like style or class)
604
- });
605
-
606
- buildPageModelThrottled(
607
- iframeDocument,
608
- editContextRef,
609
- pageViewContextRef,
610
- );
611
- }
612
- };
613
-
614
- if (iframe) {
615
- iframe.addEventListener("load", handleLoad);
616
- }
617
-
618
- // Cleanup function
619
- return () => {
620
- if (iframe) {
621
- iframe.removeEventListener("load", handleLoad);
622
-
623
- const iframeDocument =
624
- iframe.contentDocument || iframe.contentWindow?.document;
625
- if (iframeDocument) {
626
- iframeDocument.documentElement.removeEventListener(
627
- "click",
628
- handleIframeMouseDown,
629
- );
630
- iframeDocument.documentElement.removeEventListener(
631
- "contextmenu",
632
- handleContextMenu,
633
- );
634
- }
635
- }
636
- };
637
- }, [iframeRef.current]);
638
-
639
- useEffect(() => {
640
- iframeRef.current?.contentWindow?.postMessage(
641
- { type: "componentsSelected", componentIds: editContext.selection },
642
- "*",
643
- );
644
- }, [editContext.selection]);
645
-
646
- const updateScrollPosition = (e: number) => {
647
- setScroll(e);
648
- if (!compareView) pageViewContextRef.current?.setScroll(e);
649
- };
650
-
651
- useEffect(() => {
652
- if (!iframeRef.current) return;
653
- const body = iframeRef.current.contentWindow?.document.documentElement;
654
- if (!body) return;
655
- body.style.transform = `scale(${zoom})`;
656
- body.style.transformOrigin = "top center";
657
- body.style.overflow = "auto";
658
- //body.style.height = `${body.scrollHeight / zoom}px`;
659
- }, [zoom]);
660
-
661
- const scrollHandler = useThrottledCallback(updateScrollPosition, 100);
662
-
663
- if (pageViewContext.page?.item && !pageViewContext.page?.item.hasLayout) {
664
- return <NoLayout />;
665
- }
666
-
667
- const deviceHeight =
668
- pageViewContext.device === "desktop" || !pageViewContext.deviceHeight
669
- ? "100%"
670
- : pageViewContext.deviceHeight || 640;
671
-
672
- return (
673
- <div className="relative flex h-full w-full flex-col items-center bg-slate-100 select-none">
674
- {!editContext.pageView.fullscreen && (
675
- <EditorWarnings item={pageViewContext.page?.item} />
676
- )}
677
- {pageViewContext.device !== "desktop" && (
678
- <DeviceToolbar
679
- pageViewContext={pageViewContext}
680
- configuration={editContext.configuration}
681
- />
682
- )}
683
- <div
684
- className="relative flex flex-1 select-none"
685
- style={{
686
- width:
687
- pageViewContext.device === "desktop" ||
688
- pageViewContext.device === "Responsive"
689
- ? "100%"
690
- : (pageViewContext.deviceWidth || 640) +
691
- editContext.configuration.outline.width +
692
- "px",
693
- }}
694
- >
695
- <div className="relative h-full w-full">
696
- <iframe
697
- ref={iframeRef}
698
- className="page-iframe h-full w-full bg-white"
699
- style={{ height: deviceHeight }}
700
- src={iframeSrc}
701
- data-testid="pageEditoriframe"
702
- />
703
-
704
- {iframeRef.current && (
705
- <PageEditorChrome
706
- iframe={iframeRef.current}
707
- compareView={compareView}
708
- pageViewContext={pageViewContext}
709
- />
710
- )}
711
- {pageViewContext.deviceHeight && pageViewContext.device && (
712
- <div className="relative z-40 h-full w-full bg-slate-100"></div>
713
- )}
714
- </div>
715
- {!editContext.pageView.fullscreen && showMiniMap && (
716
- <MiniMap
717
- compareView={compareView}
718
- scroll={scroll}
719
- mainViewIframeRef={iframeRef}
720
- pageViewContext={pageViewContext}
721
- deviceHeight={
722
- pageViewContext.device === "Desktop"
723
- ? undefined
724
- : pageViewContext.deviceHeight
725
- }
726
- />
727
- )}
728
- {showSpinner && (
729
- <>
730
- <div className="absolute top-0 left-0 h-full w-full bg-slate-100/50"></div>
731
- <div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 transform">
732
- <Spinner />
733
- </div>
734
- </>
735
- )}
736
- </div>
737
- </div>
738
- );
739
- }
740
-
741
- function injectEditorCSS(iframeDocument: Document, editMode: boolean) {
742
- if (!iframeDocument) return;
743
- const style = iframeDocument.createElement("style");
744
-
745
- style.textContent = editMode
746
- ? `[contentEditable]:empty:before {
747
- content: attr(placeholder);
748
- opacity: 0.6;
749
- }
750
-
751
- .scChromeData, code {
752
- display: none;
753
- }
754
-
755
- [contenteditable] {
756
- outline: 0px solid transparent;
757
- }
758
- `
759
- : `
760
- [contenteditable] {
761
- outline: 0px solid transparent;
762
- }
763
- .scChromeData, code {
764
- display: none;
765
- }
766
- `;
767
-
768
- if (iframeDocument && iframeDocument.head) {
769
- iframeDocument.head.appendChild(style);
770
- }
771
- }
772
-
773
- function injectSXAScripts(iframe: HTMLIFrameElement): void {
774
- if (!iframe) return;
775
- const iframeDocument = iframe.contentDocument;
776
- const iframeWindow = iframe.contentWindow as any;
777
- if (!iframeDocument || !iframeWindow) return;
778
-
779
- iframeWindow.Sitecore = {
780
- PageModes: {
781
- HoverFrame: {
782
- extend: () => {
783
- // console.log("extend hoverframe");
784
- },
785
- },
786
- ChromeManager: {
787
- chromes: () => {
788
- // console.log("chromes");
789
- return [];
790
- },
791
- resetChromes: () => {
792
- // console.log("resetChromes");
793
- iframeWindow.XA.init();
794
- },
795
- chromesReseted: {
796
- observe: () => {
797
- // console.log("chromesReseted.observe");
798
- },
799
- },
800
- // Dummy selectionChanged with an _callbacks array
801
- selectionChanged: {
802
- _callbacks: [] as any[],
803
- // Optionally, you can add a method to trigger all callbacks if needed.
804
- trigger: function (...args: any[]): void {
805
- this._callbacks.forEach((callback: Function) => callback(...args));
806
- },
807
- },
808
- },
809
-
810
- ChromeControls: function () {},
811
- ChromeTypes: {
812
- PlaceholderSorting: function () {},
813
- Rendering: function () {},
814
- },
815
- },
816
- };
817
-
818
- // Option 1: Use main window's jQuery if available.
819
- if (iframeWindow.jQuery) {
820
- // Be cautious: if the iframe's document is different, it's better to load jQuery within the iframe.
821
- iframeWindow.$sc = iframeWindow.jQuery;
822
- } else {
823
- // Option 2: Dynamically load jQuery in the iframe.
824
- const jqueryScript = iframeDocument.createElement("script");
825
- jqueryScript.type = "text/javascript";
826
- jqueryScript.src = "https://code.jquery.com/jquery-3.6.0.min.js"; // Use the version you prefer.
827
- jqueryScript.onload = () => {
828
- // Once loaded, assign it to $sc using noConflict to avoid global collisions.
829
- iframeWindow.$sc = iframeWindow.jQuery.noConflict();
830
- // console.log("jQuery loaded in iframe and assigned to $sc");
831
- };
832
- (iframeDocument.head || iframeDocument.body).appendChild(jqueryScript);
833
- }
834
-
835
- // Add a dummy implementation for renderExpandCommand on the ChromeControls prototype.
836
- iframeWindow.Sitecore.PageModes.ChromeControls.prototype.renderExpandCommand =
837
- function () {
838
- console.log("renderExpandCommand called");
839
- // Return a dummy value if needed. For example, you might return a dummy HTML string.
840
- return "<div>Dummy Expand Command</div>";
841
- };
842
-
843
- iframeWindow.Sitecore.PageModes.ChromeTypes.PlaceholderSorting.prototype.insertSortingHandle =
844
- function () {
845
- console.log("insertSortingHandle called");
846
- };
847
- }
848
-
849
- /**
850
- * Calculates the global offset of a given target node and its local offset,
851
- * relative to the container's complete text content.
852
- *
853
- * @param container - The container element that holds the text nodes.
854
- * @param targetNode - The text node where the selection starts or ends.
855
- * @param localOffset - The offset within the target text node.
856
- * @returns The computed global offset.
857
- */
858
- function getGlobalTextOffset(
859
- container: Node,
860
- targetNode: Node,
861
- localOffset: number,
862
- ): number {
863
- let globalOffset = 0;
864
- const walker = document.createTreeWalker(
865
- container,
866
- NodeFilter.SHOW_TEXT,
867
- null,
868
- );
869
- while (walker.nextNode()) {
870
- const currentNode = walker.currentNode;
871
- // If we've reached the target node, add the local offset and return.
872
- if (currentNode === targetNode) {
873
- return globalOffset + localOffset;
874
- }
875
- // Otherwise, add the length of this text node.
876
- globalOffset += (currentNode.textContent || "").length;
877
- }
878
- return globalOffset;
879
- }