@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,155 @@
1
+ import { MenuItem, MenuItemCommandEvent } from "primereact/menuitem";
2
+
3
+ import { EditContextType } from "./client/editContext";
4
+ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
5
+ import { ContextMenu } from "primereact/contextmenu";
6
+
7
+ import { FieldDescriptor } from "../types";
8
+ import { Component, FieldButton } from "./pageModel";
9
+
10
+ // export function getFieldContextMenu(
11
+ // field: Field,
12
+ // editContext: EditContextType,
13
+ // customButtons: EditButton[] = []
14
+ // ) {
15
+ // return (e: any) => {
16
+ // e.preventDefault();
17
+ // e.stopPropagation();
18
+ // const menuItems: MenuItem[] = getComponentMenuItems(
19
+ // editContext,
20
+ // getComponentById(field._editor!.descriptor.item.id, editContext.page!)!
21
+ // );
22
+
23
+ // if (customButtons.length) {
24
+ // if (menuItems.length)
25
+ // menuItems.push({
26
+ // separator: true,
27
+ // });
28
+
29
+ // customButtons.forEach((button) => {
30
+ // menuItems.push({
31
+ // label: button.label,
32
+ // command: (ev) => button.onClick(ev.originalEvent as any),
33
+ // icon: button.icon,
34
+ // });
35
+ // });
36
+ // }
37
+
38
+ // if (field._editor?.buttons?.length) {
39
+ // if (menuItems.length)
40
+ // menuItems.push({
41
+ // separator: true,
42
+ // });
43
+
44
+ // field._editor?.buttons.forEach((button: FieldButton) => {
45
+ // menuItems.push({
46
+ // label: button.label,
47
+ // command: () => {
48
+ // editContext!.triggerFieldAction(field._editor!.descriptor, button);
49
+ // },
50
+ // icon: button.icon ? "pi " + button.icon : undefined,
51
+ // });
52
+ // });
53
+ // }
54
+
55
+ // if (!e.ctrlKey && !e.shiftKey && !e.altKey && menuItems.length) {
56
+ // editContext.select([field._editor!.descriptor.item.id]);
57
+ // editContext!.setFocusedField(field._editor!.descriptor, false);
58
+ // editContext!.showContextMenu(e, menuItems);
59
+ // }
60
+ // };
61
+ // }
62
+
63
+ export function showComponentContextMenu(
64
+ components: Component[],
65
+ editContext: EditContextType,
66
+ field?: FieldDescriptor,
67
+ fieldButtons?: FieldButton[]
68
+ ) {
69
+ const componentCommandMenuItems = getComponentMenuItems(
70
+ editContext,
71
+ components
72
+ );
73
+
74
+ const menuItems = componentCommandMenuItems;
75
+
76
+ if (!editContext.readonly && field && fieldButtons?.length) {
77
+ if (menuItems.length)
78
+ menuItems.push({
79
+ separator: true,
80
+ });
81
+
82
+ fieldButtons.forEach((button) => {
83
+ menuItems.push({
84
+ label: button.label,
85
+ command: () => {
86
+ editContext!.triggerFieldAction(field, button);
87
+ },
88
+ icon: button.icon ? "pi " + button.icon : undefined,
89
+ });
90
+ });
91
+ }
92
+
93
+ return (e: any) => {
94
+ if (!e.shiftKey && !e.altKey) {
95
+ if(menuItems.length) {
96
+
97
+ // editContext.select([component.id]);
98
+ editContext!.showContextMenu(e, menuItems);
99
+ }
100
+
101
+ return true;
102
+ }
103
+ return false;
104
+ };
105
+ }
106
+
107
+ export interface EditContextMenuRef {
108
+ show: (event: any, menuItems: MenuItem[]) => void;
109
+ close: (event: any) => void;
110
+ }
111
+
112
+ interface EditContextMenuProps {}
113
+
114
+ export const EditContextMenu = forwardRef<
115
+ EditContextMenuRef,
116
+ EditContextMenuProps
117
+ >((props, ref) => {
118
+ const cm = useRef<ContextMenu>(null);
119
+ const [menuItems, setMenuItems] = useState<MenuItem[]>([]);
120
+ if (!props) return;
121
+ useImperativeHandle(ref, () => ({
122
+ show: (e: any, items: MenuItem[]) => {
123
+ if (!e.ctrlKey && !e.shiftKey && !e.altKey) {
124
+ setMenuItems(items);
125
+ e.preventDefault();
126
+ cm.current?.show(e);
127
+ }
128
+ },
129
+ close: (event: any) => {
130
+ cm.current?.hide(event);
131
+ },
132
+ }));
133
+
134
+ return <ContextMenu model={menuItems} ref={cm} />;
135
+ });
136
+ function getComponentMenuItems(
137
+ editContext: EditContextType,
138
+ components: Component[]
139
+ ): MenuItem[] {
140
+ const componentCommands = editContext.getComponentCommands(components);
141
+
142
+ const componentCommandMenuItems = componentCommands.map((x) => {
143
+ return {
144
+ label: x.label,
145
+ icon: x.icon,
146
+ command: (ev: MenuItemCommandEvent) =>
147
+ editContext.executeCommand({
148
+ command: x,
149
+ event: ev.originalEvent,
150
+ }),
151
+ disabled: editContext.isCommandDisabled({ command: x }),
152
+ };
153
+ });
154
+ return componentCommandMenuItems;
155
+ }
@@ -0,0 +1,91 @@
1
+ "use client";
2
+
3
+ import { EditorClient } from "./client/EditorClient";
4
+ import { DialogProvider } from "./client/DialogContext";
5
+ import { ItemDescriptor } from "./pageModel";
6
+ import { EditorConfiguration } from "../config/types";
7
+ import { useEffect, useState } from "react";
8
+ import { SystemStatus } from "../types";
9
+ import { User } from "../types";
10
+ import { getUserInfo } from "./services/editService";
11
+ import { getSystemStatus } from "./services/systemService";
12
+ import uuid from "react-uuid";
13
+ import { getConfiguration } from "../config/config";
14
+
15
+ export function Editor({
16
+ configure,
17
+ className,
18
+ page,
19
+ }: {
20
+ configure: (props: {
21
+ configuration: EditorConfiguration;
22
+ user: User;
23
+ }) => EditorConfiguration;
24
+ className?: string;
25
+ page?: ItemDescriptor;
26
+ }) {
27
+ const [config, setConfig] = useState<EditorConfiguration>();
28
+ const [userInfo, setUserInfo] = useState<User>();
29
+ const [systemStatus, setSystemStatus] = useState<SystemStatus>();
30
+
31
+ const sessionId =
32
+ typeof window !== "undefined"
33
+ ? sessionStorage.getItem("sessionId") || uuid()
34
+ : uuid();
35
+
36
+ useEffect(() => {
37
+ // Get user info and system status
38
+ getUserInfo().then((userInfo) => {
39
+ if (!userInfo) {
40
+ window.location.href = "/sitecore/login";
41
+ return;
42
+ }
43
+ setUserInfo(userInfo);
44
+ });
45
+
46
+ getSystemStatus().then((status) => {
47
+ if (status.data) {
48
+ setSystemStatus(status.data);
49
+ }
50
+ });
51
+ }, []);
52
+
53
+ useEffect(() => {
54
+ if (!userInfo || !systemStatus) return;
55
+
56
+ const config = configure({
57
+ configuration: getConfiguration(),
58
+ user: userInfo,
59
+ });
60
+ setConfig(config);
61
+ }, [userInfo, systemStatus]);
62
+
63
+ if (!userInfo || !systemStatus) return null;
64
+
65
+ if (systemStatus.messages.some((m) => m.severity === "error")) {
66
+ return (
67
+ <div className="fixed inset-0 flex flex-col items-center justify-center gap-2 text-sm">
68
+ <h1 className="text-2xl">Please fix the following issues:</h1>
69
+ <div className="text-sm text-red-500">
70
+ {systemStatus.messages.map((m) => (
71
+ <div key={m.message}>{m.message}</div>
72
+ ))}
73
+ </div>
74
+ <p>Check the logs for more details.</p>
75
+ </div>
76
+ );
77
+ }
78
+
79
+ if (!config) return null;
80
+
81
+ return (
82
+ <DialogProvider>
83
+ <EditorClient
84
+ configuration={config}
85
+ className={className}
86
+ item={page}
87
+ sessionId={sessionId}
88
+ ></EditorClient>
89
+ </DialogProvider>
90
+ );
91
+ }
@@ -0,0 +1,34 @@
1
+ import { classNames } from "primereact/utils";
2
+
3
+ export function EditorWarning({
4
+ title,
5
+ severity = "warning",
6
+ children,
7
+ }: {
8
+ title: string;
9
+ severity?: "info" | "error" | "warning";
10
+ children: React.ReactNode;
11
+ }) {
12
+ const background =
13
+ severity === "info"
14
+ ? "bg-blue-100"
15
+ : severity === "error"
16
+ ? "bg-red-100"
17
+ : "bg-yellow-100";
18
+ return (
19
+ <div
20
+ className={classNames(
21
+ background,
22
+ "text-sm text-gray-500 border-b border-yellow-300 flex gap-2 items-stretch"
23
+ )}
24
+ >
25
+ <div className="bg-yellow-200 px-4 flex items-center text-gray-900">
26
+ <span className="pi pi-exclamation-triangle text-2xl" />
27
+ </div>
28
+ <div className="p-2">
29
+ <div className="font-bold">{title}</div>
30
+ <div className="text-xs">{children}</div>
31
+ </div>
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+
3
+ import { EditContextType, useEditContext } from "./client/editContext";
4
+
5
+ import { FullItem } from "./pageModel";
6
+
7
+ export type EditorWarningProps = {
8
+ item: FullItem;
9
+ editContext: EditContextType;
10
+ };
11
+
12
+ export function EditorWarnings({ item }: { item?: FullItem }) {
13
+ var context = useEditContext();
14
+ if (!context || context.previewMode) return;
15
+
16
+ if (!item) {
17
+ item = context.page?.item;
18
+ }
19
+
20
+ if (!item) return;
21
+
22
+ return (
23
+ <div className="z-50 w-full">
24
+ {context.configuration.editorWarnings.map((x, i) =>
25
+ React.createElement(x, {
26
+ item,
27
+ key: "warning" + i,
28
+ editContext: context!,
29
+ })
30
+ )}
31
+ </div>
32
+ );
33
+ }
@@ -0,0 +1,65 @@
1
+ "use client";
2
+
3
+ import { OverlayPanel } from "primereact/overlaypanel";
4
+ import {
5
+ SyntheticEvent,
6
+ forwardRef,
7
+ useImperativeHandle,
8
+ useRef,
9
+ useState,
10
+ } from "react";
11
+
12
+ import { FieldList } from "./FieldList";
13
+ import { Field } from "./pageModel";
14
+
15
+ export interface FieldEditorPopupRef {
16
+ show: (fields: Field[], sections: string[], event: SyntheticEvent) => void;
17
+ close: () => void;
18
+ }
19
+
20
+ interface FieldEditorPopupProps {}
21
+
22
+ export const FieldEditorPopup = forwardRef<
23
+ FieldEditorPopupRef,
24
+ FieldEditorPopupProps
25
+ >((_, ref) => {
26
+ const overlayRef = useRef<OverlayPanel>(null);
27
+
28
+ const [sections, setSections] = useState<string[]>([]);
29
+ const [fields, setFields] = useState<Field[]>([]);
30
+
31
+ useImperativeHandle(ref, () => ({
32
+ show: (fields: Field[], sections: string[], ev: SyntheticEvent) => {
33
+ setFields(fields);
34
+ setSections(sections);
35
+ overlayRef.current?.toggle(ev, ev.target);
36
+ },
37
+ close: () => {
38
+ overlayRef.current?.hide();
39
+ },
40
+ }));
41
+
42
+ return (
43
+ <OverlayPanel ref={overlayRef}>
44
+ <div
45
+ className="w-96 h-96 flex flex-col gap-2 overflow-auto"
46
+ onClick={(ev) => ev.stopPropagation()}
47
+ >
48
+ <div className="flex justify-end p-3">
49
+ <i
50
+ className="pi pi-times cursor-pointer"
51
+ onClick={() => overlayRef?.current?.hide()}
52
+ />
53
+ </div>
54
+
55
+ {fields && (
56
+ <FieldList
57
+ fields={[{ fields }]}
58
+ sections={sections}
59
+ validators={[]}
60
+ />
61
+ )}
62
+ </div>
63
+ </OverlayPanel>
64
+ );
65
+ });
@@ -0,0 +1,74 @@
1
+ import { Field } from "../editor/pageModel";
2
+ import { FieldHistoryItem } from "../types";
3
+ import { getFieldHistory } from "../editor/services/editService";
4
+ import { useEffect } from "react";
5
+ import { useState } from "react";
6
+
7
+ import { useEditContext } from "./client/editContext";
8
+ import { formatDate } from "./utils";
9
+ import { SimpleTable } from "./ui/SimpleTable";
10
+ import { SimpleIconButton } from "./ui/SimpleIconButton";
11
+
12
+ export function FieldHistory({
13
+ field,
14
+ onHover,
15
+ }: {
16
+ field: Field;
17
+ onHover: (historyEntry: FieldHistoryItem | undefined) => void;
18
+ }) {
19
+ const [fieldHistory, setFieldHistory] = useState<FieldHistoryItem[]>([]);
20
+ const editContext = useEditContext();
21
+
22
+ if (!editContext) {
23
+ return null;
24
+ }
25
+
26
+ useEffect(() => {
27
+ getFieldHistory(field.descriptor.item, field.id).then((result) => {
28
+ setFieldHistory(result.data ?? []);
29
+ });
30
+ }, [field]);
31
+
32
+ if (fieldHistory.length === 0)
33
+ return <div className="p-2 text-gray-500 text-xs">No history</div>;
34
+
35
+ return (
36
+ <div>
37
+ <div className="text-xs p-2 bg-gray-100 text-gray-500">
38
+ Field History
39
+ </div>
40
+ <div className="max-h-96 overflow-auto">
41
+ <SimpleTable
42
+ items={fieldHistory}
43
+ onRowHover={onHover}
44
+ rowClassName={(x) =>
45
+ x.undone
46
+ ? "text-gray-300 cursor-pointer hover:bg-gray-50 "
47
+ : "cursor-pointer hover:bg-gray-50"
48
+ }
49
+ columns={[
50
+ { header: "Date", body: (x) => formatDate(new Date(x.date)) },
51
+ { header: "User", body: (x) => x.user },
52
+ { header: "Version", body: (x) => x.version },
53
+ {
54
+ header: "Revert",
55
+ body: (x) => (
56
+ <SimpleIconButton
57
+ icon="pi pi-undo"
58
+ onClick={() =>
59
+ editContext.operations.editField({
60
+ field: field.descriptor,
61
+ rawValue: x.rawValue,
62
+ refresh: "immediate",
63
+ })
64
+ }
65
+ label="Revert"
66
+ />
67
+ ),
68
+ },
69
+ ]}
70
+ />
71
+ </div>
72
+ </div>
73
+ );
74
+ }
@@ -0,0 +1,190 @@
1
+ "use client";
2
+
3
+ import { Section } from "./ui/Section";
4
+ import { useEditContext } from "./client/editContext";
5
+ import { FieldListFieldWithFallbacks } from "./FieldListFieldWithFallbacks";
6
+ import { SingleValidatorResult } from "../types";
7
+ import { Field } from "./pageModel";
8
+ import { InputText } from "primereact/inputtext";
9
+ import { Fragment, useState } from "react";
10
+ import { Checkbox } from "primereact/checkbox";
11
+ import uuid from "react-uuid";
12
+ import { SimpleIconButton } from "./ui/SimpleIconButton";
13
+
14
+ export type ItemFields = {
15
+ headline?: string;
16
+ fields: Field[];
17
+ };
18
+
19
+ export function FieldList({
20
+ fields,
21
+ compareToFields,
22
+ sections,
23
+ validators,
24
+ filter,
25
+ simplified,
26
+ showStandardFieldsEnabled,
27
+ readonly,
28
+ }: {
29
+ fields: ItemFields[];
30
+ compareToFields?: Field[];
31
+ sections?: string[];
32
+ validators: SingleValidatorResult[];
33
+ filter?: (field: Field) => boolean;
34
+ simplified?: boolean;
35
+ showStandardFieldsEnabled?: boolean;
36
+ readonly?: boolean;
37
+ }) {
38
+ const editContext = useEditContext();
39
+
40
+ const [searchFilter, setSearchFilter] = useState<string>("");
41
+ const [showStandardFields, setShowStandardFields] = useState<boolean>(false);
42
+ const uniqueId = uuid();
43
+
44
+ if (!editContext) return;
45
+ if (!fields) return;
46
+
47
+ return (
48
+ <div>
49
+ <div className="sticky bg-gray-50 top-0 z-10 flex gap-2 border-y border-gray-200 items-center p-2 tour-field-list">
50
+ <i className="pi pi-search" />
51
+ <div className="text-xs">Filter</div>
52
+ <InputText
53
+ className="flex-1 text-xs"
54
+ value={searchFilter}
55
+ onChange={(x) => setSearchFilter(x.target.value)}
56
+ />
57
+ {searchFilter && (
58
+ <SimpleIconButton
59
+ icon="pi pi-times"
60
+ onClick={() => setSearchFilter("")}
61
+ className="text-xs"
62
+ label="Clear"
63
+ />
64
+ )}
65
+ {showStandardFieldsEnabled && (
66
+ <>
67
+ <Checkbox
68
+ inputId={uniqueId}
69
+ checked={showStandardFields}
70
+ onChange={(e: any) => setShowStandardFields(e.checked)}
71
+ />{" "}
72
+ <label htmlFor={uniqueId} className="text-xs cursor-pointer">
73
+ Show standard fields
74
+ </label>
75
+ </>
76
+ )}
77
+ </div>
78
+
79
+ {fields.map((itemFields, index) => (
80
+ <Fragment key={index}>
81
+ {itemFields.headline && (
82
+ <div className="text-sm mt-2 py-2 border-b flex items-center gap-1">
83
+ <i className="pi pi-angle-right" /> {itemFields.headline}
84
+ </div>
85
+ )}
86
+ <FieldListForSingleItem
87
+ key={index}
88
+ fields={itemFields.fields}
89
+ validators={validators}
90
+ filter={filter}
91
+ searchFilter={searchFilter}
92
+ showStandardFields={showStandardFields}
93
+ simplified={simplified}
94
+ sections={sections}
95
+ compareToFields={compareToFields}
96
+ readonly={readonly}
97
+ />
98
+ </Fragment>
99
+ ))}
100
+ </div>
101
+ );
102
+ }
103
+
104
+ function FieldListForSingleItem({
105
+ fields,
106
+ validators,
107
+ filter,
108
+ searchFilter,
109
+ simplified,
110
+ sections,
111
+ showStandardFields,
112
+ compareToFields,
113
+ readonly,
114
+ }: {
115
+ fields: Field[];
116
+ validators: SingleValidatorResult[];
117
+ filter?: (field: Field) => boolean;
118
+ searchFilter?: string;
119
+ simplified?: boolean;
120
+ sections?: string[];
121
+ showStandardFields?: boolean;
122
+ compareToFields?: Field[];
123
+ readonly?: boolean;
124
+ }) {
125
+ let fieldsArray = Array.isArray(fields)
126
+ ? (fields as Field[])
127
+ : (Object.values(fields) as Field[]);
128
+
129
+ if (filter) fieldsArray = fieldsArray.filter(filter);
130
+
131
+ if (searchFilter) {
132
+ const searchFilterLower = searchFilter.toLowerCase();
133
+ fieldsArray = fieldsArray.filter(
134
+ (x) =>
135
+ x.name?.toLowerCase().includes(searchFilterLower) ||
136
+ x.displayName?.toLowerCase().includes(searchFilterLower)
137
+ );
138
+ }
139
+
140
+ if (!showStandardFields) {
141
+ fieldsArray = fieldsArray.filter((x) => !x.name?.startsWith("__"));
142
+ }
143
+
144
+ const sectionsGrouping = fieldsArray.reduce((acc, value) => {
145
+ // Group initialization
146
+ const section = value.section || "Default";
147
+
148
+ if (value.descriptor.item.id)
149
+ if (!acc[section]) {
150
+ acc[section] = [];
151
+ }
152
+ // Grouping
153
+ acc[section].push(value);
154
+
155
+ return acc;
156
+ }, {} as any);
157
+
158
+ const sectionList: Field[][] = Object.values(sectionsGrouping);
159
+ sectionList.sort(
160
+ (a: Field[], b: Field[]) =>
161
+ (a[0]?.sectionSortOrder || 0) - (b[0]?.sectionSortOrder || 0)
162
+ );
163
+
164
+ function getSectionFields(fields: Field[]) {
165
+ fields.sort((a: any, b: any) => a?.sortOrder - b?.sortOrder);
166
+
167
+ return fields.map((field) => (
168
+ <FieldListFieldWithFallbacks
169
+ key={field.id}
170
+ fieldDescriptor={field.descriptor}
171
+ simplified={simplified}
172
+ validators={validators.filter((x) => x.fieldId === field.id)}
173
+ compareToField={compareToFields?.find((x) => x.id === field.id)}
174
+ readonly={readonly}
175
+ />
176
+ ));
177
+ }
178
+ return sectionList
179
+ .map((x) => x[0]?.section)
180
+ .filter((x) => !sections || sections.includes(x!))
181
+ .map((section) =>
182
+ simplified ? (
183
+ getSectionFields(sectionsGrouping[section!])
184
+ ) : (
185
+ <Section key={section} title={section!}>
186
+ {getSectionFields(sectionsGrouping[section!])}
187
+ </Section>
188
+ )
189
+ );
190
+ }