-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinkeep.js
More file actions
226 lines (201 loc) · 7.6 KB
/
inkeep.js
File metadata and controls
226 lines (201 loc) · 7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// customize
const inkeepSettings = {
baseSettings: {
apiKey: "1c24ba8dde97e56465741f2e64a51389662f75793a7d0ec1", // required
primaryBrandColor: "#4e89ff", // required -- your brand color, the color scheme is derived from this
organizationDisplayName: "PowerSync",
// ...optional settings
},
aiChatSettings: {
// ...optional settings
// aiAssistantAvatar: "https://mydomain.com/mylogo.svg",
exampleQuestions: [
"How do I get started?",
"What backend databases are supported?",
"What SDKs are available on the client-side?"
]
}
};
// The Mintlify search triggers, which we'll reuse to trigger the Inkeep modal
// const searchButtonContainerIds = [
// "search-bar-entry",
// "search-bar-entry-mobile",
// ];
// Clone and replace, needed to remove existing event listeners
// const clonedSearchButtonContainers = searchButtonContainerIds.map((id) => {
// const originalElement = document.getElementById(id);
// const clonedElement = originalElement.cloneNode(true);
// originalElement.parentNode.replaceChild(clonedElement, originalElement);
// return clonedElement;
// });
// Load the Inkeep component library
const inkeepScript = document.createElement("script");
inkeepScript.type = "module";
inkeepScript.src = "https://unpkg.com/@inkeep/cxkit-js@^0.5.36/dist/embed.js";
document.body.appendChild(inkeepScript);
// Once the Inkeep library is loaded, instantiate the UI components
inkeepScript.addEventListener("load", function () {
// Customization settings
// Instantiate the 'Ask AI' floating action button
Inkeep.ChatButton({
baseSettings: {
...inkeepSettings.baseSettings,
colorMode: {
sync: {
target: document.documentElement,
attributes: ["class"],
isDarkMode: (attributes) => !!attributes.class?.includes("dark"),
},
},
},
aiChatSettings: {
...inkeepSettings.aiChatSettings,
}
});
// Create and add the 'Ask AI' button next to the search bar
// function addAskAIButton() {
// // Function to create the Ask AI button
// function createAskAIButton() {
// const button = document.createElement("button");
// button.id = "ask-ai-button";
// button.innerHTML = "Ask AI";
// button.className = "ask-ai-button";
// // Style the button to match the "Get Started" button
// button.style.backgroundColor = inkeepSettings.baseSettings.primaryBrandColor;
// button.style.color = "white";
// button.style.border = "none";
// button.style.borderRadius = "12px"; // Pill-shaped to match the search bar in the screenshot
// button.style.padding = "8px 8px"; // Slightly wider padding
// button.style.marginLeft = "10px";
// button.style.cursor = "pointer";
// button.style.fontWeight = "500";
// button.style.fontSize = "14px";
// button.style.display = "flex";
// button.style.alignItems = "center";
// button.style.justifyContent = "center"; // Center text horizontally
// button.style.minWidth = "100px"; // Ensure the button has a minimum width
// button.style.boxShadow = "0 2px 4px rgba(0, 0, 0, 0.1)"; // Subtle shadow for depth
// button.style.transition = "all 0.2s ease"; // Smooth transition for hover effects
// // Add a subtle hover effect
// button.onmouseover = function() {
// this.style.backgroundColor = "#3a78f2"; // Slightly darker shade when hovering
// this.style.transform = "translateY(-1px)"; // Slight lift effect
// this.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.15)"; // Enhanced shadow on hover
// };
// button.onmouseout = function() {
// this.style.backgroundColor = inkeepSettings.baseSettings.primaryBrandColor;
// this.style.transform = "translateY(0)"; // Reset position
// this.style.boxShadow = "0 2px 4px rgba(0, 0, 0, 0.1)"; // Reset shadow
// };
// return button;
// }
// // Add the button only to the main search bar entry
// const searchContainer = document.getElementById("search-bar-entry");
// if (searchContainer) {
// const buttonContainer = document.createElement("div");
// buttonContainer.id = "ask-ai-button-container";
// buttonContainer.style.display = "flex";
// buttonContainer.style.alignItems = "center";
// const askAIButton = createAskAIButton();
// // Add click event to the button
// askAIButton.addEventListener("click", () => {
// modalChat.update({ modalSettings: { isOpen: true } });
// });
// // Insert the button after the search container
// buttonContainer.appendChild(askAIButton);
// // Insert the button container after the search container
// searchContainer.parentNode.insertBefore(buttonContainer, searchContainer.nextSibling);
// // Add CSS to hide the button on mobile
// const style = document.createElement('style');
// style.textContent = `
// @media (max-width: 768px) {
// #ask-ai-button-container {
// display: none !important;
// }
// }
// `;
// document.head.appendChild(style);
// }
// }
// Instantiate the 'Ask AI' modal chat
const modalChat = Inkeep.ModalChat({
baseSettings: {
...inkeepSettings.baseSettings,
colorMode: {
sync: {
target: document.documentElement,
attributes: ["class"],
isDarkMode: (attributes) => !!attributes.class?.includes("dark"),
},
},
},
aiChatSettings: {
...inkeepSettings.aiChatSettings,
},
modalSettings: {
onOpenChange: handleOpenChange,
},
});
function handleOpenChange(newOpen) {
modalChat.update({ modalSettings: { isOpen: newOpen } });
}
// Add the Ask AI button once the DOM is fully loaded
if (document.readyState === "complete") {
addAskAIButton();
} else {
window.addEventListener("load", addAskAIButton);
}
// The existing chat-button listener (if the element exists)
const existingChatButton = document.querySelector("#chat-button");
if (existingChatButton) {
existingChatButton.addEventListener("click", () => {
modalChat.update({ modalSettings: { isOpen: true } });
});
}
// Access chat methods
modalChat.clearChat();
// Instantiate the search bar modal
// const inkeepSearchModal = Inkeep.ModalSearchAndChat({
// baseSettings: {
// ...inkeepSettings.baseSettings,
// colorMode: {
// sync: {
// target: document.documentElement,
// attributes: ["class"],
// isDarkMode: (attributes) => !!attributes.class?.includes("dark"),
// },
// },
// },
// modalSettings: {
// onOpenChange: handleOpenChange,
// },
// });
// function handleOpenChange(newOpen) {
// inkeepSearchModal.update({ modalSettings: { isOpen: newOpen } });
// }
// When the Mintlify search bar elements are clicked, open the Inkeep search modal
// clonedSearchButtonContainers.forEach((trigger) => {
// trigger.addEventListener("click", function () {
// inkeepSearchModal.update({
// modalSettings: { isOpen: true },
// });
// });
// });
// Open the Inkeep Modal with cmd+k
// window.addEventListener(
// "keydown",
// (event) => {
// if (
// (event.metaKey || event.ctrlKey) &&
// (event.key === "k" || event.key === "K")
// ) {
// event.stopPropagation();
// inkeepSearchModal.update({
// modalSettings: { isOpen: true },
// });
// return false;
// }
// },
// true
// );
});