@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.
- package/.prettierrc +3 -0
- package/eslint.config.mjs +4 -0
- package/images/bg-shape-black.webp +0 -0
- package/package.json +52 -0
- package/src/client-components/api.ts +6 -0
- package/src/client-components/index.ts +19 -0
- package/src/components/ActionButton.tsx +43 -0
- package/src/components/Error.tsx +57 -0
- package/src/config/config.tsx +737 -0
- package/src/config/types.ts +263 -0
- package/src/editor/ComponentInfo.tsx +77 -0
- package/src/editor/ConfirmationDialog.tsx +103 -0
- package/src/editor/ContentTree.tsx +654 -0
- package/src/editor/ContextMenu.tsx +155 -0
- package/src/editor/Editor.tsx +91 -0
- package/src/editor/EditorWarning.tsx +34 -0
- package/src/editor/EditorWarnings.tsx +33 -0
- package/src/editor/FieldEditorPopup.tsx +65 -0
- package/src/editor/FieldHistory.tsx +74 -0
- package/src/editor/FieldList.tsx +190 -0
- package/src/editor/FieldListField.tsx +387 -0
- package/src/editor/FieldListFieldWithFallbacks.tsx +211 -0
- package/src/editor/FloatingToolbar.tsx +163 -0
- package/src/editor/ImageEditor.tsx +129 -0
- package/src/editor/InsertMenu.tsx +332 -0
- package/src/editor/ItemInfo.tsx +90 -0
- package/src/editor/LinkEditorDialog.tsx +192 -0
- package/src/editor/MainLayout.tsx +94 -0
- package/src/editor/NewEditorClient.tsx +11 -0
- package/src/editor/PictureCropper.tsx +505 -0
- package/src/editor/PictureEditor.tsx +206 -0
- package/src/editor/PictureEditorDialog.tsx +381 -0
- package/src/editor/PublishDialog.ignore +74 -0
- package/src/editor/ScrollingContentTree.tsx +47 -0
- package/src/editor/Terminal.tsx +215 -0
- package/src/editor/Titlebar.tsx +23 -0
- package/src/editor/ai/AiPopup.tsx +59 -0
- package/src/editor/ai/AiResponseMessage.tsx +82 -0
- package/src/editor/ai/AiTerminal.tsx +450 -0
- package/src/editor/ai/AiToolCall.tsx +46 -0
- package/src/editor/ai/EditorAiTerminal.tsx +20 -0
- package/src/editor/ai/editorAiContext.ts +18 -0
- package/src/editor/client/DialogContext.tsx +49 -0
- package/src/editor/client/EditorClient.tsx +1831 -0
- package/src/editor/client/GenericDialog.tsx +50 -0
- package/src/editor/client/editContext.ts +330 -0
- package/src/editor/client/helpers.ts +44 -0
- package/src/editor/client/itemsRepository.ts +391 -0
- package/src/editor/client/operations.ts +610 -0
- package/src/editor/client/pageModelBuilder.ts +182 -0
- package/src/editor/commands/commands.ts +23 -0
- package/src/editor/commands/componentCommands.tsx +408 -0
- package/src/editor/commands/createVersionCommand.ts +33 -0
- package/src/editor/commands/deleteVersionCommand.ts +71 -0
- package/src/editor/commands/itemCommands.tsx +186 -0
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
- package/src/editor/commands/undo.ts +39 -0
- package/src/editor/component-designer/ComponentDesigner.tsx +70 -0
- package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +11 -0
- package/src/editor/component-designer/ComponentDesignerMenu.tsx +91 -0
- package/src/editor/component-designer/ComponentEditor.tsx +97 -0
- package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +31 -0
- package/src/editor/component-designer/ComponentRenderingEditor.tsx +104 -0
- package/src/editor/component-designer/ComponentsDropdown.tsx +39 -0
- package/src/editor/component-designer/PlaceholdersEditor.tsx +183 -0
- package/src/editor/component-designer/RenderingsDropdown.tsx +36 -0
- package/src/editor/component-designer/TemplateEditor.tsx +236 -0
- package/src/editor/component-designer/aiContext.ts +23 -0
- package/src/editor/componentTreeHelper.tsx +114 -0
- package/src/editor/control-center/ControlCenterMenu.tsx +71 -0
- package/src/editor/control-center/IndexOverview.tsx +50 -0
- package/src/editor/control-center/IndexSettings.tsx +266 -0
- package/src/editor/control-center/Status.tsx +7 -0
- package/src/editor/editor-warnings/ItemLocked.tsx +63 -0
- package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +22 -0
- package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +23 -0
- package/src/editor/editor-warnings/NoWriteAccess.tsx +15 -0
- package/src/editor/editor-warnings/ValidationErrors.tsx +54 -0
- package/src/editor/field-types/AttachmentEditor.tsx +9 -0
- package/src/editor/field-types/CheckboxEditor.tsx +47 -0
- package/src/editor/field-types/DropLinkEditor.tsx +75 -0
- package/src/editor/field-types/DropListEditor.tsx +84 -0
- package/src/editor/field-types/ImageFieldEditor.tsx +65 -0
- package/src/editor/field-types/InternalLinkFieldEditor.tsx +112 -0
- package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
- package/src/editor/field-types/MultiLineText.tsx +63 -0
- package/src/editor/field-types/PictureFieldEditor.tsx +121 -0
- package/src/editor/field-types/RawEditor.tsx +53 -0
- package/src/editor/field-types/ReactQuill.tsx +580 -0
- package/src/editor/field-types/RichTextEditor.tsx +22 -0
- package/src/editor/field-types/RichTextEditorComponent.tsx +108 -0
- package/src/editor/field-types/SingleLineText.tsx +150 -0
- package/src/editor/field-types/TreeListEditor.tsx +261 -0
- package/src/editor/fieldTypes.ts +140 -0
- package/src/editor/media-selector/AiImageSearch.tsx +186 -0
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +95 -0
- package/src/editor/media-selector/MediaSelector.tsx +42 -0
- package/src/editor/media-selector/Preview.tsx +14 -0
- package/src/editor/media-selector/Thumbnails.tsx +48 -0
- package/src/editor/media-selector/TreeSelector.tsx +292 -0
- package/src/editor/media-selector/UploadZone.tsx +137 -0
- package/src/editor/menubar/ActionsMenu.tsx +47 -0
- package/src/editor/menubar/ActiveUsers.tsx +17 -0
- package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
- package/src/editor/menubar/BrowseHistory.tsx +37 -0
- package/src/editor/menubar/ItemLanguageVersion.tsx +52 -0
- package/src/editor/menubar/LanguageSelector.tsx +152 -0
- package/src/editor/menubar/Menu.tsx +83 -0
- package/src/editor/menubar/NavButtons.tsx +74 -0
- package/src/editor/menubar/PageSelector.tsx +139 -0
- package/src/editor/menubar/PageViewerControls.tsx +99 -0
- package/src/editor/menubar/Separator.tsx +12 -0
- package/src/editor/menubar/SiteInfo.tsx +53 -0
- package/src/editor/menubar/User.tsx +27 -0
- package/src/editor/menubar/VersionSelector.tsx +143 -0
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +287 -0
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +44 -0
- package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +23 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +64 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +35 -0
- package/src/editor/page-editor-chrome/FrameMenu.tsx +263 -0
- package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
- package/src/editor/page-editor-chrome/InlineEditor.tsx +147 -0
- package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +61 -0
- package/src/editor/page-editor-chrome/NoLayout.tsx +36 -0
- package/src/editor/page-editor-chrome/PageEditorChrome.tsx +119 -0
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +154 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +171 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +233 -0
- package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
- package/src/editor/page-viewer/EditorForm.tsx +247 -0
- package/src/editor/page-viewer/MiniMap.tsx +351 -0
- package/src/editor/page-viewer/PageViewer.tsx +127 -0
- package/src/editor/page-viewer/PageViewerFrame.tsx +1030 -0
- package/src/editor/page-viewer/pageViewContext.ts +186 -0
- package/src/editor/pageModel.ts +191 -0
- package/src/editor/picture-shared.tsx +53 -0
- package/src/editor/reviews/Comment.tsx +265 -0
- package/src/editor/reviews/Comments.tsx +50 -0
- package/src/editor/reviews/PreviewInfo.tsx +35 -0
- package/src/editor/reviews/Reviews.tsx +280 -0
- package/src/editor/reviews/reviewCommands.tsx +47 -0
- package/src/editor/reviews/useReviews.tsx +70 -0
- package/src/editor/services/aiService.ts +155 -0
- package/src/editor/services/componentDesignerService.ts +151 -0
- package/src/editor/services/contentService.ts +159 -0
- package/src/editor/services/editService.ts +462 -0
- package/src/editor/services/indexService.ts +24 -0
- package/src/editor/services/reviewsService.ts +45 -0
- package/src/editor/services/serviceHelper.ts +95 -0
- package/src/editor/services/systemService.ts +5 -0
- package/src/editor/services/translationService.ts +21 -0
- package/src/editor/services-server/api.ts +150 -0
- package/src/editor/services-server/graphQL.ts +106 -0
- package/src/editor/sidebar/ComponentPalette.tsx +146 -0
- package/src/editor/sidebar/ComponentTree.tsx +512 -0
- package/src/editor/sidebar/ComponentTree2.tsxx +490 -0
- package/src/editor/sidebar/Debug.tsx +105 -0
- package/src/editor/sidebar/DictionaryEditor.tsx +261 -0
- package/src/editor/sidebar/EditHistory.tsx +134 -0
- package/src/editor/sidebar/GraphQL.tsx +164 -0
- package/src/editor/sidebar/Insert.tsx +35 -0
- package/src/editor/sidebar/MainContentTree.tsx +95 -0
- package/src/editor/sidebar/Performance.tsx +53 -0
- package/src/editor/sidebar/Sessions.tsx +35 -0
- package/src/editor/sidebar/Sidebar.tsx +20 -0
- package/src/editor/sidebar/SidebarView.tsx +150 -0
- package/src/editor/sidebar/Translations.tsx +276 -0
- package/src/editor/sidebar/Validation.tsx +102 -0
- package/src/editor/sidebar/ViewSelector.tsx +49 -0
- package/src/editor/sidebar/Workbox.tsx +209 -0
- package/src/editor/ui/CenteredMessage.tsx +7 -0
- package/src/editor/ui/CopyToClipboardButton.tsx +23 -0
- package/src/editor/ui/DialogButtons.tsx +11 -0
- package/src/editor/ui/Icons.tsx +585 -0
- package/src/editor/ui/ItemNameDialog.tsx +94 -0
- package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
- package/src/editor/ui/ItemSearch.tsx +173 -0
- package/src/editor/ui/PerfectTree.tsx +550 -0
- package/src/editor/ui/Section.tsx +35 -0
- package/src/editor/ui/SimpleIconButton.tsx +43 -0
- package/src/editor/ui/SimpleMenu.tsx +48 -0
- package/src/editor/ui/SimpleTable.tsx +63 -0
- package/src/editor/ui/SimpleTabs.tsx +55 -0
- package/src/editor/ui/SimpleToolbar.tsx +7 -0
- package/src/editor/ui/Spinner.tsx +7 -0
- package/src/editor/ui/Splitter.tsx +247 -0
- package/src/editor/ui/StackedPanels.tsx +134 -0
- package/src/editor/ui/Toolbar.tsx +7 -0
- package/src/editor/utils/id-helper.ts +3 -0
- package/src/editor/utils/insertOptions.ts +69 -0
- package/src/editor/utils/itemutils.ts +29 -0
- package/src/editor/utils/useMemoDebug.ts +28 -0
- package/src/editor/utils.ts +435 -0
- package/src/editor/views/CompareView.tsx +256 -0
- package/src/editor/views/EditView.tsx +27 -0
- package/src/editor/views/ItemEditor.tsx +58 -0
- package/src/editor/views/SingleEditView.tsx +44 -0
- package/src/fonts/Geist-Black.woff2 +0 -0
- package/src/fonts/Geist-Bold.woff2 +0 -0
- package/src/fonts/Geist-ExtraBold.woff2 +0 -0
- package/src/fonts/Geist-ExtraLight.woff2 +0 -0
- package/src/fonts/Geist-Light.woff2 +0 -0
- package/src/fonts/Geist-Medium.woff2 +0 -0
- package/src/fonts/Geist-Regular.woff2 +0 -0
- package/src/fonts/Geist-SemiBold.woff2 +0 -0
- package/src/fonts/Geist-Thin.woff2 +0 -0
- package/src/fonts/Geist[wght].woff2 +0 -0
- package/src/index.ts +7 -0
- package/src/page-wizard/PageWizard.tsx +163 -0
- package/src/page-wizard/SelectWizard.tsx +109 -0
- package/src/page-wizard/WizardSteps.tsx +207 -0
- package/src/page-wizard/service.ts +35 -0
- package/src/page-wizard/startPageWizardCommand.ts +27 -0
- package/src/page-wizard/steps/BuildPageStep.tsx +266 -0
- package/src/page-wizard/steps/CollectStep.tsx +233 -0
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +443 -0
- package/src/page-wizard/steps/Components.tsx +193 -0
- package/src/page-wizard/steps/CreatePage.tsx +285 -0
- package/src/page-wizard/steps/CreatePageAndLayoutStep.tsx +384 -0
- package/src/page-wizard/steps/EditButton.tsx +34 -0
- package/src/page-wizard/steps/FieldEditor.tsx +102 -0
- package/src/page-wizard/steps/Generate.tsx +32 -0
- package/src/page-wizard/steps/ImagesStep.tsx +318 -0
- package/src/page-wizard/steps/LayoutStep.tsx +228 -0
- package/src/page-wizard/steps/SelectStep.tsx +256 -0
- package/src/page-wizard/steps/schema.ts +180 -0
- package/src/page-wizard/steps/usePageCreator.ts +279 -0
- package/src/splash-screen/NewPage.tsx +232 -0
- package/src/splash-screen/SectionHeadline.tsx +21 -0
- package/src/splash-screen/SplashScreen.tsx +156 -0
- package/src/tour/Tour.tsx +558 -0
- package/src/tour/default-tour.tsx +300 -0
- package/src/tour/preview-tour.tsx +127 -0
- package/src/types.ts +302 -0
- package/styles.css +476 -0
- package/tsconfig.build.json +21 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { useEditContext } from "../client/editContext";
|
|
2
|
+
|
|
3
|
+
import { InputText } from "primereact/inputtext";
|
|
4
|
+
import {
|
|
5
|
+
FieldTypeGroup,
|
|
6
|
+
TemplateField,
|
|
7
|
+
TemplateSection,
|
|
8
|
+
getFieldTypes,
|
|
9
|
+
} from "../services/componentDesignerService";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { Dropdown } from "primereact/dropdown";
|
|
12
|
+
|
|
13
|
+
export function TemplateEditor() {
|
|
14
|
+
const context = useEditContext();
|
|
15
|
+
if (!context) return null;
|
|
16
|
+
|
|
17
|
+
const [sections, setSections] = useState<TemplateSection[]>([]);
|
|
18
|
+
const [fieldTypes, setFieldTypes] = useState<FieldTypeGroup[]>([]);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const newSections = [
|
|
22
|
+
...(context.componentDesignerComponent?.template?.sections.map((s) => ({
|
|
23
|
+
...s,
|
|
24
|
+
})) || []),
|
|
25
|
+
];
|
|
26
|
+
if (
|
|
27
|
+
newSections.length === 0 ||
|
|
28
|
+
newSections[newSections.length - 1].fields.length > 0
|
|
29
|
+
)
|
|
30
|
+
newSections.push({
|
|
31
|
+
name: "",
|
|
32
|
+
fields: [],
|
|
33
|
+
key: Math.random().toString(),
|
|
34
|
+
});
|
|
35
|
+
newSections.forEach((section) => {
|
|
36
|
+
const fields = [...section.fields];
|
|
37
|
+
if (
|
|
38
|
+
section.id ||
|
|
39
|
+
(section.name != "" &&
|
|
40
|
+
(!fields.length ||
|
|
41
|
+
fields[fields.length - 1].id ||
|
|
42
|
+
fields[fields.length - 1].name != ""))
|
|
43
|
+
) {
|
|
44
|
+
fields.push({
|
|
45
|
+
name: "",
|
|
46
|
+
type: "",
|
|
47
|
+
source: "",
|
|
48
|
+
key: Math.random().toString(),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
section.fields = fields;
|
|
52
|
+
});
|
|
53
|
+
setSections(newSections);
|
|
54
|
+
}, [context.componentDesignerComponent]);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const load = async () => {
|
|
58
|
+
const types = await getFieldTypes();
|
|
59
|
+
setFieldTypes(types);
|
|
60
|
+
};
|
|
61
|
+
load();
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const template = context.componentDesignerComponent?.template;
|
|
65
|
+
|
|
66
|
+
if (!template) return null;
|
|
67
|
+
|
|
68
|
+
const updateComponent = (sections: TemplateSection[]) => {
|
|
69
|
+
const newSections = sections.filter((x) => x.id || x.name);
|
|
70
|
+
newSections.forEach((section) => {
|
|
71
|
+
section.fields = section.fields.filter((x) => x.id || x.name);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const newTemplate = {
|
|
75
|
+
...template,
|
|
76
|
+
sections: newSections,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const newComponent = {
|
|
80
|
+
...context.componentDesignerComponent!,
|
|
81
|
+
template: newTemplate,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
console.log("Updating component", newComponent);
|
|
85
|
+
|
|
86
|
+
context.setComponentDesignerComponent(newComponent);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const update = () => {
|
|
90
|
+
updateComponent(sections);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const removeField = (section: TemplateSection, field: TemplateField) => {
|
|
94
|
+
section.fields = section.fields.filter((x) => x.id !== field.id);
|
|
95
|
+
update();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const handleDragStart = (
|
|
99
|
+
event: React.DragEvent,
|
|
100
|
+
index: number,
|
|
101
|
+
sectionIndex?: number
|
|
102
|
+
) => {
|
|
103
|
+
event.dataTransfer.setData("text/plain", index.toString());
|
|
104
|
+
event.dataTransfer.effectAllowed = "move";
|
|
105
|
+
//event.currentTarget.style.opacity = "0.5";
|
|
106
|
+
if (sectionIndex === undefined) {
|
|
107
|
+
event.dataTransfer.setData("isSection", "true");
|
|
108
|
+
} else {
|
|
109
|
+
event.dataTransfer.setData("sectionIndex", sectionIndex.toString());
|
|
110
|
+
event.dataTransfer.setData("isSection", "false");
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleDragOver = (event: React.DragEvent) => {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
event.dataTransfer.dropEffect = "move";
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const handleDrop = (
|
|
120
|
+
event: React.DragEvent,
|
|
121
|
+
dropIndex: number,
|
|
122
|
+
sectionIndex?: number
|
|
123
|
+
) => {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
const dragIndex = parseInt(event.dataTransfer.getData("text/plain"));
|
|
126
|
+
const isSectionDrag = event.dataTransfer.getData("isSection") === "true";
|
|
127
|
+
|
|
128
|
+
if (isSectionDrag && sectionIndex === undefined) {
|
|
129
|
+
const newSections = sections;
|
|
130
|
+
const [removed] = newSections.splice(dragIndex, 1);
|
|
131
|
+
newSections.splice(dropIndex, 0, removed);
|
|
132
|
+
|
|
133
|
+
updateComponent(newSections);
|
|
134
|
+
} else if (!isSectionDrag) {
|
|
135
|
+
const sourceSectionIndex = parseInt(
|
|
136
|
+
event.dataTransfer.getData("sectionIndex")
|
|
137
|
+
);
|
|
138
|
+
const sourceSection = sections[sourceSectionIndex];
|
|
139
|
+
const targetSection = sections[sectionIndex ?? dropIndex];
|
|
140
|
+
|
|
141
|
+
const sourceFields = sourceSection.fields;
|
|
142
|
+
const targetFields = targetSection.fields;
|
|
143
|
+
const [removed] = sourceFields.splice(dragIndex, 1);
|
|
144
|
+
|
|
145
|
+
if (sectionIndex === undefined) {
|
|
146
|
+
targetFields.push(removed);
|
|
147
|
+
} else {
|
|
148
|
+
targetFields.splice(dropIndex, 0, removed);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
updateComponent(sections);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div className="p-1">
|
|
157
|
+
{sections.map((section, sectionIndex) => {
|
|
158
|
+
return (
|
|
159
|
+
<div key={section.id || section.key} className="mb-4">
|
|
160
|
+
<div className=" flex gap-1">
|
|
161
|
+
{dragHandle(sectionIndex)}
|
|
162
|
+
<InputText
|
|
163
|
+
className="text-xs"
|
|
164
|
+
value={section.name}
|
|
165
|
+
onChange={(e) => {
|
|
166
|
+
section.name = e.target.value;
|
|
167
|
+
update();
|
|
168
|
+
}}
|
|
169
|
+
/>
|
|
170
|
+
</div>
|
|
171
|
+
{section.fields.map((field, fieldIndex) => {
|
|
172
|
+
return (
|
|
173
|
+
<div
|
|
174
|
+
key={field.id || field.key}
|
|
175
|
+
className="ml-4 flex gap-2 mt-1 items-center"
|
|
176
|
+
>
|
|
177
|
+
{dragHandle(fieldIndex, sectionIndex)}
|
|
178
|
+
<InputText
|
|
179
|
+
key="name"
|
|
180
|
+
className="text-xs flex-1"
|
|
181
|
+
value={field.name}
|
|
182
|
+
onChange={(e) => {
|
|
183
|
+
field.name = e.target.value;
|
|
184
|
+
update();
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
<Dropdown
|
|
188
|
+
key="type"
|
|
189
|
+
filter
|
|
190
|
+
options={fieldTypes}
|
|
191
|
+
optionGroupLabel="name"
|
|
192
|
+
optionGroupChildren="fieldTypes"
|
|
193
|
+
className="text-xs flex-1"
|
|
194
|
+
value={field.type}
|
|
195
|
+
onChange={(e) => {
|
|
196
|
+
field.type = e.target.value;
|
|
197
|
+
update();
|
|
198
|
+
}}
|
|
199
|
+
/>
|
|
200
|
+
<InputText
|
|
201
|
+
key="source"
|
|
202
|
+
className="text-xs flex-1"
|
|
203
|
+
value={field.source}
|
|
204
|
+
onChange={(e) => {
|
|
205
|
+
field.source = e.target.value;
|
|
206
|
+
update();
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
<i
|
|
210
|
+
className="pi pi-fw pi-times cursor-pointer"
|
|
211
|
+
onClick={() => removeField(section, field)}
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
})}
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
})}
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
function dragHandle(index: number, sectionIndex?: number) {
|
|
223
|
+
return (
|
|
224
|
+
<div
|
|
225
|
+
draggable
|
|
226
|
+
onDragStart={(event) => handleDragStart(event, index, sectionIndex)}
|
|
227
|
+
onDragOver={handleDragOver}
|
|
228
|
+
onDrop={(event) => handleDrop(event, index, sectionIndex)}
|
|
229
|
+
// onDragEnd={handleDragEnd}
|
|
230
|
+
className="cursor-grab text-xs bg-gray-50 text-center p-0.5 border flex justify-center items-center"
|
|
231
|
+
>
|
|
232
|
+
<i className="pi pi-ellipsis-v" />
|
|
233
|
+
</div>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AiContext } from "../ai/AiTerminal";
|
|
2
|
+
//import { configuration } from "../config/config";
|
|
3
|
+
import { EditContextType } from "../client/editContext";
|
|
4
|
+
import { getItemDescriptor } from "../utils";
|
|
5
|
+
|
|
6
|
+
export function createDesignerAiContext({
|
|
7
|
+
editContext,
|
|
8
|
+
}: {
|
|
9
|
+
editContext: EditContextType;
|
|
10
|
+
}): AiContext {
|
|
11
|
+
return {
|
|
12
|
+
//configuration.services.editorService.baseUrl +
|
|
13
|
+
endpoint: "/alpaca/ai/designerprompt",
|
|
14
|
+
callback: () => {
|
|
15
|
+
editContext.requestRefresh();
|
|
16
|
+
},
|
|
17
|
+
promptData: {
|
|
18
|
+
templateId: editContext.componentDesignerComponent?.templateId,
|
|
19
|
+
renderingId: editContext.componentDesignerRendering?.id,
|
|
20
|
+
contextItem: getItemDescriptor(editContext.page?.item!),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { EditContextType, DragObject } from "./client/editContext";
|
|
2
|
+
import { Component, Page, Placeholder } from "./pageModel";
|
|
3
|
+
|
|
4
|
+
export function findComponent(
|
|
5
|
+
id: string,
|
|
6
|
+
placeholders: Placeholder[],
|
|
7
|
+
): Component | undefined {
|
|
8
|
+
if (!placeholders) return;
|
|
9
|
+
for (const p of placeholders) {
|
|
10
|
+
for (const c of p.components) {
|
|
11
|
+
if (c.id === id || c.datasourceItem?.id === id) {
|
|
12
|
+
return c;
|
|
13
|
+
}
|
|
14
|
+
if (c.placeholders) {
|
|
15
|
+
const match = findComponent(id, c.placeholders);
|
|
16
|
+
if (match) {
|
|
17
|
+
return match;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getComponentById(
|
|
27
|
+
id: string,
|
|
28
|
+
page: Page,
|
|
29
|
+
): Component | undefined {
|
|
30
|
+
if (!page) return;
|
|
31
|
+
return findComponent(id, page.rootComponent.placeholders);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getComponentByIdFromHeadlessLayout(
|
|
35
|
+
id: string,
|
|
36
|
+
page: any,
|
|
37
|
+
): Component | undefined {
|
|
38
|
+
if (!page) return;
|
|
39
|
+
return findComponent(id, page.placeholders);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getSelectedComponents(editContext: EditContextType) {
|
|
43
|
+
if (!editContext) return [];
|
|
44
|
+
const page = editContext.page;
|
|
45
|
+
if (!page) return [];
|
|
46
|
+
const selectedComponents = editContext.selection
|
|
47
|
+
.map((x) => getComponentById(x, page))
|
|
48
|
+
.filter((x) => x);
|
|
49
|
+
return selectedComponents.length === 0 ? [] : selectedComponents;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getComponentByIdWithPlaceholder(
|
|
53
|
+
id: string,
|
|
54
|
+
page: Page,
|
|
55
|
+
): { placeholder: Placeholder; component: Component } | null {
|
|
56
|
+
if (!page) return null;
|
|
57
|
+
return findComponentWithPlaceholder(id, page.rootComponent.placeholders);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function findComponentWithPlaceholder(
|
|
61
|
+
id: string,
|
|
62
|
+
placeholders: Placeholder[],
|
|
63
|
+
): { placeholder: Placeholder; component: Component } | null {
|
|
64
|
+
if (!placeholders) return null;
|
|
65
|
+
for (const p of placeholders) {
|
|
66
|
+
for (const c of p.components) {
|
|
67
|
+
if (c.id === id || c.datasourceItem?.id === id) {
|
|
68
|
+
return { component: c, placeholder: p };
|
|
69
|
+
}
|
|
70
|
+
if (c.placeholders) {
|
|
71
|
+
const match = findComponentWithPlaceholder(id, c.placeholders);
|
|
72
|
+
if (match) {
|
|
73
|
+
return match;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getAllPlaceholders(page: Page) {
|
|
83
|
+
const placeholders: Placeholder[] = [];
|
|
84
|
+
const addPlaceholders = (p: Placeholder[]) => {
|
|
85
|
+
p.forEach((x) => {
|
|
86
|
+
placeholders.push(x);
|
|
87
|
+
if (x.components) {
|
|
88
|
+
x.components.forEach((c) => {
|
|
89
|
+
addPlaceholders(c.placeholders);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
addPlaceholders(page.rootComponent.placeholders);
|
|
95
|
+
return placeholders;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const isValidPlaceholder = (
|
|
99
|
+
placeholder: Placeholder,
|
|
100
|
+
dragObject: DragObject,
|
|
101
|
+
) => {
|
|
102
|
+
return (
|
|
103
|
+
placeholder.insertOptions?.find(
|
|
104
|
+
(y) =>
|
|
105
|
+
y.typeId === dragObject.typeId ||
|
|
106
|
+
y.typeId === dragObject?.templateId ||
|
|
107
|
+
y.compatibleTemplates?.find((z) => z == dragObject.typeId) !==
|
|
108
|
+
undefined ||
|
|
109
|
+
y.typeId === dragObject.templateId ||
|
|
110
|
+
y.compatibleTemplates?.find((z) => z == dragObject.templateId) !==
|
|
111
|
+
undefined,
|
|
112
|
+
) !== undefined
|
|
113
|
+
);
|
|
114
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useRouter } from "next/navigation";
|
|
2
|
+
import { usePathname, useSearchParams } from "next/navigation";
|
|
3
|
+
import { useEditContext } from "../client/editContext";
|
|
4
|
+
import { SimpleMenu } from "../ui/SimpleMenu";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
export function ControlCenterMenu() {
|
|
7
|
+
const editContext = useEditContext();
|
|
8
|
+
const config = editContext?.configuration;
|
|
9
|
+
const searchParams = useSearchParams();
|
|
10
|
+
const urlActiveItemKey = searchParams.get("ccpanel");
|
|
11
|
+
const [activeItemKey, setActiveItemKey] = useState<string | null>(
|
|
12
|
+
urlActiveItemKey
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const router = useRouter();
|
|
16
|
+
const pathname = usePathname();
|
|
17
|
+
|
|
18
|
+
const updateUrl = (key: string | null) => {
|
|
19
|
+
if (urlActiveItemKey === key) return;
|
|
20
|
+
|
|
21
|
+
const current = new URLSearchParams(Array.from(searchParams.entries()));
|
|
22
|
+
|
|
23
|
+
if (key) {
|
|
24
|
+
current.set("ccpanel", key);
|
|
25
|
+
} else {
|
|
26
|
+
current.delete("ccpanel");
|
|
27
|
+
}
|
|
28
|
+
router.push(`${pathname}?${current.toString()}`, { scroll: false });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
updateUrl(activeItemKey);
|
|
33
|
+
}, [activeItemKey]);
|
|
34
|
+
|
|
35
|
+
const items = config?.controlCenter.groups.map((group) => {
|
|
36
|
+
return {
|
|
37
|
+
key: group.title,
|
|
38
|
+
label: group.title,
|
|
39
|
+
icon: group.icon,
|
|
40
|
+
items:
|
|
41
|
+
group.panels.map((panel) => ({
|
|
42
|
+
key: panel.id,
|
|
43
|
+
label: panel.title,
|
|
44
|
+
})) || [],
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const groups = config?.controlCenter.groups;
|
|
50
|
+
const item = groups
|
|
51
|
+
?.flatMap((x) => x.panels)
|
|
52
|
+
?.find((item) => item.id === activeItemKey);
|
|
53
|
+
if (item) {
|
|
54
|
+
editContext?.setCenterPanelView(item.content);
|
|
55
|
+
}
|
|
56
|
+
}, [activeItemKey]);
|
|
57
|
+
|
|
58
|
+
if (!items) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<SimpleMenu
|
|
64
|
+
items={items}
|
|
65
|
+
activeItemKey={activeItemKey}
|
|
66
|
+
onItemClick={(item) => {
|
|
67
|
+
setActiveItemKey(item.key);
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { getIndexes } from "../services/indexService";
|
|
4
|
+
|
|
5
|
+
import { IndexSettings } from "./IndexSettings";
|
|
6
|
+
import { classNames } from "primereact/utils";
|
|
7
|
+
|
|
8
|
+
export function IndexOverview() {
|
|
9
|
+
const [indexes, setIndexes] = useState<string[] | undefined>(undefined);
|
|
10
|
+
const [selectedIndex, setSelectedIndex] = useState<string | undefined>(
|
|
11
|
+
undefined
|
|
12
|
+
);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
async function loadIndexes() {
|
|
15
|
+
const indexes = await getIndexes();
|
|
16
|
+
if (indexes.indexOf("master") === -1) {
|
|
17
|
+
indexes.push("master");
|
|
18
|
+
}
|
|
19
|
+
if (indexes.indexOf("media") === -1) {
|
|
20
|
+
indexes.push("media");
|
|
21
|
+
}
|
|
22
|
+
setIndexes(indexes);
|
|
23
|
+
}
|
|
24
|
+
loadIndexes();
|
|
25
|
+
}, []);
|
|
26
|
+
return (
|
|
27
|
+
<div className="flex items-stretch h-full">
|
|
28
|
+
<div className="flex flex-col gap-2 border-r border-gray-200">
|
|
29
|
+
<div className="flex items-center justify-center p-2 min-w-40 border-b border-gray-200">
|
|
30
|
+
Index
|
|
31
|
+
</div>
|
|
32
|
+
{indexes?.map((index) => (
|
|
33
|
+
<div
|
|
34
|
+
key={index}
|
|
35
|
+
onClick={() => setSelectedIndex(index)}
|
|
36
|
+
className={classNames(
|
|
37
|
+
"cursor-pointer p-2 px-6 hover:bg-gray-100 text-sm",
|
|
38
|
+
selectedIndex === index && "bg-gray-100"
|
|
39
|
+
)}
|
|
40
|
+
>
|
|
41
|
+
{index}
|
|
42
|
+
</div>
|
|
43
|
+
))}
|
|
44
|
+
</div>
|
|
45
|
+
<div className="flex-1 p-2">
|
|
46
|
+
{selectedIndex && <IndexSettings index={{ name: selectedIndex }} />}
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|