-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
339 lines (295 loc) · 14.4 KB
/
index.html
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./assets/styles.css">
<link rel="stylesheet" href="./assets/hljs.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto&family=Ubuntu&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script src="https://kit.fontawesome.com/c1798fb82d.js" crossorigin="anonymous"></script>
<title>Snap Documentation</title>
<link rel="icon" href="./favicon.svg">
<script src="https://snapui.searchspring.io/vrntn7/bundle.js" id="searchspring-context"></script>
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-router@4"></script>
<script>
function modifyLinks(markdown) {
var replaces = [
{ a: "(https://searchspring.github.io/snap/#/start-setup)", b: "(#/start-setup)"},
{ a: "(https://searchspring.github.io/snapi-explorer/)", b: "(#/api-explorer)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/SEARCH.md)", b: "(#/advanced-search)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/PREACT_DISPLAYING_DATA.md)", b: "(#/start-preact-events)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/PREACT_BADGES.md)", b: "(#/start-preact-badges)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION.md)", b: "(#/integration)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_BACKGROUND_FILTERS.md)", b: "(#/integration-backgroundFilters)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_CONTEXT.md)", b: "(#/integration-context)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_DEBUGGING.md)", b: "(#/integration-debugging)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_TRACKING.md)", b: "(#/integration-tracking)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_RECOMMENDATIONS.md)", b: "(#/integration-recommendations)"},
{ a: "(https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_LEGACY_RECOMMENDATIONS.md)", b: "(#/integration-legacy-recommendations)"},
{ a: "https://github.com/searchspring/snap/blob/main/images/snap-dependencies.jpg?raw=true", b: "./images/snap-dependencies.jpg"},
{ a: "https://github.com/searchspring/snap/blob/main/images/snap-dependencies.png?raw=true", b: "./images/snap-dependencies.png"},
{ a: "https://github.com/searchspring/snap/blob/main/images/logger-example.png?raw=true", b: "./images/logger-example.png"},
{ a: "https://github.com/searchspring/snap/blob/main/images/emojis.png?raw=true", b: "./images/emojis.png"},
{ a: "https://github.com/searchspring/snap/blob/main/images/colors.png?raw=true", b: "./images/colors.png"},
{ a: "https://github.com/searchspring/snap/blob/main/images/colors.png?raw=true", b: "./images/colors.png"},
{ a: "https://github.com/searchspring/snap/blob/main/images/nebo404.svg?raw=true", b: "./images/nebo404.svg"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-client)", b: "(#/package-client)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx)", b: "(#/package-storeMobx)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager)", b: "(#/package-urlManager)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/Translators/Url)", b: "(#/package-urlManager-translators-url)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-event-manager)", b: "(#/package-eventManager)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-profiler)", b: "(#/package-profiler)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-platforms)", b: "(#/package-platforms)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-logger)", b: "(#/package-logger)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-controller)", b: "(#/package-controller)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-toolbox)", b: "(#/package-toolbox)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-tracker)", b: "(#/package-tracker)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-preact-components)", b: "(#/components-preact)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-preact)", b: "(#/start-preact)"},
{ a: "(https://github.com/searchspring/snap/blob/main/packages/snap-preact/src/Instantiators/README.md)", b: "(#/package-preact-instantiator)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-toolbox/src/DomTargeter)", b: "(#/package-toolbox-domTargeter)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-toolbox/src/getContext)", b: "(#/package-toolbox-getContext)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx/src/Storage)", b: "(#/package-storeMobx-storage)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx/src/Search)", b: "(#/package-storeMobx-search)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx/src/Autocomplete)", b: "(#/package-storeMobx-autocomplete)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx/src/Recommendation)", b: "(#/package-storeMobx-recommendation)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx/src/Finder)", b: "(#/package-storeMobx-finder)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-store-mobx/src/Abstract)", b: "(#/package-storeMobx-abstract)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Abstract)", b: "(#/package-controller-abstract)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Search)", b: "(#/package-controller-search)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Autocomplete)", b: "(#/package-controller-autocomplete)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Recommendation)", b: "(#/package-controller-recommendation)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Finder)", b: "(#/package-controller-finder)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-platforms/bigcommerce)", b: "(#/package-platforms-bigcommerce)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-platforms/magento2)", b: "(#/package-platforms-magento2)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-platforms/shopify)", b: "(#/package-platforms-shopify)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/Translators)", b: "(#/package-urlManager-translators)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/linkers)", b: "(#/package-urlManager-linkers)" },
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/Translators/Url)", b: "(#/package-urlManager-translators-url)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/Translators/QueryString)", b: "(#/package-urlManager-translators-queryString)"},
{ a: "(https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/linkers/react)", b: "(#/package-urlManager-linkers-react)"},
{ a: "(https://searchspring.github.io/snap/)", b: "(#/)"},
];
replaces.forEach(function(replace) {
markdown = markdown.replaceAll(replace.a, replace.b);
});
return markdown
}
import('./docs/documents.js').then(function (_) {
const documents = _.default;
const App = {
data() {
return {
documents
}
},
computed: {
routes() {
const routeMap = this.documents.reduce((acc, section) => {
section?.links?.forEach((link) => {
if (link.route) {
acc[link.route] = link;
}
link?.links?.forEach((sublink) => {
if (sublink.route) {
acc[sublink.route] = sublink;
}
})
});
return acc;
}, {});
return routeMap;
},
},
template: `
<Navigation :documents="documents"></Navigation>
<div id="content">
<router-view :routes="routes"></router-view>
</div>
<div id="ac-overlay"></div>
`
}
const app = Vue.createApp(App);
app.component('Content', {
props: ['routes'],
template: `
<iframe v-if="routeData.type == 'iframe'" :src="routeData.url" id="frame" @load="onLoad"></iframe>
<Markdown v-else-if="routeData.type == 'markdown'" :src="routeData.url" />
<div id="searchWrapper"></div>
`,
computed: {
currentRoute() {
return this.$route.path;
},
routeData() {
const params = decodeURIComponent(window.location.href.split('?params=')[1] || '');
if (params && this.routes[this.currentRoute] && this.routes[this.currentRoute].url && this.routes[this.currentRoute].type === 'iframe') {
const currentiFrameSrc = document.querySelector('iframe')?.src;
let url = currentiFrameSrc || `${this.routes[this.currentRoute].url}${params}`;
if(params.includes('&ac')) {
url = `${this.routes[this.currentRoute].url}${params}`;
}
if(url.startsWith('http') && url.includes('/packages/')) {
url = `./packages/${url.split('/packages/')[1]}`
}
return { type: 'iframe', url }
}
return this.routes[this.currentRoute] || { type: 'markdown', url: './docs/404.md' };
}
},
methods: {
onLoad() {
const mutations = [];
// Select the node that will be observed for mutations
const targetNode = document.getElementById('frame').contentWindow.document.querySelector('title');
// Options for the observer (which mutations to observe)
const config = { characterData: true, attributes: true, childList: true, subtree: true};
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
mutations.push(mutationsList[0])
if(mutationsList.length && mutations.length > 1) {
const url = mutationsList[0].target.baseURI;
const params = encodeURIComponent(`?${url.split('?')[1]}`);
const fullRoute = window.location.href.split('#')[1] // '/components-preact?params=%3Fpath%3D%2Fdocs%2FOrganisms-Autocomplete'
const route = fullRoute.split('?')[0]; // '/components-preact'
const newRoute = `${route}?params=${params}`;
window.location.hash = newRoute;
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
},
}
});
app.component('Markdown', {
props: ['src'],
template: `
<div id="markdown" v-html="markedHTML"></div>
`,
data() {
return {
markdown: '',
}
},
watch: {
src() {
this.getMarkdown(this.src);
}
},
computed: {
markedHTML() {
return marked(this.markdown);
}
},
created() {
this.getMarkdown(this.src);
},
updated() {
window.highlight();
},
methods: {
async getMarkdown(file) {
this.markdown = '';
const response = await fetch(file);
let text = await response.text()
this.iframe = "";
this.markdown = modifyLinks(text);
}
}
});
app.component('Link', {
props: ['link', 'active'],
template: `
<router-link v-if="link.route && !link.hidden" :key="link.route" :to="'' + link.route" :class="{ 'active': active }">
{{link.label}}
</router-link>
<a v-else-if="link.type == 'external'" :href="link.url" target="_blank">
{{link.label}}
<i v-if="link.icon" :class="link.icon"></i>
</a>
`,
});
app.component('Navigation', {
props: ['documents'],
components: ['Link'],
data() {
return {
navVisible: true,
}
},
computed: {
currentRoute() {
return this.$route.path;
}
},
methods: {
toggleNav() {
this.navVisible = !this.navVisible
},
inRoute(link) {
if (link?.route) {
const includedRoutes = [link.route];
link.links?.forEach(sublink => includedRoutes.push(sublink.route));
return includedRoutes.includes(this.currentRoute);
}
}
},
template: `
<div id="navigation-wrapper">
<router-link :key="'/'" :to="'/'">
<div id="header">
<div class="logo-container">
<img src="./images/logo-snap.svg"/>
</div>
</div>
</router-link>
<span class="collapseNav" @click="toggleNav"><i class="fas fa-bars fa-2x"></i></span>
<div id="search-container">
</div>
<div id="navigation" :class="{ visible: navVisible }" >
<div v-for="section in documents" class="section">
<h3>{{ section.categoryName }}</h3>
<ul class="links">
<li v-for="link in section.links">
<Link :link="link" :active="inRoute(link)" />
<ul v-if="link.links && inRoute(link)" class="sublinks">
<li v-for="sublink in link.links">
<Link :link="sublink" :active="inRoute(sublink)"/>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
`,
});
const routes = [
{ path: '/', component: app.component('Content') },
{ path: '/:path', component: app.component('Content') },
]
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes,
});
app.use(router);
app.mount('#app');
window.highlight = function() {
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightBlock(block);
});
}
})
</script>
</body>
</html>