@plurid/plurid-react-server 0.0.0-12 → 0.0.0-15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distribution/data/interfaces/external/index.d.ts +6 -5
- package/distribution/data/interfaces/internal/index.d.ts +4 -1
- package/distribution/index.es.js +22 -35
- package/distribution/index.js +22 -59
- package/distribution/objects/ContentGenerator/index.d.ts +0 -2
- package/distribution/objects/Renderer/index.d.ts +1 -0
- package/distribution/objects/Server/index.d.ts +1 -0
- package/package.json +22 -22
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { Helmet } from 'react-helmet-async';
|
|
3
|
-
import { PluridRoute, PluridRoutePlane, PluridPreserve, IsoMatcherRouteResult } from '@plurid/plurid-data';
|
|
3
|
+
import { PluridRoute, PluridRoutePlane, PluridPreserve, IsoMatcherRouteResult, PluridRouterProperties } from '@plurid/plurid-data';
|
|
4
4
|
import { PluridReactComponent } from '@plurid/plurid-react';
|
|
5
5
|
export declare type PluridServerMiddleware = (request: express.Request, response: express.Response, next: express.NextFunction) => void;
|
|
6
6
|
export declare type ServerRequest = express.Request & {
|
|
@@ -65,11 +65,10 @@ export interface PluridServerOptions {
|
|
|
65
65
|
stiller: PluridStillerOptions;
|
|
66
66
|
}
|
|
67
67
|
export declare type PluridServerPartialOptions = Partial<PluridServerOptions>;
|
|
68
|
-
export interface PluridServerService<P = any> {
|
|
68
|
+
export interface PluridServerService<P = any, PP = any> {
|
|
69
69
|
name: string;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
properties?: P;
|
|
70
|
+
Provider: P;
|
|
71
|
+
properties?: PP;
|
|
73
72
|
}
|
|
74
73
|
export interface PluridServerConfiguration {
|
|
75
74
|
routes: PluridRoute<PluridReactComponent>[];
|
|
@@ -80,6 +79,7 @@ export interface PluridServerConfiguration {
|
|
|
80
79
|
middleware?: PluridServerMiddleware[];
|
|
81
80
|
exterior?: PluridReactComponent;
|
|
82
81
|
shell?: PluridReactComponent;
|
|
82
|
+
routerProperties?: Partial<PluridRouterProperties<PluridReactComponent>>;
|
|
83
83
|
/**
|
|
84
84
|
* Replace the internal plurid plane with a custom implementation.
|
|
85
85
|
*/
|
|
@@ -126,6 +126,7 @@ export interface PluridServerTemplateConfiguration {
|
|
|
126
126
|
* Default: `__PRELOADED_PLURID_METASTATE__`
|
|
127
127
|
*/
|
|
128
128
|
defaultPreloadedPluridMetastate?: string;
|
|
129
|
+
minify?: boolean;
|
|
129
130
|
}
|
|
130
131
|
export interface PluridStillerOptions {
|
|
131
132
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Helmet } from 'react-helmet-async';
|
|
2
2
|
import { ServerStyleSheet } from 'styled-components';
|
|
3
|
-
import { Indexed, PluridRoute, PluridRoutePlane, PluridPreserveResponse } from '@plurid/plurid-data';
|
|
3
|
+
import { Indexed, PluridRoute, PluridRoutePlane, PluridPreserveResponse, PluridRouterProperties } from '@plurid/plurid-data';
|
|
4
4
|
import { PluridReactComponent } from '@plurid/plurid-react';
|
|
5
5
|
import { PluridServerService, PluridStillerOptions } from '../external';
|
|
6
6
|
export interface PluridRendererConfiguration {
|
|
@@ -19,6 +19,7 @@ export interface PluridRendererConfiguration {
|
|
|
19
19
|
defaultPreloadedPluridMetastate: string | undefined;
|
|
20
20
|
pluridMetastate: string;
|
|
21
21
|
globals: Record<string, string> | undefined;
|
|
22
|
+
minify: boolean | undefined;
|
|
22
23
|
}
|
|
23
24
|
export interface StillerOptions {
|
|
24
25
|
host: string;
|
|
@@ -51,6 +52,7 @@ export interface PluridContentGeneratorData {
|
|
|
51
52
|
helmet: Helmet;
|
|
52
53
|
exterior: PluridReactComponent | undefined;
|
|
53
54
|
shell: PluridReactComponent | undefined;
|
|
55
|
+
routerProperties: Partial<PluridRouterProperties<PluridReactComponent>>;
|
|
54
56
|
routes: PluridRoute<PluridReactComponent>[];
|
|
55
57
|
planes: PluridRoutePlane<PluridReactComponent>[];
|
|
56
58
|
pluridMetastate: any;
|
|
@@ -78,4 +80,5 @@ export interface RendererTemplateData {
|
|
|
78
80
|
defaultPreloadedPluridMetastate: string;
|
|
79
81
|
pluridMetastate: string;
|
|
80
82
|
globals: Record<string, string>;
|
|
83
|
+
minify: boolean;
|
|
81
84
|
}
|
package/distribution/index.es.js
CHANGED
|
@@ -160,7 +160,9 @@ const defaultStillerOptions = {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
const cleanTemplate = template => minify(template, {
|
|
163
|
-
collapseWhitespace: true
|
|
163
|
+
collapseWhitespace: true,
|
|
164
|
+
conservativeCollapse: true,
|
|
165
|
+
collapseInlineTagWhitespace: false
|
|
164
166
|
});
|
|
165
167
|
|
|
166
168
|
const resolveBackgroundStyle = store => {
|
|
@@ -213,15 +215,18 @@ const NOT_FOUND_TEMPLATE = cleanTemplate(`\n<!DOCTYPE html>\n<html>\n <head>\
|
|
|
213
215
|
const SERVER_ERROR_TEMPLATE = cleanTemplate(`\n<!DOCTYPE html>\n<html>\n <head>\n <title>[500] Server Error</title>\n <style>\n html, body {\n margin: 0;\n background: #242b33;\n color: #ddd;\n user-select: none;\n }\n\n .error {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-family: 'Ubuntu', -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto;\n }\n </style>\n </head>\n\n <body>\n <div class="error">[500] Server Error</div>\n </body>\n</html>\n`);
|
|
214
216
|
|
|
215
217
|
const template = data => {
|
|
216
|
-
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, root: root, content: content, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals} = data;
|
|
218
|
+
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, root: root, content: content, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals, minify: minify} = data;
|
|
217
219
|
const injectedGlobals = globalsInjector(globals);
|
|
218
220
|
const templateString = `\n<!DOCTYPE html>\n<html lang="${htmlLanguage}" ${htmlAttributes}>\n <head>\n ${head}\n\n ${defaultStyle && `<style>\n ${defaultStyle}\n </style>`}\n\n ${styles}\n\n ${headScripts.join("\n")}\n\n <script src="${vendorScriptSource}"><\/script>\n <script defer src="${mainScriptSource}"><\/script>\n </head>\n <body ${bodyAttributes}>\n <div id="${root}">${content}</div>\n\n <script>\n ${injectedGlobals}\n window.${defaultPreloadedPluridMetastate} = ${pluridMetastate};\n <\/script>\n\n ${bodyScripts.join("\n")}\n </body>\n</html>\n `;
|
|
221
|
+
if (!minify) {
|
|
222
|
+
return templateString;
|
|
223
|
+
}
|
|
219
224
|
return cleanTemplate(templateString);
|
|
220
225
|
};
|
|
221
226
|
|
|
222
227
|
class PluridRenderer {
|
|
223
228
|
constructor(configuration) {
|
|
224
|
-
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, content: content, root: root, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals} = configuration;
|
|
229
|
+
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, content: content, root: root, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals, minify: minify} = configuration;
|
|
225
230
|
const {gradientBackground: gradientBackground, gradientForeground: gradientForeground} = resolveBackgroundStyle("");
|
|
226
231
|
const defaultStyleBasic = `\n body {\n background: radial-gradient(ellipse at center, ${gradientBackground} 0%, ${gradientForeground} 100%);\n height: 100%;\n margin: 0;\n }\n `;
|
|
227
232
|
this.htmlLanguage = htmlLanguage || DEFAULT_RENDERER_LANGUAGE;
|
|
@@ -239,6 +244,7 @@ class PluridRenderer {
|
|
|
239
244
|
this.defaultPreloadedPluridMetastate = defaultPreloadedPluridMetastate || DEFAULT__PRELOADED_PLURID_METASTATE__;
|
|
240
245
|
this.pluridMetastate = pluridMetastate || DEFAULT_RENDERER_PLURID_STATE;
|
|
241
246
|
this.globals = globals !== null && globals !== void 0 ? globals : {};
|
|
247
|
+
this.minify = minify !== null && minify !== void 0 ? minify : true;
|
|
242
248
|
}
|
|
243
249
|
html() {
|
|
244
250
|
const data = {
|
|
@@ -256,7 +262,8 @@ class PluridRenderer {
|
|
|
256
262
|
content: this.content,
|
|
257
263
|
defaultPreloadedPluridMetastate: this.defaultPreloadedPluridMetastate,
|
|
258
264
|
pluridMetastate: this.pluridMetastate,
|
|
259
|
-
globals: this.globals
|
|
265
|
+
globals: this.globals,
|
|
266
|
+
minify: this.minify
|
|
260
267
|
};
|
|
261
268
|
return template(data);
|
|
262
269
|
}
|
|
@@ -274,19 +281,11 @@ const wrapping = (WrappedComponent, WrappeeComponent, properties) => class exten
|
|
|
274
281
|
class PluridContentGenerator {
|
|
275
282
|
constructor(data) {
|
|
276
283
|
this.data = data;
|
|
277
|
-
this.importProviders();
|
|
278
284
|
}
|
|
279
285
|
render() {
|
|
280
286
|
var _a;
|
|
281
287
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
282
|
-
|
|
283
|
-
yield this.importProviders();
|
|
284
|
-
}
|
|
285
|
-
if (!this.providers) {
|
|
286
|
-
console.log("Plurid Server Error :: Providers not loaded");
|
|
287
|
-
return "";
|
|
288
|
-
}
|
|
289
|
-
const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname, hostname: hostname} = this.data;
|
|
288
|
+
const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, routerProperties: routerProperties, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname, hostname: hostname} = this.data;
|
|
290
289
|
const RoutedApplication = () => React.createElement(PluridProvider, {
|
|
291
290
|
metastate: pluridMetastate
|
|
292
291
|
}, React.createElement(PluridRouterStatic, {
|
|
@@ -299,14 +298,15 @@ class PluridContentGenerator {
|
|
|
299
298
|
gateway: gateway,
|
|
300
299
|
gatewayEndpoint: gatewayEndpoint,
|
|
301
300
|
gatewayQuery: gatewayQuery,
|
|
302
|
-
hostname: hostname
|
|
301
|
+
hostname: hostname,
|
|
302
|
+
routerProperties: routerProperties
|
|
303
303
|
}));
|
|
304
304
|
let Wrap = wrapping(HelmetProvider, RoutedApplication, {
|
|
305
305
|
context: helmet
|
|
306
306
|
});
|
|
307
307
|
for (const service of services) {
|
|
308
308
|
const preserveProperties = (_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.providers) === null || _a === void 0 ? void 0 : _a[service.name];
|
|
309
|
-
Wrap = wrapping(
|
|
309
|
+
Wrap = wrapping(service.Provider, Wrap, Object.assign(Object.assign({}, service.properties), preserveProperties));
|
|
310
310
|
}
|
|
311
311
|
const content = renderToString(React.createElement(StyleSheetManager, {
|
|
312
312
|
sheet: stylesheet.instance
|
|
@@ -314,22 +314,6 @@ class PluridContentGenerator {
|
|
|
314
314
|
return content;
|
|
315
315
|
}));
|
|
316
316
|
}
|
|
317
|
-
importProviders() {
|
|
318
|
-
return __awaiter(this, void 0, void 0, (function*() {
|
|
319
|
-
const providers = {};
|
|
320
|
-
for (const service of this.data.services) {
|
|
321
|
-
try {
|
|
322
|
-
const importedService = yield import(service.package);
|
|
323
|
-
const ImportedServiceProvider = service.provider === "default" ? importedService : importedService[service.provider];
|
|
324
|
-
providers[service.name] = ImportedServiceProvider;
|
|
325
|
-
} catch (error) {
|
|
326
|
-
console.log(`Plurid Server Error :: Service '${service.name}' from '${service.package}' could not be imported.`);
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
this.providers = providers;
|
|
331
|
-
}));
|
|
332
|
-
}
|
|
333
317
|
}
|
|
334
318
|
|
|
335
319
|
const resolveElementFromPlaneMatch = (planeMatch, elementqlEndpoint) => {
|
|
@@ -352,7 +336,7 @@ const {IsoMatcher: PluridIsoMatcher} = routing;
|
|
|
352
336
|
|
|
353
337
|
class PluridServer {
|
|
354
338
|
constructor(configuration) {
|
|
355
|
-
const {routes: routes, planes: planes, preserves: preserves, helmet: helmet, styles: styles, middleware: middleware, exterior: exterior, shell: shell, services: services, options: options, template: template, usePTTP: usePTTP, pttpHandler: pttpHandler, elementqlEndpoint: elementqlEndpoint} = configuration;
|
|
339
|
+
const {routes: routes, planes: planes, preserves: preserves, helmet: helmet, styles: styles, middleware: middleware, exterior: exterior, shell: shell, routerProperties: routerProperties, services: services, options: options, template: template, usePTTP: usePTTP, pttpHandler: pttpHandler, elementqlEndpoint: elementqlEndpoint} = configuration;
|
|
356
340
|
this.routes = routes;
|
|
357
341
|
this.planes = planes || [];
|
|
358
342
|
this.preserves = preserves;
|
|
@@ -361,6 +345,7 @@ class PluridServer {
|
|
|
361
345
|
this.middleware = middleware || [];
|
|
362
346
|
this.exterior = exterior;
|
|
363
347
|
this.shell = shell;
|
|
348
|
+
this.routerProperties = routerProperties || {};
|
|
364
349
|
this.services = services || [];
|
|
365
350
|
this.options = this.handleOptions(options);
|
|
366
351
|
this.template = template;
|
|
@@ -730,11 +715,11 @@ class PluridServer {
|
|
|
730
715
|
}));
|
|
731
716
|
}
|
|
732
717
|
renderApplication(isoMatch, preserveResult, matchedPlane) {
|
|
733
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
718
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
734
719
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
735
720
|
const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
|
|
736
721
|
const mergedHtmlLanguage = ((_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _a === void 0 ? void 0 : _a.htmlLanguage) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.htmlLanguage);
|
|
737
|
-
const pluridMetastate = yield serverComputeMetastate(isoMatch, this.routes, globals);
|
|
722
|
+
const pluridMetastate = yield serverComputeMetastate(isoMatch, this.routes, globals, this.options.hostname);
|
|
738
723
|
const {content: content, styles: styles} = yield this.getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane);
|
|
739
724
|
const stringedStyles = this.styles.reduce(((accumulator, style) => accumulator + style), "");
|
|
740
725
|
const preserveStyles = ((_d = (_c = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _c === void 0 ? void 0 : _c.styles) === null || _d === void 0 ? void 0 : _d.join(" ")) || "";
|
|
@@ -765,7 +750,8 @@ class PluridServer {
|
|
|
765
750
|
content: content,
|
|
766
751
|
defaultPreloadedPluridMetastate: (_r = this.template) === null || _r === void 0 ? void 0 : _r.defaultPreloadedPluridMetastate,
|
|
767
752
|
pluridMetastate: JSON.stringify(pluridMetastate),
|
|
768
|
-
globals: globals
|
|
753
|
+
globals: globals,
|
|
754
|
+
minify: (_s = this.template) === null || _s === void 0 ? void 0 : _s.minify
|
|
769
755
|
});
|
|
770
756
|
return renderer;
|
|
771
757
|
}));
|
|
@@ -784,6 +770,7 @@ class PluridServer {
|
|
|
784
770
|
stylesheet: stylesheet,
|
|
785
771
|
exterior: this.exterior,
|
|
786
772
|
shell: this.shell,
|
|
773
|
+
routerProperties: this.routerProperties,
|
|
787
774
|
helmet: this.helmet,
|
|
788
775
|
routes: this.routes,
|
|
789
776
|
planes: this.planes,
|
package/distribution/index.js
CHANGED
|
@@ -44,26 +44,6 @@ function _interopDefaultLegacy(e) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function _interopNamespace(e) {
|
|
48
|
-
if (e && e.__esModule) return e;
|
|
49
|
-
var n = Object.create(null);
|
|
50
|
-
if (e) {
|
|
51
|
-
Object.keys(e).forEach((function(k) {
|
|
52
|
-
if (k !== "default") {
|
|
53
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
54
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function() {
|
|
57
|
-
return e[k];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
n["default"] = e;
|
|
64
|
-
return Object.freeze(n);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
47
|
var fs__default = _interopDefaultLegacy(fs);
|
|
68
48
|
|
|
69
49
|
var path__default = _interopDefaultLegacy(path);
|
|
@@ -208,7 +188,9 @@ const defaultStillerOptions = {
|
|
|
208
188
|
};
|
|
209
189
|
|
|
210
190
|
const cleanTemplate = template => htmlMinifier.minify(template, {
|
|
211
|
-
collapseWhitespace: true
|
|
191
|
+
collapseWhitespace: true,
|
|
192
|
+
conservativeCollapse: true,
|
|
193
|
+
collapseInlineTagWhitespace: false
|
|
212
194
|
});
|
|
213
195
|
|
|
214
196
|
const resolveBackgroundStyle = store => {
|
|
@@ -261,15 +243,18 @@ const NOT_FOUND_TEMPLATE = cleanTemplate(`\n<!DOCTYPE html>\n<html>\n <head>\
|
|
|
261
243
|
const SERVER_ERROR_TEMPLATE = cleanTemplate(`\n<!DOCTYPE html>\n<html>\n <head>\n <title>[500] Server Error</title>\n <style>\n html, body {\n margin: 0;\n background: #242b33;\n color: #ddd;\n user-select: none;\n }\n\n .error {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-family: 'Ubuntu', -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto;\n }\n </style>\n </head>\n\n <body>\n <div class="error">[500] Server Error</div>\n </body>\n</html>\n`);
|
|
262
244
|
|
|
263
245
|
const template = data => {
|
|
264
|
-
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, root: root, content: content, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals} = data;
|
|
246
|
+
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, root: root, content: content, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals, minify: minify} = data;
|
|
265
247
|
const injectedGlobals = globalsInjector(globals);
|
|
266
248
|
const templateString = `\n<!DOCTYPE html>\n<html lang="${htmlLanguage}" ${htmlAttributes}>\n <head>\n ${head}\n\n ${defaultStyle && `<style>\n ${defaultStyle}\n </style>`}\n\n ${styles}\n\n ${headScripts.join("\n")}\n\n <script src="${vendorScriptSource}"><\/script>\n <script defer src="${mainScriptSource}"><\/script>\n </head>\n <body ${bodyAttributes}>\n <div id="${root}">${content}</div>\n\n <script>\n ${injectedGlobals}\n window.${defaultPreloadedPluridMetastate} = ${pluridMetastate};\n <\/script>\n\n ${bodyScripts.join("\n")}\n </body>\n</html>\n `;
|
|
249
|
+
if (!minify) {
|
|
250
|
+
return templateString;
|
|
251
|
+
}
|
|
267
252
|
return cleanTemplate(templateString);
|
|
268
253
|
};
|
|
269
254
|
|
|
270
255
|
class PluridRenderer {
|
|
271
256
|
constructor(configuration) {
|
|
272
|
-
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, content: content, root: root, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals} = configuration;
|
|
257
|
+
const {htmlLanguage: htmlLanguage, head: head, htmlAttributes: htmlAttributes, bodyAttributes: bodyAttributes, defaultStyle: defaultStyle, styles: styles, headScripts: headScripts, bodyScripts: bodyScripts, vendorScriptSource: vendorScriptSource, mainScriptSource: mainScriptSource, content: content, root: root, defaultPreloadedPluridMetastate: defaultPreloadedPluridMetastate, pluridMetastate: pluridMetastate, globals: globals, minify: minify} = configuration;
|
|
273
258
|
const {gradientBackground: gradientBackground, gradientForeground: gradientForeground} = resolveBackgroundStyle("");
|
|
274
259
|
const defaultStyleBasic = `\n body {\n background: radial-gradient(ellipse at center, ${gradientBackground} 0%, ${gradientForeground} 100%);\n height: 100%;\n margin: 0;\n }\n `;
|
|
275
260
|
this.htmlLanguage = htmlLanguage || DEFAULT_RENDERER_LANGUAGE;
|
|
@@ -287,6 +272,7 @@ class PluridRenderer {
|
|
|
287
272
|
this.defaultPreloadedPluridMetastate = defaultPreloadedPluridMetastate || DEFAULT__PRELOADED_PLURID_METASTATE__;
|
|
288
273
|
this.pluridMetastate = pluridMetastate || DEFAULT_RENDERER_PLURID_STATE;
|
|
289
274
|
this.globals = globals !== null && globals !== void 0 ? globals : {};
|
|
275
|
+
this.minify = minify !== null && minify !== void 0 ? minify : true;
|
|
290
276
|
}
|
|
291
277
|
html() {
|
|
292
278
|
const data = {
|
|
@@ -304,7 +290,8 @@ class PluridRenderer {
|
|
|
304
290
|
content: this.content,
|
|
305
291
|
defaultPreloadedPluridMetastate: this.defaultPreloadedPluridMetastate,
|
|
306
292
|
pluridMetastate: this.pluridMetastate,
|
|
307
|
-
globals: this.globals
|
|
293
|
+
globals: this.globals,
|
|
294
|
+
minify: this.minify
|
|
308
295
|
};
|
|
309
296
|
return template(data);
|
|
310
297
|
}
|
|
@@ -322,19 +309,11 @@ const wrapping = (WrappedComponent, WrappeeComponent, properties) => class exten
|
|
|
322
309
|
class PluridContentGenerator {
|
|
323
310
|
constructor(data) {
|
|
324
311
|
this.data = data;
|
|
325
|
-
this.importProviders();
|
|
326
312
|
}
|
|
327
313
|
render() {
|
|
328
314
|
var _a;
|
|
329
315
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
330
|
-
|
|
331
|
-
yield this.importProviders();
|
|
332
|
-
}
|
|
333
|
-
if (!this.providers) {
|
|
334
|
-
console.log("Plurid Server Error :: Providers not loaded");
|
|
335
|
-
return "";
|
|
336
|
-
}
|
|
337
|
-
const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname, hostname: hostname} = this.data;
|
|
316
|
+
const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, routerProperties: routerProperties, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname, hostname: hostname} = this.data;
|
|
338
317
|
const RoutedApplication = () => React__default["default"].createElement(pluridReact.PluridProvider, {
|
|
339
318
|
metastate: pluridMetastate
|
|
340
319
|
}, React__default["default"].createElement(pluridReact.PluridRouterStatic, {
|
|
@@ -347,14 +326,15 @@ class PluridContentGenerator {
|
|
|
347
326
|
gateway: gateway,
|
|
348
327
|
gatewayEndpoint: gatewayEndpoint,
|
|
349
328
|
gatewayQuery: gatewayQuery,
|
|
350
|
-
hostname: hostname
|
|
329
|
+
hostname: hostname,
|
|
330
|
+
routerProperties: routerProperties
|
|
351
331
|
}));
|
|
352
332
|
let Wrap = wrapping(reactHelmetAsync.HelmetProvider, RoutedApplication, {
|
|
353
333
|
context: helmet
|
|
354
334
|
});
|
|
355
335
|
for (const service of services) {
|
|
356
336
|
const preserveProperties = (_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.providers) === null || _a === void 0 ? void 0 : _a[service.name];
|
|
357
|
-
Wrap = wrapping(
|
|
337
|
+
Wrap = wrapping(service.Provider, Wrap, Object.assign(Object.assign({}, service.properties), preserveProperties));
|
|
358
338
|
}
|
|
359
339
|
const content = server.renderToString(React__default["default"].createElement(styledComponents.StyleSheetManager, {
|
|
360
340
|
sheet: stylesheet.instance
|
|
@@ -362,26 +342,6 @@ class PluridContentGenerator {
|
|
|
362
342
|
return content;
|
|
363
343
|
}));
|
|
364
344
|
}
|
|
365
|
-
importProviders() {
|
|
366
|
-
return __awaiter(this, void 0, void 0, (function*() {
|
|
367
|
-
const providers = {};
|
|
368
|
-
for (const service of this.data.services) {
|
|
369
|
-
try {
|
|
370
|
-
const importedService = yield function(t) {
|
|
371
|
-
return Promise.resolve().then((function() {
|
|
372
|
-
return _interopNamespace(require(t));
|
|
373
|
-
}));
|
|
374
|
-
}(service.package);
|
|
375
|
-
const ImportedServiceProvider = service.provider === "default" ? importedService : importedService[service.provider];
|
|
376
|
-
providers[service.name] = ImportedServiceProvider;
|
|
377
|
-
} catch (error) {
|
|
378
|
-
console.log(`Plurid Server Error :: Service '${service.name}' from '${service.package}' could not be imported.`);
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
this.providers = providers;
|
|
383
|
-
}));
|
|
384
|
-
}
|
|
385
345
|
}
|
|
386
346
|
|
|
387
347
|
const resolveElementFromPlaneMatch = (planeMatch, elementqlEndpoint) => {
|
|
@@ -404,7 +364,7 @@ const {IsoMatcher: PluridIsoMatcher} = pluridEngine.routing;
|
|
|
404
364
|
|
|
405
365
|
class PluridServer {
|
|
406
366
|
constructor(configuration) {
|
|
407
|
-
const {routes: routes, planes: planes, preserves: preserves, helmet: helmet, styles: styles, middleware: middleware, exterior: exterior, shell: shell, services: services, options: options, template: template, usePTTP: usePTTP, pttpHandler: pttpHandler, elementqlEndpoint: elementqlEndpoint} = configuration;
|
|
367
|
+
const {routes: routes, planes: planes, preserves: preserves, helmet: helmet, styles: styles, middleware: middleware, exterior: exterior, shell: shell, routerProperties: routerProperties, services: services, options: options, template: template, usePTTP: usePTTP, pttpHandler: pttpHandler, elementqlEndpoint: elementqlEndpoint} = configuration;
|
|
408
368
|
this.routes = routes;
|
|
409
369
|
this.planes = planes || [];
|
|
410
370
|
this.preserves = preserves;
|
|
@@ -413,6 +373,7 @@ class PluridServer {
|
|
|
413
373
|
this.middleware = middleware || [];
|
|
414
374
|
this.exterior = exterior;
|
|
415
375
|
this.shell = shell;
|
|
376
|
+
this.routerProperties = routerProperties || {};
|
|
416
377
|
this.services = services || [];
|
|
417
378
|
this.options = this.handleOptions(options);
|
|
418
379
|
this.template = template;
|
|
@@ -782,11 +743,11 @@ class PluridServer {
|
|
|
782
743
|
}));
|
|
783
744
|
}
|
|
784
745
|
renderApplication(isoMatch, preserveResult, matchedPlane) {
|
|
785
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
746
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
786
747
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
787
748
|
const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
|
|
788
749
|
const mergedHtmlLanguage = ((_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _a === void 0 ? void 0 : _a.htmlLanguage) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.htmlLanguage);
|
|
789
|
-
const pluridMetastate = yield pluridReact.serverComputeMetastate(isoMatch, this.routes, globals);
|
|
750
|
+
const pluridMetastate = yield pluridReact.serverComputeMetastate(isoMatch, this.routes, globals, this.options.hostname);
|
|
790
751
|
const {content: content, styles: styles} = yield this.getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane);
|
|
791
752
|
const stringedStyles = this.styles.reduce(((accumulator, style) => accumulator + style), "");
|
|
792
753
|
const preserveStyles = ((_d = (_c = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _c === void 0 ? void 0 : _c.styles) === null || _d === void 0 ? void 0 : _d.join(" ")) || "";
|
|
@@ -817,7 +778,8 @@ class PluridServer {
|
|
|
817
778
|
content: content,
|
|
818
779
|
defaultPreloadedPluridMetastate: (_r = this.template) === null || _r === void 0 ? void 0 : _r.defaultPreloadedPluridMetastate,
|
|
819
780
|
pluridMetastate: JSON.stringify(pluridMetastate),
|
|
820
|
-
globals: globals
|
|
781
|
+
globals: globals,
|
|
782
|
+
minify: (_s = this.template) === null || _s === void 0 ? void 0 : _s.minify
|
|
821
783
|
});
|
|
822
784
|
return renderer;
|
|
823
785
|
}));
|
|
@@ -836,6 +798,7 @@ class PluridServer {
|
|
|
836
798
|
stylesheet: stylesheet,
|
|
837
799
|
exterior: this.exterior,
|
|
838
800
|
shell: this.shell,
|
|
801
|
+
routerProperties: this.routerProperties,
|
|
839
802
|
helmet: this.helmet,
|
|
840
803
|
routes: this.routes,
|
|
841
804
|
planes: this.planes,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { PluridContentGeneratorData } from "../../data/interfaces";
|
|
2
2
|
declare class PluridContentGenerator {
|
|
3
3
|
private data;
|
|
4
|
-
private providers;
|
|
5
4
|
constructor(data: PluridContentGeneratorData);
|
|
6
5
|
render(): Promise<string>;
|
|
7
|
-
private importProviders;
|
|
8
6
|
}
|
|
9
7
|
export default PluridContentGenerator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plurid/plurid-react-server",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-15",
|
|
4
4
|
"description": "React implementation of Plurid to view and explore the web in three dimensions with server-side rendering",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plurid",
|
|
@@ -77,59 +77,59 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@apollo/client": "^3.6.9",
|
|
80
|
-
"@babel/core": "^7.
|
|
80
|
+
"@babel/core": "^7.19.0",
|
|
81
81
|
"@plurid/elementql": "^0.0.0-1",
|
|
82
82
|
"@plurid/elementql-client-react": "^0.0.0-1",
|
|
83
|
-
"@plurid/plurid-data": "0.0.0-
|
|
84
|
-
"@plurid/plurid-engine": "0.0.0-
|
|
85
|
-
"@plurid/plurid-functions": "0.0.0-
|
|
83
|
+
"@plurid/plurid-data": "0.0.0-20",
|
|
84
|
+
"@plurid/plurid-engine": "0.0.0-18",
|
|
85
|
+
"@plurid/plurid-functions": "0.0.0-30",
|
|
86
86
|
"@plurid/plurid-functions-react": "0.0.0-5",
|
|
87
87
|
"@plurid/plurid-icons-react": "0.0.0-5",
|
|
88
|
-
"@plurid/plurid-pubsub": "0.0.0-
|
|
89
|
-
"@plurid/plurid-react": "0.0.0-
|
|
88
|
+
"@plurid/plurid-pubsub": "0.0.0-9",
|
|
89
|
+
"@plurid/plurid-react": "0.0.0-30",
|
|
90
90
|
"@plurid/plurid-themes": "0.0.0-2",
|
|
91
|
-
"@plurid/plurid-ui-components-react": "0.0.0-
|
|
92
|
-
"@plurid/plurid-ui-state-react": "0.0.0-
|
|
91
|
+
"@plurid/plurid-ui-components-react": "0.0.0-18",
|
|
92
|
+
"@plurid/plurid-ui-state-react": "0.0.0-7",
|
|
93
93
|
"@redux-devtools/extension": "^3.2.3",
|
|
94
|
-
"@rollup/plugin-node-resolve": "^
|
|
94
|
+
"@rollup/plugin-node-resolve": "^14.0.0",
|
|
95
95
|
"@types/body-parser": "^1.19.2",
|
|
96
96
|
"@types/compression": "^1.7.2",
|
|
97
97
|
"@types/detect-port": "^1.3.2",
|
|
98
98
|
"@types/express": "^4.17.13",
|
|
99
99
|
"@types/hammerjs": "^2.0.41",
|
|
100
100
|
"@types/html-minifier": "^4.0.2",
|
|
101
|
-
"@types/jest": "^
|
|
102
|
-
"@types/node": "^18.7.
|
|
103
|
-
"@types/react": "^18.0.
|
|
101
|
+
"@types/jest": "^29.0.0",
|
|
102
|
+
"@types/node": "^18.7.15",
|
|
103
|
+
"@types/react": "^18.0.18",
|
|
104
104
|
"@types/react-dom": "^18.0.6",
|
|
105
105
|
"@types/react-redux": "^7.1.24",
|
|
106
106
|
"@types/react-stripe-elements": "^6.0.6",
|
|
107
107
|
"@types/styled-components": "^5.1.26",
|
|
108
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
109
|
-
"@typescript-eslint/parser": "^5.
|
|
108
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
109
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
110
110
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
111
111
|
"cross-fetch": "^3.1.5",
|
|
112
|
-
"eslint": "^8.
|
|
113
|
-
"graphql": "^16.
|
|
112
|
+
"eslint": "^8.23.0",
|
|
113
|
+
"graphql": "^16.6.0",
|
|
114
114
|
"hammerjs": "^2.0.8",
|
|
115
|
-
"jest": "^
|
|
116
|
-
"jest-config": "^
|
|
115
|
+
"jest": "^29.0.2",
|
|
116
|
+
"jest-config": "^29.0.2",
|
|
117
117
|
"react": "^18.2.0",
|
|
118
118
|
"react-dom": "^18.2.0",
|
|
119
119
|
"react-helmet-async": "^1.3.0",
|
|
120
120
|
"react-redux": "^8.0.2",
|
|
121
121
|
"redux": "^4.2.0",
|
|
122
122
|
"redux-thunk": "^2.4.1",
|
|
123
|
-
"rollup": "^2.
|
|
123
|
+
"rollup": "^2.79.0",
|
|
124
124
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
125
125
|
"rollup-plugin-terser": "^7.0.2",
|
|
126
|
-
"rollup-plugin-typescript2": "^0.
|
|
126
|
+
"rollup-plugin-typescript2": "^0.33.0",
|
|
127
127
|
"styled-components": "^5.3.5",
|
|
128
128
|
"ts-jest": "^28.0.8",
|
|
129
129
|
"ts-node": "^10.9.1",
|
|
130
130
|
"tslib": "^2.4.0",
|
|
131
131
|
"ttypescript": "^1.5.13",
|
|
132
|
-
"typescript": "^4.
|
|
132
|
+
"typescript": "^4.8.2",
|
|
133
133
|
"typescript-transform-paths": "^3.3.1"
|
|
134
134
|
}
|
|
135
135
|
}
|