You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					80 lines
				
				2.5 KiB
			
		
		
			
		
	
	
					80 lines
				
				2.5 KiB
			| 
											3 years ago
										 | "use strict"; | ||
|  | 
 | ||
|  | Object.defineProperty(exports, "__esModule", { | ||
|  |   value: true | ||
|  | }); | ||
|  | exports.default = void 0; | ||
|  | 
 | ||
|  | var _designSystem = require("@adminjs/design-system"); | ||
|  | 
 | ||
|  | var _viewHelpers = _interopRequireDefault(require("../backend/utils/view-helpers/view-helpers")); | ||
|  | 
 | ||
|  | var _store = require("./store"); | ||
|  | 
 | ||
|  | var _optionsParser = require("../backend/utils/options-parser/options-parser"); | ||
|  | 
 | ||
|  | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|  | 
 | ||
|  | /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
|  | 
 | ||
|  | /** | ||
|  |  * Renders (SSR) html for given location | ||
|  |  * | ||
|  |  * @param {AdminJS} admin | ||
|  |  * @param {Object} [currentAdmin] | ||
|  |  * @param {String} currentAdmin.email | ||
|  |  * @param {String} location='/' | ||
|  |  * | ||
|  |  * @private | ||
|  |  */ | ||
|  | const html = async (admin, currentAdmin, location = '/') => { | ||
|  |   const h = new _viewHelpers.default({ | ||
|  |     options: admin.options | ||
|  |   }); | ||
|  |   const store = await (0, _store.initializeStore)(admin, currentAdmin); | ||
|  |   const reduxState = store.getState(); | ||
|  |   const { | ||
|  |     branding, | ||
|  |     assets | ||
|  |   } = reduxState; | ||
|  |   const scripts = (assets && assets.scripts || []).map(s => `<script src="${s}"></script>`); | ||
|  |   const styles = (assets && assets.styles || []).map(l => `<link rel="stylesheet" type="text/css" href="${l}">`); | ||
|  |   const theme = (0, _designSystem.combineStyles)(branding.theme || {}); | ||
|  |   const faviconTag = (0, _optionsParser.getFaviconFromBranding)(branding); | ||
|  |   return `
 | ||
|  |     <!DOCTYPE html> | ||
|  |     <html> | ||
|  |     <head> | ||
|  |       <script> | ||
|  |         window.REDUX_STATE = ${JSON.stringify(reduxState)}; | ||
|  |         window.THEME = ${JSON.stringify(theme)}; | ||
|  |         window.AdminJS = { Components: {} }; | ||
|  |       </script> | ||
|  |       <meta charset="utf-8"> | ||
|  |       <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
|  |       <title>${branding.companyName}</title> | ||
|  |       ${faviconTag} | ||
|  | 
 | ||
|  |       <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" type="text/css"> | ||
|  | 
 | ||
|  |       <script src="${h.assetPath('global.bundle.js', assets)}"></script> | ||
|  |       <script src="${h.assetPath('design-system.bundle.js', assets)}"></script> | ||
|  |       <script src="${h.assetPath('app.bundle.js', assets)}"></script> | ||
|  |       <script src="${h.assetPath('components.bundle.js', assets)}"></script> | ||
|  |       ${styles.join('\n')} | ||
|  |     </head> | ||
|  |     <body> | ||
|  |       <div id="app" /> | ||
|  |       <script> | ||
|  |         var app = document.getElementById('app'); | ||
|  |         var root = createRoot(app) | ||
|  |         root.render(AdminJS.Application); | ||
|  |       </script> | ||
|  |       ${scripts.join('\n')} | ||
|  |     </body> | ||
|  |     </html> | ||
|  |   `;
 | ||
|  | }; | ||
|  | 
 | ||
|  | var _default = html; | ||
|  | exports.default = _default; |