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-04 15:27:40 +02:00
|
|
|
import './index.css';
|
|
|
|
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-06 10:16:15 +02:00
|
|
|
const appVersion = scriptTag.dataset.version;
|
2022-07-07 11:09:53 +02:00
|
|
|
return {adminUrl, apiKey, appVersion};
|
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() {
|
2022-07-07 11:09:53 +02:00
|
|
|
const {adminUrl, apiKey, appVersion} = getSiteData();
|
|
|
|
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}
|
2022-07-06 10:16:15 +02:00
|
|
|
appVersion={appVersion}
|
|
|
|
/>
|
2022-07-04 15:41:14 +02:00
|
|
|
</React.StrictMode>,
|
|
|
|
document.getElementById(ROOT_DIV_ID)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
init();
|