@alpaca-editor/core 1.0.0

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 (239) hide show
  1. package/.prettierrc +3 -0
  2. package/eslint.config.mjs +4 -0
  3. package/images/bg-shape-black.webp +0 -0
  4. package/package.json +52 -0
  5. package/src/client-components/api.ts +6 -0
  6. package/src/client-components/index.ts +19 -0
  7. package/src/components/ActionButton.tsx +43 -0
  8. package/src/components/Error.tsx +57 -0
  9. package/src/config/config.tsx +737 -0
  10. package/src/config/types.ts +263 -0
  11. package/src/editor/ComponentInfo.tsx +77 -0
  12. package/src/editor/ConfirmationDialog.tsx +103 -0
  13. package/src/editor/ContentTree.tsx +654 -0
  14. package/src/editor/ContextMenu.tsx +155 -0
  15. package/src/editor/Editor.tsx +91 -0
  16. package/src/editor/EditorWarning.tsx +34 -0
  17. package/src/editor/EditorWarnings.tsx +33 -0
  18. package/src/editor/FieldEditorPopup.tsx +65 -0
  19. package/src/editor/FieldHistory.tsx +74 -0
  20. package/src/editor/FieldList.tsx +190 -0
  21. package/src/editor/FieldListField.tsx +387 -0
  22. package/src/editor/FieldListFieldWithFallbacks.tsx +211 -0
  23. package/src/editor/FloatingToolbar.tsx +163 -0
  24. package/src/editor/ImageEditor.tsx +129 -0
  25. package/src/editor/InsertMenu.tsx +332 -0
  26. package/src/editor/ItemInfo.tsx +90 -0
  27. package/src/editor/LinkEditorDialog.tsx +192 -0
  28. package/src/editor/MainLayout.tsx +94 -0
  29. package/src/editor/NewEditorClient.tsx +11 -0
  30. package/src/editor/PictureCropper.tsx +505 -0
  31. package/src/editor/PictureEditor.tsx +206 -0
  32. package/src/editor/PictureEditorDialog.tsx +381 -0
  33. package/src/editor/PublishDialog.ignore +74 -0
  34. package/src/editor/ScrollingContentTree.tsx +47 -0
  35. package/src/editor/Terminal.tsx +215 -0
  36. package/src/editor/Titlebar.tsx +23 -0
  37. package/src/editor/ai/AiPopup.tsx +59 -0
  38. package/src/editor/ai/AiResponseMessage.tsx +82 -0
  39. package/src/editor/ai/AiTerminal.tsx +450 -0
  40. package/src/editor/ai/AiToolCall.tsx +46 -0
  41. package/src/editor/ai/EditorAiTerminal.tsx +20 -0
  42. package/src/editor/ai/editorAiContext.ts +18 -0
  43. package/src/editor/client/DialogContext.tsx +49 -0
  44. package/src/editor/client/EditorClient.tsx +1831 -0
  45. package/src/editor/client/GenericDialog.tsx +50 -0
  46. package/src/editor/client/editContext.ts +330 -0
  47. package/src/editor/client/helpers.ts +44 -0
  48. package/src/editor/client/itemsRepository.ts +391 -0
  49. package/src/editor/client/operations.ts +610 -0
  50. package/src/editor/client/pageModelBuilder.ts +182 -0
  51. package/src/editor/commands/commands.ts +23 -0
  52. package/src/editor/commands/componentCommands.tsx +408 -0
  53. package/src/editor/commands/createVersionCommand.ts +33 -0
  54. package/src/editor/commands/deleteVersionCommand.ts +71 -0
  55. package/src/editor/commands/itemCommands.tsx +186 -0
  56. package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
  57. package/src/editor/commands/undo.ts +39 -0
  58. package/src/editor/component-designer/ComponentDesigner.tsx +70 -0
  59. package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +11 -0
  60. package/src/editor/component-designer/ComponentDesignerMenu.tsx +91 -0
  61. package/src/editor/component-designer/ComponentEditor.tsx +97 -0
  62. package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +31 -0
  63. package/src/editor/component-designer/ComponentRenderingEditor.tsx +104 -0
  64. package/src/editor/component-designer/ComponentsDropdown.tsx +39 -0
  65. package/src/editor/component-designer/PlaceholdersEditor.tsx +183 -0
  66. package/src/editor/component-designer/RenderingsDropdown.tsx +36 -0
  67. package/src/editor/component-designer/TemplateEditor.tsx +236 -0
  68. package/src/editor/component-designer/aiContext.ts +23 -0
  69. package/src/editor/componentTreeHelper.tsx +114 -0
  70. package/src/editor/control-center/ControlCenterMenu.tsx +71 -0
  71. package/src/editor/control-center/IndexOverview.tsx +50 -0
  72. package/src/editor/control-center/IndexSettings.tsx +266 -0
  73. package/src/editor/control-center/Status.tsx +7 -0
  74. package/src/editor/editor-warnings/ItemLocked.tsx +63 -0
  75. package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +22 -0
  76. package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +23 -0
  77. package/src/editor/editor-warnings/NoWriteAccess.tsx +15 -0
  78. package/src/editor/editor-warnings/ValidationErrors.tsx +54 -0
  79. package/src/editor/field-types/AttachmentEditor.tsx +9 -0
  80. package/src/editor/field-types/CheckboxEditor.tsx +47 -0
  81. package/src/editor/field-types/DropLinkEditor.tsx +75 -0
  82. package/src/editor/field-types/DropListEditor.tsx +84 -0
  83. package/src/editor/field-types/ImageFieldEditor.tsx +65 -0
  84. package/src/editor/field-types/InternalLinkFieldEditor.tsx +112 -0
  85. package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
  86. package/src/editor/field-types/MultiLineText.tsx +63 -0
  87. package/src/editor/field-types/PictureFieldEditor.tsx +121 -0
  88. package/src/editor/field-types/RawEditor.tsx +53 -0
  89. package/src/editor/field-types/ReactQuill.tsx +580 -0
  90. package/src/editor/field-types/RichTextEditor.tsx +22 -0
  91. package/src/editor/field-types/RichTextEditorComponent.tsx +108 -0
  92. package/src/editor/field-types/SingleLineText.tsx +150 -0
  93. package/src/editor/field-types/TreeListEditor.tsx +261 -0
  94. package/src/editor/fieldTypes.ts +140 -0
  95. package/src/editor/media-selector/AiImageSearch.tsx +186 -0
  96. package/src/editor/media-selector/AiImageSearchPrompt.tsx +95 -0
  97. package/src/editor/media-selector/MediaSelector.tsx +42 -0
  98. package/src/editor/media-selector/Preview.tsx +14 -0
  99. package/src/editor/media-selector/Thumbnails.tsx +48 -0
  100. package/src/editor/media-selector/TreeSelector.tsx +292 -0
  101. package/src/editor/media-selector/UploadZone.tsx +137 -0
  102. package/src/editor/menubar/ActionsMenu.tsx +47 -0
  103. package/src/editor/menubar/ActiveUsers.tsx +17 -0
  104. package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
  105. package/src/editor/menubar/BrowseHistory.tsx +37 -0
  106. package/src/editor/menubar/ItemLanguageVersion.tsx +52 -0
  107. package/src/editor/menubar/LanguageSelector.tsx +152 -0
  108. package/src/editor/menubar/Menu.tsx +83 -0
  109. package/src/editor/menubar/NavButtons.tsx +74 -0
  110. package/src/editor/menubar/PageSelector.tsx +139 -0
  111. package/src/editor/menubar/PageViewerControls.tsx +99 -0
  112. package/src/editor/menubar/Separator.tsx +12 -0
  113. package/src/editor/menubar/SiteInfo.tsx +53 -0
  114. package/src/editor/menubar/User.tsx +27 -0
  115. package/src/editor/menubar/VersionSelector.tsx +143 -0
  116. package/src/editor/page-editor-chrome/CommentHighlighting.tsx +287 -0
  117. package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
  118. package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +44 -0
  119. package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +23 -0
  120. package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +64 -0
  121. package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +35 -0
  122. package/src/editor/page-editor-chrome/FrameMenu.tsx +263 -0
  123. package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
  124. package/src/editor/page-editor-chrome/InlineEditor.tsx +147 -0
  125. package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +61 -0
  126. package/src/editor/page-editor-chrome/NoLayout.tsx +36 -0
  127. package/src/editor/page-editor-chrome/PageEditorChrome.tsx +119 -0
  128. package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +154 -0
  129. package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +171 -0
  130. package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +233 -0
  131. package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
  132. package/src/editor/page-viewer/EditorForm.tsx +247 -0
  133. package/src/editor/page-viewer/MiniMap.tsx +351 -0
  134. package/src/editor/page-viewer/PageViewer.tsx +127 -0
  135. package/src/editor/page-viewer/PageViewerFrame.tsx +1030 -0
  136. package/src/editor/page-viewer/pageViewContext.ts +186 -0
  137. package/src/editor/pageModel.ts +191 -0
  138. package/src/editor/picture-shared.tsx +53 -0
  139. package/src/editor/reviews/Comment.tsx +265 -0
  140. package/src/editor/reviews/Comments.tsx +50 -0
  141. package/src/editor/reviews/PreviewInfo.tsx +35 -0
  142. package/src/editor/reviews/Reviews.tsx +280 -0
  143. package/src/editor/reviews/reviewCommands.tsx +47 -0
  144. package/src/editor/reviews/useReviews.tsx +70 -0
  145. package/src/editor/services/aiService.ts +155 -0
  146. package/src/editor/services/componentDesignerService.ts +151 -0
  147. package/src/editor/services/contentService.ts +159 -0
  148. package/src/editor/services/editService.ts +462 -0
  149. package/src/editor/services/indexService.ts +24 -0
  150. package/src/editor/services/reviewsService.ts +45 -0
  151. package/src/editor/services/serviceHelper.ts +95 -0
  152. package/src/editor/services/systemService.ts +5 -0
  153. package/src/editor/services/translationService.ts +21 -0
  154. package/src/editor/services-server/api.ts +150 -0
  155. package/src/editor/services-server/graphQL.ts +106 -0
  156. package/src/editor/sidebar/ComponentPalette.tsx +146 -0
  157. package/src/editor/sidebar/ComponentTree.tsx +512 -0
  158. package/src/editor/sidebar/ComponentTree2.tsxx +490 -0
  159. package/src/editor/sidebar/Debug.tsx +105 -0
  160. package/src/editor/sidebar/DictionaryEditor.tsx +261 -0
  161. package/src/editor/sidebar/EditHistory.tsx +134 -0
  162. package/src/editor/sidebar/GraphQL.tsx +164 -0
  163. package/src/editor/sidebar/Insert.tsx +35 -0
  164. package/src/editor/sidebar/MainContentTree.tsx +95 -0
  165. package/src/editor/sidebar/Performance.tsx +53 -0
  166. package/src/editor/sidebar/Sessions.tsx +35 -0
  167. package/src/editor/sidebar/Sidebar.tsx +20 -0
  168. package/src/editor/sidebar/SidebarView.tsx +150 -0
  169. package/src/editor/sidebar/Translations.tsx +276 -0
  170. package/src/editor/sidebar/Validation.tsx +102 -0
  171. package/src/editor/sidebar/ViewSelector.tsx +49 -0
  172. package/src/editor/sidebar/Workbox.tsx +209 -0
  173. package/src/editor/ui/CenteredMessage.tsx +7 -0
  174. package/src/editor/ui/CopyToClipboardButton.tsx +23 -0
  175. package/src/editor/ui/DialogButtons.tsx +11 -0
  176. package/src/editor/ui/Icons.tsx +585 -0
  177. package/src/editor/ui/ItemNameDialog.tsx +94 -0
  178. package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
  179. package/src/editor/ui/ItemSearch.tsx +173 -0
  180. package/src/editor/ui/PerfectTree.tsx +550 -0
  181. package/src/editor/ui/Section.tsx +35 -0
  182. package/src/editor/ui/SimpleIconButton.tsx +43 -0
  183. package/src/editor/ui/SimpleMenu.tsx +48 -0
  184. package/src/editor/ui/SimpleTable.tsx +63 -0
  185. package/src/editor/ui/SimpleTabs.tsx +55 -0
  186. package/src/editor/ui/SimpleToolbar.tsx +7 -0
  187. package/src/editor/ui/Spinner.tsx +7 -0
  188. package/src/editor/ui/Splitter.tsx +247 -0
  189. package/src/editor/ui/StackedPanels.tsx +134 -0
  190. package/src/editor/ui/Toolbar.tsx +7 -0
  191. package/src/editor/utils/id-helper.ts +3 -0
  192. package/src/editor/utils/insertOptions.ts +69 -0
  193. package/src/editor/utils/itemutils.ts +29 -0
  194. package/src/editor/utils/useMemoDebug.ts +28 -0
  195. package/src/editor/utils.ts +435 -0
  196. package/src/editor/views/CompareView.tsx +256 -0
  197. package/src/editor/views/EditView.tsx +27 -0
  198. package/src/editor/views/ItemEditor.tsx +58 -0
  199. package/src/editor/views/SingleEditView.tsx +44 -0
  200. package/src/fonts/Geist-Black.woff2 +0 -0
  201. package/src/fonts/Geist-Bold.woff2 +0 -0
  202. package/src/fonts/Geist-ExtraBold.woff2 +0 -0
  203. package/src/fonts/Geist-ExtraLight.woff2 +0 -0
  204. package/src/fonts/Geist-Light.woff2 +0 -0
  205. package/src/fonts/Geist-Medium.woff2 +0 -0
  206. package/src/fonts/Geist-Regular.woff2 +0 -0
  207. package/src/fonts/Geist-SemiBold.woff2 +0 -0
  208. package/src/fonts/Geist-Thin.woff2 +0 -0
  209. package/src/fonts/Geist[wght].woff2 +0 -0
  210. package/src/index.ts +7 -0
  211. package/src/page-wizard/PageWizard.tsx +163 -0
  212. package/src/page-wizard/SelectWizard.tsx +109 -0
  213. package/src/page-wizard/WizardSteps.tsx +207 -0
  214. package/src/page-wizard/service.ts +35 -0
  215. package/src/page-wizard/startPageWizardCommand.ts +27 -0
  216. package/src/page-wizard/steps/BuildPageStep.tsx +266 -0
  217. package/src/page-wizard/steps/CollectStep.tsx +233 -0
  218. package/src/page-wizard/steps/ComponentTypesSelector.tsx +443 -0
  219. package/src/page-wizard/steps/Components.tsx +193 -0
  220. package/src/page-wizard/steps/CreatePage.tsx +285 -0
  221. package/src/page-wizard/steps/CreatePageAndLayoutStep.tsx +384 -0
  222. package/src/page-wizard/steps/EditButton.tsx +34 -0
  223. package/src/page-wizard/steps/FieldEditor.tsx +102 -0
  224. package/src/page-wizard/steps/Generate.tsx +32 -0
  225. package/src/page-wizard/steps/ImagesStep.tsx +318 -0
  226. package/src/page-wizard/steps/LayoutStep.tsx +228 -0
  227. package/src/page-wizard/steps/SelectStep.tsx +256 -0
  228. package/src/page-wizard/steps/schema.ts +180 -0
  229. package/src/page-wizard/steps/usePageCreator.ts +279 -0
  230. package/src/splash-screen/NewPage.tsx +232 -0
  231. package/src/splash-screen/SectionHeadline.tsx +21 -0
  232. package/src/splash-screen/SplashScreen.tsx +156 -0
  233. package/src/tour/Tour.tsx +558 -0
  234. package/src/tour/default-tour.tsx +300 -0
  235. package/src/tour/preview-tour.tsx +127 -0
  236. package/src/types.ts +302 -0
  237. package/styles.css +476 -0
  238. package/tsconfig.build.json +21 -0
  239. package/tsconfig.json +11 -0
@@ -0,0 +1,154 @@
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
+ if (element) {
40
+ const itemId = element.getAttribute("data-itemid");
41
+ const language = element.getAttribute("data-language");
42
+ const version = element.getAttribute("data-version");
43
+ const fieldId = element.getAttribute("data-fieldid");
44
+
45
+ if (
46
+ !itemId ||
47
+ !language ||
48
+ !version ||
49
+ !fieldId ||
50
+ !pageViewContext?.page ||
51
+ !iframe?.contentWindow
52
+ )
53
+ return;
54
+
55
+ const component = getComponentById(itemId, pageViewContext.page!);
56
+
57
+ if (component == null) return;
58
+
59
+ const pictureField = component.datasourceItem?.fields.find(
60
+ (f) => f.id === fieldId
61
+ ) as PictureField;
62
+
63
+ if (!pictureField) return;
64
+
65
+ setField(pictureField);
66
+ } else {
67
+ setField(undefined);
68
+ }
69
+ }, [element, pageViewContext?.page]);
70
+
71
+ useEffect(() => {
72
+ if (!element || !iframe?.contentWindow) return;
73
+
74
+ const sourceELement = getCurrentPictureSource(
75
+ element,
76
+ iframe.contentWindow
77
+ );
78
+
79
+ if (sourceELement) {
80
+ const variantName = sourceELement.getAttribute("data-variant");
81
+
82
+ if (variantName) {
83
+ setVariantName(variantName);
84
+ }
85
+ }
86
+ }, [pageViewContext?.viewport, element]);
87
+
88
+ const handleLoad = () => {
89
+ if (iframe?.contentDocument) {
90
+ iframe.contentDocument.addEventListener("mouseenter", onMouseEnter, true);
91
+ }
92
+ };
93
+
94
+ useEffect(() => {
95
+ if (iframe) {
96
+ // Ensure the iframe is loaded and accessible
97
+ iframe.addEventListener("load", handleLoad);
98
+
99
+ return () => {
100
+ if (iframe?.contentDocument) {
101
+ iframe?.contentDocument.removeEventListener(
102
+ "mouseenter",
103
+ onMouseEnter
104
+ );
105
+ }
106
+
107
+ if (iframe) {
108
+ iframe.removeEventListener("load", handleLoad);
109
+ }
110
+ };
111
+ }
112
+ }, [iframe, editContext?.refreshCompletedFlag]);
113
+
114
+ if (!field || !variantName || !element) return null;
115
+
116
+ const bounds = element.getBoundingClientRect();
117
+
118
+ const style = {
119
+ left: bounds.x + "px",
120
+ top: bounds.y + "px",
121
+ width: bounds.width + "px",
122
+ height: bounds.height + "px",
123
+ };
124
+
125
+ return (
126
+ <PictureEditor
127
+ field={field}
128
+ variantName={variantName}
129
+ style={style}
130
+ forwardScrollevents={true}
131
+ isPageEditor={true}
132
+ />
133
+ );
134
+ }
135
+
136
+ function getCurrentPictureSource(
137
+ pictureElement: HTMLElement,
138
+ iframeWindow: Window
139
+ ): HTMLElement | null {
140
+ if (pictureElement.tagName === "IMG") return pictureElement;
141
+
142
+ const sources = pictureElement.querySelectorAll("source");
143
+ let currentSrc: HTMLSourceElement | null = null;
144
+
145
+ sources.forEach((source) => {
146
+ const media = source.getAttribute("media");
147
+ if (!media) return;
148
+ if (media && iframeWindow.matchMedia(media).matches) {
149
+ currentSrc = source;
150
+ }
151
+ });
152
+
153
+ return currentSrc || pictureElement.querySelector("img") || null;
154
+ }
@@ -0,0 +1,171 @@
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{" "}
68
+ <span className="font-bold">{parentName}</span> /{" "}
69
+ <span className="font-bold">{description || placeholder.name}</span>{" "}
70
+ at position <span className="font-bold">{index + 1}</span>
71
+ </div>
72
+ );
73
+ } else {
74
+ editContext.setStatusMessage("");
75
+ }
76
+ }, [isHovering]);
77
+
78
+ return (
79
+ <div className="absolute" style={overlayStyle}>
80
+ <div
81
+ onDragOver={dragOver}
82
+ title={(description ?? placeholder.name) + " (" + index + ")"}
83
+ data-testid="placeholder-dropzone"
84
+ data-testindex={index}
85
+ onDrop={drop}
86
+ onDragLeave={() => setIsHovering(false)}
87
+ onClick={(e) => {
88
+ //const placeholderKeyComponents = placeholder.key.split("_");
89
+ // const parentId =
90
+ // placeholderKeyComponents.length === 1
91
+ // ? undefined
92
+ // : placeholderKeyComponents[0];
93
+ const insertOption = placeholder.insertOptions.find(
94
+ (x) => x.typeId === editContext.selectedForInsertion
95
+ );
96
+ if (insertOption) {
97
+ editContext!.droppedInPlaceholder(
98
+ placeholder.key,
99
+ index,
100
+ spotPositionElement,
101
+ spotPositionAnchor,
102
+ insertOption
103
+ );
104
+
105
+ return;
106
+ }
107
+ const insertOptions =
108
+ placeholder.insertOptions
109
+ ?.filter((x) => !x.isHidden && !x.isInvalid)
110
+ .map((x) => ({
111
+ id: x.typeId,
112
+ icon: (
113
+ <img
114
+ src={getAbsoluteIconUrl(x.icon)}
115
+ width="16"
116
+ height="16"
117
+ className="m-1"
118
+ />
119
+ ),
120
+ label: x.name,
121
+ command: () => {
122
+ editContext.operations.addComponent(
123
+ x.typeId,
124
+ placeholder.key,
125
+ index
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 (
138
+ <span className="text-black text-sm ">Insert</span>
139
+ );
140
+ },
141
+ },
142
+ ...insertOptions,
143
+ ]);
144
+ e.preventDefault();
145
+ }}
146
+ className="placeholder cursor-pointer placeholder-dropzone"
147
+ >
148
+ <div
149
+ className={classNames(
150
+ isHovering
151
+ ? "z-30 shadow-xl shadow-black w-20 h-20 shadow-blue-500/50"
152
+ : "z-30 w-10 h-10 hover:scale-[1.1]",
153
+ "transition-all duration-200 text-white text-center p-2 text-sm flex justify-center items-center bg-blue-500 rounded-full absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 test-ph-dropzone tour-placeholder-dropzone"
154
+ )}
155
+ data-testid="placeholder-dropzone-button"
156
+ >
157
+ <i className="pi pi-plus block" />
158
+ {/* {isHovering && (
159
+ <div className="flex flex-col items-center">
160
+ {parentName}{" "}
161
+ <div className="text-xs text-gray-500">
162
+ ({description || placeholder.key} {index})
163
+ </div>
164
+ </div>
165
+ )} */}
166
+ </div>
167
+ </div>
168
+ </div>
169
+ // </div>
170
+ );
171
+ }
@@ -0,0 +1,233 @@
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 } 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.compatibleTemplates?.find(
43
+ (z) => z == editContext.dragObject?.typeId
44
+ ) !== undefined ||
45
+ y.typeId === editContext.dragObject?.templateId ||
46
+ y.compatibleTemplates?.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
+ const placeholderElement =
69
+ iframe!.contentWindow?.document.body.querySelector(
70
+ "[data-placeholder-start='" + placeholder.key + "']"
71
+ );
72
+
73
+ if (!placeholderElement) return;
74
+
75
+ const prev = getPreviousElement(placeholderElement);
76
+
77
+ const nextOrParent =
78
+ getNextElement(placeholderElement) || placeholderElement.parentElement;
79
+
80
+ const orientation = placeholderElement?.getAttribute("data-orientation");
81
+
82
+ const rect = (prev ?? nextOrParent)!.getBoundingClientRect();
83
+ const zoom = pageViewContext.zoom;
84
+
85
+ const position =
86
+ orientation === "horizontal"
87
+ ? {
88
+ x: (prev ? rect.x + rect.width : rect.x) * zoom,
89
+ y: (rect.y + rect.height / 2) * zoom,
90
+ }
91
+ : {
92
+ x: (rect.x + rect.width / 2) * zoom,
93
+ y: (prev ? rect.y + rect.height : rect.y) * zoom,
94
+ };
95
+
96
+ let index = 0;
97
+
98
+ const description = placeholderElement.getAttribute("data-description");
99
+
100
+ let anchor: "top" | "bottom" | "left" | "right" = "top";
101
+
102
+ if (prev && orientation === "horizontal") {
103
+ anchor = "right";
104
+ }
105
+ if (prev && orientation !== "horizontal") {
106
+ anchor = "bottom";
107
+ }
108
+ if (!prev && orientation === "horizontal") {
109
+ anchor = "left";
110
+ }
111
+ if (!prev && orientation !== "horizontal") {
112
+ anchor = "top";
113
+ }
114
+
115
+ zones.push({
116
+ placeholder,
117
+ position,
118
+ index,
119
+ element: prev ?? nextOrParent!,
120
+ anchor,
121
+ description,
122
+ });
123
+
124
+ let nextElement = placeholderElement?.nextElementSibling;
125
+ while (nextElement) {
126
+ nextElement = nextElement?.nextElementSibling;
127
+ if (nextElement) {
128
+ if (
129
+ nextElement.getAttribute("data-placeholder-end") === placeholder.key
130
+ ) {
131
+ break;
132
+ }
133
+
134
+ if (nextElement.getAttribute("data-component-end")) {
135
+ const componentRect = findComponentRect(
136
+ iframe,
137
+ (nextElement.getAttribute("data-component-end") ||
138
+ nextElement.getAttribute("data-dropzone"))!
139
+ );
140
+ if (!componentRect) continue;
141
+ const position = getPositionFromRect(
142
+ componentRect.rect,
143
+ pageViewContext.zoom,
144
+ orientation
145
+ );
146
+ index++;
147
+ zones.push({
148
+ placeholder,
149
+ position,
150
+ index,
151
+ anchor: orientation === "horizontal" ? "right" : "bottom",
152
+ element: componentRect.elements[componentRect.elements.length - 1]!,
153
+ });
154
+ } else if (nextElement.getAttribute("data-dropzone")) {
155
+ const rect = nextElement.getBoundingClientRect();
156
+ const position = getPositionFromRect(rect, pageViewContext.zoom);
157
+ index++;
158
+ zones.push({
159
+ placeholder,
160
+ position,
161
+ index,
162
+ anchor: orientation === "horizontal" ? "left" : "top",
163
+ element: nextElement,
164
+ });
165
+ }
166
+ }
167
+ }
168
+ });
169
+
170
+ return zones.map((zone, index) => {
171
+ const x = Math.min(
172
+ pageViewContext.viewport.width - 20,
173
+ Math.max(20, zone.position.x * (scale || 1))
174
+ );
175
+ const y = Math.min(
176
+ scrollHeight - 20,
177
+ Math.max(20 - pageViewContext.scroll, zone.position.y * (scale || 1))
178
+ );
179
+
180
+ return (
181
+ <PlaceholderDropZone
182
+ key={index}
183
+ placeholder={zone.placeholder}
184
+ spotPosition={{
185
+ x,
186
+ y,
187
+ }}
188
+ index={zone.index}
189
+ size={size}
190
+ spotPositionElement={zone.element}
191
+ spotPositionAnchor={zone.anchor}
192
+ parentName={zone.placeholder.parentComponent?.name}
193
+ description={zone.description || undefined}
194
+ />
195
+ );
196
+ });
197
+ }
198
+
199
+ function getPreviousElement(element: Element): Element | null {
200
+ let prev = element.previousElementSibling;
201
+ while (prev && prev.tagName === "SCRIPT") {
202
+ prev = prev.previousElementSibling;
203
+ }
204
+ return prev;
205
+ }
206
+
207
+ function getNextElement(element: Element): Element | null {
208
+ let next = element.nextElementSibling;
209
+
210
+ while (next && next.tagName === "SCRIPT") {
211
+ next = next.nextElementSibling;
212
+ }
213
+ return next;
214
+ }
215
+
216
+ function getPositionFromRect(
217
+ rect: { x: number; y: number; width: number; height: number },
218
+ zoom: number,
219
+ orientation?: string | null
220
+ ) {
221
+ const position =
222
+ orientation === "horizontal"
223
+ ? {
224
+ x: rect.x + rect.width * zoom,
225
+ y: (rect.y + rect.height / 2) * zoom,
226
+ }
227
+ : {
228
+ x: (rect.x + rect.width / 2) * zoom,
229
+ y: rect.y + rect.height * zoom,
230
+ };
231
+
232
+ return position;
233
+ }
@@ -0,0 +1,70 @@
1
+ import { Dropdown } from "primereact/dropdown";
2
+ import { InputNumber } from "primereact/inputnumber";
3
+ import { SimpleIconButton } from "../ui/SimpleIconButton";
4
+ import { RotateDeviceIcon } from "../ui/Icons";
5
+ import { useDebouncedCallback } from "use-debounce";
6
+ import { PageViewContext } from "./pageViewContext";
7
+ import { EditorConfiguration } from "../../config/types";
8
+
9
+ export function DeviceToolbar({
10
+ pageViewContext,
11
+ configuration,
12
+ }: {
13
+ pageViewContext: PageViewContext;
14
+ configuration: EditorConfiguration;
15
+ }) {
16
+ const debouncedSetDeviceWidth = useDebouncedCallback(
17
+ (width: number | undefined) => {
18
+ pageViewContext.setDeviceWidth(width);
19
+ },
20
+ 400
21
+ );
22
+ const debouncedSetDeviceHeight = useDebouncedCallback(
23
+ (height: number | undefined) => {
24
+ pageViewContext.setDeviceHeight(height);
25
+ },
26
+ 400
27
+ );
28
+
29
+ return (
30
+ <div className="flex justify-center w-full items-center bg-gray-100 p-1 z-1000 text-sm gap-2 border-b">
31
+ <Dropdown
32
+ options={configuration.devices.map((x) => ({
33
+ label: x.name,
34
+ value: x.name,
35
+ }))}
36
+ value={pageViewContext.device}
37
+ onChange={(e) => pageViewContext.setDevice(e.value)}
38
+ />
39
+ <InputNumber
40
+ size={4}
41
+ max={10000}
42
+ className="text-sm"
43
+ value={pageViewContext.deviceWidth}
44
+ onChange={(e) => debouncedSetDeviceWidth(e.value || undefined)}
45
+ />
46
+ x
47
+ <InputNumber
48
+ size={4}
49
+ max={10000}
50
+ className="text-sm"
51
+ value={pageViewContext.deviceHeight}
52
+ onChange={(e) => debouncedSetDeviceHeight(e.value || undefined)}
53
+ />
54
+ <SimpleIconButton
55
+ icon="pi pi-lock"
56
+ selected={pageViewContext.lockHeight || false}
57
+ onClick={() =>
58
+ pageViewContext.setLockHeight(!pageViewContext.lockHeight)
59
+ }
60
+ label="Lock Height"
61
+ />
62
+ <SimpleIconButton
63
+ icon={<RotateDeviceIcon className="w-4 h-4" />}
64
+ selected={pageViewContext.rotate || false}
65
+ onClick={() => pageViewContext.setRotate(!pageViewContext.rotate)}
66
+ label="Rotate"
67
+ />
68
+ </div>
69
+ );
70
+ }