@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,558 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { useEditContext } from "../client-components";
|
|
3
|
+
import { classNames } from "primereact/utils";
|
|
4
|
+
import { EditContextType } from "../editor/client/editContext";
|
|
5
|
+
|
|
6
|
+
export function Tour({ tourStopCallback }: { tourStopCallback: () => void }) {
|
|
7
|
+
const [currentStep, setCurrentStep] = useState<string>("start-tour");
|
|
8
|
+
const [show, setShow] = useState(true);
|
|
9
|
+
const editContext = useEditContext();
|
|
10
|
+
const [focusRect, setFocusRect] = useState<DOMRect | null>(null);
|
|
11
|
+
const [pointToRect, setPointToRect] = useState<DOMRect | null>(null);
|
|
12
|
+
const delay = (ms: number) =>
|
|
13
|
+
new Promise((resolve) => setTimeout(resolve, ms)) as Promise<void>;
|
|
14
|
+
|
|
15
|
+
const waitForElement = (
|
|
16
|
+
selector: string,
|
|
17
|
+
timeout: number = 0
|
|
18
|
+
): Promise<DOMRect | undefined> => {
|
|
19
|
+
if (selector.startsWith("iframe:")) {
|
|
20
|
+
return waitForElementInIframe(selector.substring(7), timeout);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return new Promise<DOMRect | undefined>((resolve) => {
|
|
24
|
+
const startTime = Date.now();
|
|
25
|
+
const checkForElement = () => {
|
|
26
|
+
const element = document.querySelector(selector);
|
|
27
|
+
if (element) {
|
|
28
|
+
let rect = element.getBoundingClientRect();
|
|
29
|
+
const extendFocus = step?.extendFocus || 10;
|
|
30
|
+
rect = new DOMRect(
|
|
31
|
+
rect.left - extendFocus / 2,
|
|
32
|
+
rect.top - extendFocus / 2,
|
|
33
|
+
rect.width + extendFocus,
|
|
34
|
+
rect.height + extendFocus
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
resolve(rect);
|
|
38
|
+
} else if (timeout > 0 && Date.now() - startTime >= timeout) {
|
|
39
|
+
resolve(undefined);
|
|
40
|
+
} else {
|
|
41
|
+
requestAnimationFrame(checkForElement);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
checkForElement();
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const waitForElementInIframe = (
|
|
49
|
+
selector: string,
|
|
50
|
+
timeout: number = 0
|
|
51
|
+
): Promise<DOMRect | undefined> => {
|
|
52
|
+
return new Promise<DOMRect | undefined>((resolve, reject) => {
|
|
53
|
+
const startTime = Date.now();
|
|
54
|
+
const checkForElement = () => {
|
|
55
|
+
const iframe = document.querySelector(
|
|
56
|
+
"iframe.page-iframe"
|
|
57
|
+
) as HTMLIFrameElement;
|
|
58
|
+
if (iframe && iframe.contentDocument) {
|
|
59
|
+
const element = iframe.contentDocument.querySelector(selector);
|
|
60
|
+
if (element) {
|
|
61
|
+
const elementRect = element.getBoundingClientRect();
|
|
62
|
+
const iframeRect = iframe.getBoundingClientRect();
|
|
63
|
+
let rect = new DOMRect(
|
|
64
|
+
elementRect.left + iframeRect.left,
|
|
65
|
+
elementRect.top + iframeRect.top,
|
|
66
|
+
elementRect.width,
|
|
67
|
+
elementRect.height
|
|
68
|
+
);
|
|
69
|
+
const extendFocus = step?.extendFocus || 10;
|
|
70
|
+
rect = new DOMRect(
|
|
71
|
+
rect.left - extendFocus / 2,
|
|
72
|
+
rect.top - extendFocus / 2,
|
|
73
|
+
rect.width + extendFocus,
|
|
74
|
+
rect.height + extendFocus
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
resolve(rect);
|
|
78
|
+
} else if (timeout > 0 && Date.now() - startTime >= timeout) {
|
|
79
|
+
resolve(undefined);
|
|
80
|
+
} else {
|
|
81
|
+
requestAnimationFrame(checkForElement);
|
|
82
|
+
}
|
|
83
|
+
} else if (Date.now() - startTime >= timeout) {
|
|
84
|
+
reject(new Error(`Timeout waiting for iframe: ${selector}`));
|
|
85
|
+
} else {
|
|
86
|
+
requestAnimationFrame(checkForElement);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
checkForElement();
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const waitForElementToDisappear = (selector: string): Promise<void> => {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
const checkForElement = () => {
|
|
96
|
+
const element = document.querySelector(selector);
|
|
97
|
+
if (!element) {
|
|
98
|
+
resolve();
|
|
99
|
+
} else {
|
|
100
|
+
requestAnimationFrame(checkForElement);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
checkForElement();
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const waitForInput = (
|
|
108
|
+
selector: string,
|
|
109
|
+
minNumberOfCharacters: number = 1
|
|
110
|
+
): Promise<void> => {
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
const checkForInput = () => {
|
|
113
|
+
const input = document.querySelector(selector);
|
|
114
|
+
|
|
115
|
+
let inputValue = "";
|
|
116
|
+
|
|
117
|
+
if (input?.getAttribute("contenteditable")) {
|
|
118
|
+
console.log("contenteditable", (input as HTMLElement).innerText);
|
|
119
|
+
inputValue = (input as HTMLElement).innerText;
|
|
120
|
+
} else if (
|
|
121
|
+
input &&
|
|
122
|
+
(input as HTMLInputElement).value.length >= minNumberOfCharacters
|
|
123
|
+
) {
|
|
124
|
+
inputValue = (input as HTMLInputElement).value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (inputValue.length >= minNumberOfCharacters) {
|
|
128
|
+
console.log("input found", inputValue);
|
|
129
|
+
resolve();
|
|
130
|
+
} else {
|
|
131
|
+
requestAnimationFrame(checkForInput);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
checkForInput();
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
function setNativeValue(
|
|
139
|
+
element: HTMLInputElement | HTMLTextAreaElement,
|
|
140
|
+
value: string
|
|
141
|
+
) {
|
|
142
|
+
const valueSetter = Object.getOwnPropertyDescriptor(
|
|
143
|
+
element.constructor.prototype,
|
|
144
|
+
"value"
|
|
145
|
+
)?.set;
|
|
146
|
+
const prototype = Object.getPrototypeOf(element);
|
|
147
|
+
const prototypeValueSetter = Object.getOwnPropertyDescriptor(
|
|
148
|
+
prototype,
|
|
149
|
+
"value"
|
|
150
|
+
)?.set;
|
|
151
|
+
|
|
152
|
+
if (valueSetter && valueSetter !== prototypeValueSetter) {
|
|
153
|
+
prototypeValueSetter?.call(element, value);
|
|
154
|
+
} else {
|
|
155
|
+
valueSetter?.call(element, value);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const event = new Event("input", { bubbles: true });
|
|
159
|
+
element.dispatchEvent(event);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function simulateTyping(
|
|
163
|
+
element: HTMLInputElement | HTMLTextAreaElement,
|
|
164
|
+
text: string,
|
|
165
|
+
interval = 35
|
|
166
|
+
) {
|
|
167
|
+
let i = 0;
|
|
168
|
+
|
|
169
|
+
while (i <= text.length) {
|
|
170
|
+
const currentText = text.substring(0, i);
|
|
171
|
+
setNativeValue(element, currentText);
|
|
172
|
+
i++;
|
|
173
|
+
|
|
174
|
+
const randomDelay = interval * (0.5 + Math.random());
|
|
175
|
+
await delay(randomDelay);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Stops the tour and resets the state.
|
|
181
|
+
*/
|
|
182
|
+
const stopTour = () => {
|
|
183
|
+
setCurrentStep("start-tour");
|
|
184
|
+
setFocusRect(null);
|
|
185
|
+
tourStopCallback();
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const tours = editContext!.configuration.tours;
|
|
189
|
+
const tour =
|
|
190
|
+
tours[editContext!.configuration.activeTour as keyof typeof tours];
|
|
191
|
+
|
|
192
|
+
const tourSteps = tour.getSteps({
|
|
193
|
+
editContext: editContext as EditContextType,
|
|
194
|
+
nextStep: (stepId) => setCurrentStep(stepId),
|
|
195
|
+
stopTour: () => tourStopCallback(),
|
|
196
|
+
waitForElement,
|
|
197
|
+
waitForElementToDisappear,
|
|
198
|
+
setFocusRect,
|
|
199
|
+
delay,
|
|
200
|
+
waitForInput: waitForInput,
|
|
201
|
+
simulateTyping,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const step = tourSteps[currentStep];
|
|
205
|
+
if (!step) return null;
|
|
206
|
+
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
const runStep = async () => {
|
|
209
|
+
setShow(false);
|
|
210
|
+
setFocusRect(null);
|
|
211
|
+
|
|
212
|
+
await delay(500);
|
|
213
|
+
|
|
214
|
+
const step = tourSteps[currentStep];
|
|
215
|
+
if (!step) return;
|
|
216
|
+
|
|
217
|
+
console.log("step", currentStep, step);
|
|
218
|
+
if (step.prepareAction) {
|
|
219
|
+
await step.prepareAction();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (step.focusElement) {
|
|
223
|
+
const rect = await waitForElement(step.focusElement, 5000);
|
|
224
|
+
if (!rect) setCurrentStep("error");
|
|
225
|
+
else setFocusRect(rect);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
setShow(true);
|
|
229
|
+
|
|
230
|
+
if (step.waitForUserInput) {
|
|
231
|
+
const nextStep = (await step.waitForUserInput()) || step.nextStep;
|
|
232
|
+
if (nextStep) {
|
|
233
|
+
setCurrentStep(nextStep);
|
|
234
|
+
} else console.log("no next step defined for step", currentStep);
|
|
235
|
+
} else {
|
|
236
|
+
if (step.waitForElement) {
|
|
237
|
+
await waitForElement(step.waitForElement);
|
|
238
|
+
if (step.nextStep) {
|
|
239
|
+
setCurrentStep(step.nextStep);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
runStep();
|
|
245
|
+
}, [currentStep]);
|
|
246
|
+
|
|
247
|
+
useEffect(() => {
|
|
248
|
+
const getPointTo = async () => {
|
|
249
|
+
let pointToRect = focusRect;
|
|
250
|
+
|
|
251
|
+
if (step.getPointTo) {
|
|
252
|
+
const pointTo = step.getPointTo();
|
|
253
|
+
if (pointTo) {
|
|
254
|
+
pointToRect = pointTo;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (step.pointToElement) {
|
|
259
|
+
const rect = await waitForElement(step.pointToElement, 5000);
|
|
260
|
+
if (rect) {
|
|
261
|
+
pointToRect = rect;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
setPointToRect(pointToRect);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
getPointTo();
|
|
269
|
+
}, [focusRect, currentStep]);
|
|
270
|
+
|
|
271
|
+
if (!step) {
|
|
272
|
+
throw new Error(`Tour step ${currentStep} not found`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const bubblePosition = step.bubblePosition || "right";
|
|
276
|
+
const bubbleStyle: React.CSSProperties = {};
|
|
277
|
+
|
|
278
|
+
let boxStyle: React.CSSProperties = {
|
|
279
|
+
position: "fixed",
|
|
280
|
+
left: "50%",
|
|
281
|
+
top: "50%",
|
|
282
|
+
transform: "translate(-50%, -50%)",
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
let arrowStyle: React.CSSProperties = {};
|
|
286
|
+
|
|
287
|
+
if (pointToRect) {
|
|
288
|
+
if (bubblePosition === "right") {
|
|
289
|
+
boxStyle = {
|
|
290
|
+
position: "absolute",
|
|
291
|
+
left: pointToRect.left + pointToRect.width,
|
|
292
|
+
top: pointToRect.top - 10,
|
|
293
|
+
alignItems: "flex-start",
|
|
294
|
+
};
|
|
295
|
+
arrowStyle = {
|
|
296
|
+
marginLeft: "-20px",
|
|
297
|
+
};
|
|
298
|
+
bubbleStyle.marginLeft = "80px";
|
|
299
|
+
bubbleStyle.marginTop = "-20px";
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (bubblePosition === "left") {
|
|
303
|
+
boxStyle = {
|
|
304
|
+
position: "absolute",
|
|
305
|
+
right: window.innerWidth - pointToRect.left,
|
|
306
|
+
top: pointToRect.top + pointToRect.height / 2,
|
|
307
|
+
alignItems: "flex-end",
|
|
308
|
+
};
|
|
309
|
+
arrowStyle = {
|
|
310
|
+
marginRight: "-20px",
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (bubblePosition === "bottom") {
|
|
315
|
+
boxStyle = {
|
|
316
|
+
position: "absolute",
|
|
317
|
+
left: pointToRect.left + pointToRect.width / 2,
|
|
318
|
+
top: pointToRect.top + pointToRect.height,
|
|
319
|
+
transform: "translate(-50%, 0)",
|
|
320
|
+
};
|
|
321
|
+
if (step.flipArrow) {
|
|
322
|
+
arrowStyle = {
|
|
323
|
+
transform: "scaleX(-1)",
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (bubblePosition === "top-right") {
|
|
329
|
+
boxStyle = {
|
|
330
|
+
position: "absolute",
|
|
331
|
+
left: pointToRect.left + pointToRect.width,
|
|
332
|
+
bottom: window.innerHeight - pointToRect.top,
|
|
333
|
+
transform: "translate(-50%, 0)",
|
|
334
|
+
flexDirection: "column-reverse",
|
|
335
|
+
};
|
|
336
|
+
arrowStyle = {
|
|
337
|
+
transform: "rotate(180deg)",
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
if (step.flipArrow) {
|
|
341
|
+
arrowStyle = {
|
|
342
|
+
transform: "scaleX(-1)",
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const arrowRotation = bubblePosition === "right" ? "-a-rotate-90" : "";
|
|
349
|
+
|
|
350
|
+
const overlayStyle: React.CSSProperties = {
|
|
351
|
+
position: "fixed",
|
|
352
|
+
top: 0,
|
|
353
|
+
left: 0,
|
|
354
|
+
width: "100%",
|
|
355
|
+
height: "100%",
|
|
356
|
+
backgroundColor: "rgba(0, 0, 0, 0.3)",
|
|
357
|
+
pointerEvents: "auto",
|
|
358
|
+
clipPath: focusRect
|
|
359
|
+
? `polygon(0% 0%, 0% 100%, ${focusRect.left}px 100%, ${
|
|
360
|
+
focusRect.left
|
|
361
|
+
}px ${focusRect.top}px, ${focusRect.left + focusRect.width}px ${
|
|
362
|
+
focusRect.top
|
|
363
|
+
}px, ${focusRect.left + focusRect.width}px ${
|
|
364
|
+
focusRect.top + focusRect.height
|
|
365
|
+
}px, ${focusRect.left}px ${focusRect.top + focusRect.height}px, ${
|
|
366
|
+
focusRect.left
|
|
367
|
+
}px 100%, 100% 100%, 100% 0%)`
|
|
368
|
+
: "none",
|
|
369
|
+
// clipPath: focusPosition
|
|
370
|
+
// ? `path('M 0 0 H 100% V 100% H 0 Z M ${focusPosition.left}px ${focusPosition.top}px H ${focusPosition.left + focusPosition.width}px V ${focusPosition.top + focusPosition.height}px H ${focusPosition.left}px Z')`
|
|
371
|
+
// : 'none',
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
if (!show) {
|
|
375
|
+
return <div className="overlay" style={overlayStyle}></div>;
|
|
376
|
+
}
|
|
377
|
+
return (
|
|
378
|
+
<>
|
|
379
|
+
<div className="overlay" style={overlayStyle}></div>
|
|
380
|
+
|
|
381
|
+
<div
|
|
382
|
+
style={boxStyle}
|
|
383
|
+
className="text-gray-800 flex flex-col items-center fade-in"
|
|
384
|
+
>
|
|
385
|
+
{focusRect && (
|
|
386
|
+
<svg
|
|
387
|
+
width="100px"
|
|
388
|
+
height="100px"
|
|
389
|
+
viewBox="0 -7.89 113.08 113.08"
|
|
390
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
391
|
+
className={classNames("pointer-events-none", arrowRotation)}
|
|
392
|
+
style={arrowStyle}
|
|
393
|
+
>
|
|
394
|
+
<path
|
|
395
|
+
style={{ stroke: "#0000ff", fill: "#0000ff" }}
|
|
396
|
+
d="M20.1871 175C15.7485 172.891 13.0008 172.469 12.1553 170.992C8.98489 165.508 5.39173 160.024 3.70083 153.908C-1.37187 137.666 -0.737781 121.214 2.64402 104.762C8.35081 76.7092 21.0325 51.8201 36.8847 28.1966C38.5756 25.6655 40.0552 23.1344 41.7461 20.3924C41.7461 20.1814 41.5347 19.7596 41.112 19.1268C36.462 20.3923 31.6007 21.6579 26.9507 22.7125C24.4144 23.1344 21.4552 23.1344 18.9189 22.2907C17.4394 21.8688 15.3258 19.5486 15.3258 18.0722C15.3258 16.1739 16.8053 13.8537 18.0735 12.1663C19.1303 11.1117 21.0326 10.9008 22.7235 10.4789C35.4052 7.31508 48.087 3.72935 60.9801 0.776411C71.9709 -1.75468 75.564 1.83105 74.9299 12.5882C74.2959 23.7672 74.0845 34.9462 73.6618 45.9142C73.4505 49.289 72.8164 52.8747 72.3936 56.6714C63.5164 52.6638 63.5164 52.6638 60.346 18.494C47.0301 33.2588 38.1529 49.289 29.9098 65.7411C21.6666 82.1932 16.1712 99.489 13.2121 117.839C10.2531 136.823 13.8462 154.751 20.1871 175Z"
|
|
397
|
+
fill="#0D1927"
|
|
398
|
+
/>
|
|
399
|
+
</svg>
|
|
400
|
+
)}
|
|
401
|
+
|
|
402
|
+
<style>
|
|
403
|
+
{`
|
|
404
|
+
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;700&display=swap');
|
|
405
|
+
.handwritten {
|
|
406
|
+
font-family: 'Caveat', cursive;
|
|
407
|
+
}
|
|
408
|
+
.fade-background {
|
|
409
|
+
background: radial-gradient(circle, rgba(255,255,255,0.8) 60%, rgba(255,255,255,0) 90%);
|
|
410
|
+
}
|
|
411
|
+
.fade-in {
|
|
412
|
+
animation: fadeIn 0.5s ease-in-out;
|
|
413
|
+
}
|
|
414
|
+
@keyframes fadeIn {
|
|
415
|
+
from { opacity: 0; }
|
|
416
|
+
to { opacity: 1; }
|
|
417
|
+
}
|
|
418
|
+
`}
|
|
419
|
+
</style>
|
|
420
|
+
<div
|
|
421
|
+
className={`relative flex items-stretch justify-center bg-gray-50 rounded-lg border border-gray-800 gap-6 shadow-2xl`}
|
|
422
|
+
style={bubbleStyle}
|
|
423
|
+
>
|
|
424
|
+
<div
|
|
425
|
+
className="text-xs font-bold cursor-pointer flex items-center gap-2 absolute top-0 right-0 mr-2 mt-2"
|
|
426
|
+
onClick={stopTour}
|
|
427
|
+
>
|
|
428
|
+
<i className="pi pi-times" />
|
|
429
|
+
</div>
|
|
430
|
+
<div className="flex flex-col items-center justify-center gap-2 bg-gray-200 p-6 rounded-l-lg">
|
|
431
|
+
<AlpacaIcon />
|
|
432
|
+
</div>
|
|
433
|
+
<div className="flex flex-col items-end justify-center gap-3 p-4 ">
|
|
434
|
+
{/* Step Content */}
|
|
435
|
+
<div className="opacity-100 text-2xl font-bold handwritten text-center flex flex-col items-center max-w-[450px]">
|
|
436
|
+
<div className="text-4xl mb-4">{step.title}</div>
|
|
437
|
+
<div>{step.description}</div>
|
|
438
|
+
</div>
|
|
439
|
+
{/* Render Buttons Defined in Step Data */}
|
|
440
|
+
<div className="flex gap-2">
|
|
441
|
+
{step.buttons &&
|
|
442
|
+
step.buttons.map((button, index) => (
|
|
443
|
+
<button
|
|
444
|
+
key={index}
|
|
445
|
+
onClick={button.onClick}
|
|
446
|
+
className={button.className}
|
|
447
|
+
>
|
|
448
|
+
{button.label}
|
|
449
|
+
</button>
|
|
450
|
+
))}
|
|
451
|
+
</div>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
|
|
456
|
+
{/* Optional: Overlay to highlight elements */}
|
|
457
|
+
{/* {<div className="fade-background fixed inset-0 z-40"></div>} */}
|
|
458
|
+
</>
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
function AlpacaIcon() {
|
|
462
|
+
return (
|
|
463
|
+
<svg
|
|
464
|
+
height="80px"
|
|
465
|
+
width="80px"
|
|
466
|
+
version="1.1"
|
|
467
|
+
id="Layer_1"
|
|
468
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
469
|
+
viewBox="0 0 512 512"
|
|
470
|
+
>
|
|
471
|
+
<path
|
|
472
|
+
style={{ fill: "#EBE4DD" }}
|
|
473
|
+
d="M102.989,153.011v153.011C119.613,428.825,184.332,506.115,256,506.115
|
|
474
|
+
s136.387-77.29,153.012-200.092V153.011H102.989z"
|
|
475
|
+
/>
|
|
476
|
+
<path
|
|
477
|
+
style={{ fill: "#D8CCBC" }}
|
|
478
|
+
d="M255.999,153.011v353.103H256c71.668,0,136.387-77.29,153.012-200.092V153.011H255.999z"
|
|
479
|
+
/>
|
|
480
|
+
<path
|
|
481
|
+
style={{ fill: "#A58868" }}
|
|
482
|
+
d="M273.655,435.494h-35.31c0,41.195-17.007,41.195-29.425,41.195V512
|
|
483
|
+
c16.246,0,34.206-4.021,47.08-18.162C268.873,507.979,286.834,512,303.08,512v-35.31C290.662,476.69,273.655,476.69,273.655,435.494
|
|
484
|
+
z"
|
|
485
|
+
/>
|
|
486
|
+
<path
|
|
487
|
+
style={{ fill: "#947859" }}
|
|
488
|
+
d="M273.655,435.494H256v58.343C268.873,507.979,286.834,512,303.08,512v-35.31
|
|
489
|
+
C290.662,476.69,273.655,476.69,273.655,435.494z"
|
|
490
|
+
/>
|
|
491
|
+
<path
|
|
492
|
+
style={{ fill: "#EBE4DD" }}
|
|
493
|
+
d="M126.529,0C81.025,0,44.138,36.888,44.138,82.391s36.888,82.391,82.391,82.391V0z"
|
|
494
|
+
/>
|
|
495
|
+
<path
|
|
496
|
+
style={{ fill: "#D8CCBC" }}
|
|
497
|
+
d="M385.471,164.782c45.503,0,82.391-36.888,82.391-82.391S430.975,0,385.471,0V164.782z"
|
|
498
|
+
/>
|
|
499
|
+
<path
|
|
500
|
+
style={{ fill: "#BFA993" }}
|
|
501
|
+
d="M490.407,247.172c0.643-3.83,0.996-7.758,0.996-11.77c0-39.003-31.618-70.621-70.621-70.621
|
|
502
|
+
s-70.621,31.618-70.621,70.621c0,4.012,0.352,7.94,0.995,11.77H490.407z"
|
|
503
|
+
/>
|
|
504
|
+
<path
|
|
505
|
+
style={{ fill: "#EDEDED" }}
|
|
506
|
+
d="M420.782,306.023c39.003,0,70.621-31.618,70.621-70.621H350.161
|
|
507
|
+
C350.161,274.405,381.779,306.023,420.782,306.023z"
|
|
508
|
+
/>
|
|
509
|
+
<path
|
|
510
|
+
style={{ fill: "#454449" }}
|
|
511
|
+
d="M397.241,235.401c0,12.981,10.559,23.54,23.538,23.54h0.002c12.981,0.001,23.54-10.559,23.54-23.54
|
|
512
|
+
H397.241z"
|
|
513
|
+
/>
|
|
514
|
+
<path
|
|
515
|
+
style={{ fill: "#BFA993" }}
|
|
516
|
+
d="M160.844,247.172c0.643-3.83,0.995-7.758,0.995-11.77c0-39.003-31.618-70.621-70.621-70.621
|
|
517
|
+
S20.598,196.4,20.598,235.402c0,4.012,0.352,7.94,0.995,11.77H160.844z"
|
|
518
|
+
/>
|
|
519
|
+
<path
|
|
520
|
+
style={{ fill: "#EDEDED" }}
|
|
521
|
+
d="M91.218,306.023c39.003,0,70.621-31.618,70.621-70.621H20.598
|
|
522
|
+
C20.598,274.405,52.216,306.023,91.218,306.023z"
|
|
523
|
+
/>
|
|
524
|
+
<path
|
|
525
|
+
style={{ fill: "#454449" }}
|
|
526
|
+
d="M67.678,235.401c0,12.981,10.559,23.54,23.538,23.54h0.002c12.981,0.001,23.54-10.559,23.54-23.54
|
|
527
|
+
H67.678z"
|
|
528
|
+
/>
|
|
529
|
+
<path
|
|
530
|
+
style={{ fill: "#D8CCBC" }}
|
|
531
|
+
d="M391.356,107.187c0-15.527,4.902-33.778-5.082-46.69c-8.818-11.403-28.519-12.694-43.229-20.793
|
|
532
|
+
c-12.822-7.059-23.38-23.527-39.415-27.235c-14.505-3.356-31.411,6.442-47.63,6.442c-16.218,0-33.125-9.796-47.631-6.442
|
|
533
|
+
c-16.036,3.708-26.595,20.178-39.415,27.237c-14.71,8.099-34.41,9.391-43.227,20.792c-9.985,12.912-5.082,31.161-5.082,46.689
|
|
534
|
+
s-4.902,33.778,5.082,46.69c8.818,11.403,28.519,12.693,43.229,20.793c12.821,7.059,23.379,23.527,39.413,27.235
|
|
535
|
+
c14.505,3.356,31.412-6.442,47.63-6.442s33.125,9.796,47.632,6.442c16.034-3.708,26.592-20.176,39.413-27.237
|
|
536
|
+
c14.709-8.099,34.411-9.391,43.228-20.792C396.259,140.965,391.356,122.715,391.356,107.187z"
|
|
537
|
+
/>
|
|
538
|
+
<path
|
|
539
|
+
style={{ fill: "#BFA993" }}
|
|
540
|
+
d="M386.274,60.497c-8.818-11.403-28.519-12.694-43.229-20.793
|
|
541
|
+
c-12.822-7.059-23.38-23.527-39.415-27.235c-14.505-3.356-31.411,6.442-47.63,6.442v176.552c16.218,0,33.125,9.796,47.632,6.442
|
|
542
|
+
c16.034-3.708,26.592-20.176,39.413-27.237c14.709-8.099,34.411-9.391,43.228-20.792c9.985-12.912,5.082-31.161,5.082-46.689
|
|
543
|
+
S396.259,73.409,386.274,60.497z"
|
|
544
|
+
/>
|
|
545
|
+
<path
|
|
546
|
+
style={{ fill: "#58575D" }}
|
|
547
|
+
d="M293.664,406.069c-6.186,18.772-22.763,39.469-37.664,39.784
|
|
548
|
+
c-14.901-0.315-31.478-21.012-37.664-39.784c-2.858-9.591,4.529-17.529,16.478-17.655c14.124,0,28.248,0,42.372,0
|
|
549
|
+
C289.136,388.54,296.522,396.476,293.664,406.069z"
|
|
550
|
+
/>
|
|
551
|
+
<path
|
|
552
|
+
style={{ fill: "#454449" }}
|
|
553
|
+
d="M277.186,388.414c-7.062,0-14.124,0-21.186,0v57.439c14.901-0.315,31.478-21.012,37.664-39.784
|
|
554
|
+
C296.522,396.476,289.136,388.54,277.186,388.414z"
|
|
555
|
+
/>
|
|
556
|
+
</svg>
|
|
557
|
+
);
|
|
558
|
+
}
|