2022-07-04 15:27:40 +02:00
|
|
|
import React from 'react';
|
2022-07-04 15:41:14 +02:00
|
|
|
import ReactDOM from 'react-dom';
|
2022-07-13 07:36:47 +05:30
|
|
|
|
2022-07-04 15:27:40 +02:00
|
|
|
import App from './App';
|
|
|
|
|
2022-07-04 16:47:41 +02:00
|
|
|
const ROOT_DIV_ID = 'sodo-search-root';
|
2022-07-04 15:27:40 +02:00
|
|
|
|
2022-07-04 15:41:14 +02:00
|
|
|
function addRootDiv() {
|
|
|
|
const elem = document.createElement('div');
|
|
|
|
elem.id = ROOT_DIV_ID;
|
|
|
|
document.body.appendChild(elem);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSiteData() {
|
|
|
|
/**
|
|
|
|
* @type {HTMLElement}
|
|
|
|
*/
|
2022-07-04 16:46:27 +02:00
|
|
|
const scriptTag = document.querySelector('script[data-sodo-search]');
|
2022-07-04 15:41:14 +02:00
|
|
|
if (scriptTag) {
|
2022-07-07 11:09:53 +02:00
|
|
|
const adminUrl = scriptTag.dataset.sodoSearch;
|
2022-07-04 15:41:14 +02:00
|
|
|
const apiKey = scriptTag.dataset.key;
|
2022-07-25 22:23:09 +05:30
|
|
|
const stylesUrl = scriptTag.dataset.styles;
|
2024-09-24 07:39:32 -04:00
|
|
|
const locale = scriptTag.dataset.locale || 'en';
|
|
|
|
return {adminUrl, apiKey, stylesUrl, locale};
|
2022-07-04 15:41:14 +02:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-07-07 11:09:53 +02:00
|
|
|
function setup() {
|
2022-07-04 15:41:14 +02:00
|
|
|
addRootDiv();
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
2024-09-24 07:39:32 -04:00
|
|
|
const {adminUrl, apiKey, stylesUrl, locale} = getSiteData();
|
2022-07-07 11:09:53 +02:00
|
|
|
const adminBaseUrl = (adminUrl || window.location.origin)?.replace(/\/+$/, '');
|
|
|
|
setup();
|
2022-07-04 15:41:14 +02:00
|
|
|
ReactDOM.render(
|
|
|
|
<React.StrictMode>
|
2022-07-06 10:16:15 +02:00
|
|
|
<App
|
2022-07-07 11:09:53 +02:00
|
|
|
adminUrl={adminBaseUrl} apiKey={apiKey}
|
2024-09-24 07:39:32 -04:00
|
|
|
stylesUrl={stylesUrl} locale={locale}
|
2022-07-06 10:16:15 +02:00
|
|
|
/>
|
2022-07-04 15:41:14 +02:00
|
|
|
</React.StrictMode>,
|
|
|
|
document.getElementById(ROOT_DIV_ID)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
init();
|