@joystick.js/node-canary 0.0.0-canary.372 → 0.0.0-canary.373
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/dist/app/ssr/index.js +5 -5
- package/package.json +1 -1
- package/src/app/ssr/index.js +7 -2
package/dist/app/ssr/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import u from"fs";import p from"../api/get_api_for_data_functions.js";import
|
|
1
|
+
import u from"fs";import{parseHTML as p}from"linkedom";import y from"../api/get_api_for_data_functions.js";import $ from"../../lib/get_browser_safe_request.js";import h from"../settings/load.js";import b from"./set_base_attributes_in_html.js";import w from"./set_head_tags_in_html.js";import i from"../../lib/path_exists.js";import f from"../accounts/get_browser_safe_user.js";const{readFile:a}=u.promises,r=h(),s=process.env.NODE_ENV==="development";document=p("<div></div>");const g=(e={})=>e?.base_html.replace("${css}",`<style type="text/css" js-css>${e?.css}</style>`).replace('<div id="app"></div>',`
|
|
2
2
|
<div id="app">${e?.html}</div>
|
|
3
3
|
<script>
|
|
4
4
|
window.joystick = {
|
|
@@ -13,20 +13,20 @@ import u from"fs";import p from"../api/get_api_for_data_functions.js";import y f
|
|
|
13
13
|
${s?`window.__joystick_hmr_port__ = ${parseInt(process.env.PORT,10)+1}`:""}
|
|
14
14
|
window.__joystick_layout_url__ = ${e?.render_layout_path?`"/_joystick/${e?.render_layout_path}"`:null};
|
|
15
15
|
window.__joystick_page_url__ = ${e?.render_component_path?`"/_joystick/${e?.render_component_path}"`:null};
|
|
16
|
-
window.__joystick_request__ = ${JSON.stringify(
|
|
16
|
+
window.__joystick_request__ = ${JSON.stringify($(e?.req))};
|
|
17
17
|
window.__joystick_settings__ = ${JSON.stringify({global:r?.global,public:r?.public})};
|
|
18
18
|
|
|
19
19
|
window.__joystick_should_auto_mount__ = true;
|
|
20
20
|
window.__joystick_ssr_props__ = ${JSON.stringify(e?.props)};
|
|
21
21
|
window.__joystick_url__ = ${JSON.stringify(e?.url)};
|
|
22
|
-
window.__joystick_user__ = ${JSON.stringify(
|
|
22
|
+
window.__joystick_user__ = ${JSON.stringify(f(e?.req?.context?.user))};
|
|
23
23
|
</script>
|
|
24
24
|
<script type="module" src="/_joystick/utils/process.js"></script>
|
|
25
25
|
<script type="module" src="/_joystick/index.client.js"></script>
|
|
26
26
|
${e?.render_component_path?`<script type="module" src="/_joystick/${e?.render_component_path}"></script>`:""}
|
|
27
27
|
${e?.render_layout_path?`<script type="module" src="/_joystick/${e?.render_layout_path}"></script>`:""}
|
|
28
28
|
${s?'<script type="module" src="/_joystick/hmr/client.js"></script>':""}
|
|
29
|
-
`)
|
|
29
|
+
`),j=(e={})=>e?.base_html.replace("${css}",`<style type="text/css">${e?.css}</style>`).replace("${subject}",e?.email_options?.subject).replace("${preheader}",e?.email_options?.preheader||"").replace('<div id="email"></div>',`<div id="email">${e?.html}</div>`),k=(e={})=>e?.is_email?j(e):g(e),v=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.html`)?a(`email/${e?`base_${e}`:"base"}.html`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.html`),""),N=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.css`)?a(`email/${e?`base_${e}`:"base"}.css`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.css`),""),O=(e=null,t={})=>e(t),q=async(e={})=>{const t=O(e?.component_to_render,e?.component_options),c=y(e?.req,e?.api_schema),l=[],_=await t.render_for_ssr(c,e?.req,l,{is_email:e?.is_email}),n=e?.is_email?await N(e?.email_options?.base_html_name):null,o=e?.is_email?await v(e?.email_options?.base_html_name):null,m=k({is_email:e?.is_email,attributes:e?.attributes,base_html:e?.is_email?o:e?.base_html,component_instance:t,css:e?.is_email?`
|
|
30
30
|
${n}
|
|
31
31
|
${_?.css}
|
|
32
|
-
`:_?.css,data:_?.data,email_options:e?.email_options,head:e?.head,html:_?.html,props:e?.component_options?.props,render_component_path:e?.render_component_path,render_layout_path:e?.render_layout_path,req:e?.req,translations:e?.component_options?.translations,url:e?.component_options?.url}),d=
|
|
32
|
+
`:_?.css,data:_?.data,email_options:e?.email_options,head:e?.head,html:_?.html,props:e?.component_options?.props,render_component_path:e?.render_component_path,render_layout_path:e?.render_layout_path,req:e?.req,translations:e?.component_options?.translations,url:e?.component_options?.url}),d=w(m,e?.head,e?.req);return b(d,e?.attributes)};var L=q;export{L as default};
|
package/package.json
CHANGED
package/src/app/ssr/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import { parseHTML } from 'linkedom';
|
|
2
3
|
import get_api_for_data_functions from "../api/get_api_for_data_functions.js";
|
|
3
4
|
import get_browser_safe_request from "../../lib/get_browser_safe_request.js";
|
|
4
5
|
import load_settings from '../settings/load.js';
|
|
@@ -11,8 +12,13 @@ const { readFile } = fs.promises;
|
|
|
11
12
|
const app_settings = load_settings();
|
|
12
13
|
const is_development = process.env.NODE_ENV === 'development';
|
|
13
14
|
|
|
15
|
+
// NOTE: Set a global document so we have access to a pseudo-DOM in @joystick.js/ui
|
|
16
|
+
// when server-side rendering.
|
|
17
|
+
document = parseHTML('<div></div>');
|
|
18
|
+
|
|
14
19
|
const build_html_response_for_browser = (options = {}) => {
|
|
15
20
|
return options?.base_html
|
|
21
|
+
.replace('${css}', `<style type="text/css" js-css>${options?.css}</style>`)
|
|
16
22
|
.replace(`<div id="app"></div>`, `
|
|
17
23
|
<div id="app">${options?.html}</div>
|
|
18
24
|
<script>
|
|
@@ -44,8 +50,7 @@ const build_html_response_for_browser = (options = {}) => {
|
|
|
44
50
|
${options?.render_component_path ? `<script type="module" src="/_joystick/${options?.render_component_path}"></script>` : ''}
|
|
45
51
|
${options?.render_layout_path ? `<script type="module" src="/_joystick/${options?.render_layout_path}"></script>` : ''}
|
|
46
52
|
${is_development ? `<script type="module" src="/_joystick/hmr/client.js"></script>` : ''}
|
|
47
|
-
`)
|
|
48
|
-
.replace('${css}', `<style type="text/css" js-css>${options?.css}</style>`);
|
|
53
|
+
`);
|
|
49
54
|
};
|
|
50
55
|
|
|
51
56
|
const build_html_response_for_email = (options = {}) => {
|