@joystick.js/node-canary 0.0.0-canary.381 → 0.0.0-canary.383

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.
@@ -1 +1 @@
1
- var _=null,c=0,l=(t={},e=null)=>{let o=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(t.query).toString()}`);_&&(clearInterval(_),_=null);let i={client:o,send:(n={})=>(t.queryParams&&(n={...n,...t.queryParams}),o.send(JSON.stringify(n)))};return o.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,e&&e(i)}),o.addEventListener("message",n=>{console.log("FROM SERVER",{event:n,options:t}),n?.data&&t.onMessage&&t.onMessage(JSON.parse(n.data),i)}),o.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),o=null,t.autoReconnect&&!_&&(_=setInterval(()=>{o=null,c<12?(l(t,e),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(_))},5e3))}),i},u=async()=>{let t=await d();window.joystick.mount(t,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},d=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,p=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,y=async()=>{let t=await p(),e=await d();window.joystick.mount(t,Object.assign({page:e},window.__joystick_ssr_props__),document.getElementById("app"))},w=t=>{let e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(e,t)},g=(t={})=>{let e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src","/_joystick/index.client.js"),t.parentNode.replaceChild(e,t)},j=l({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(t={},e={})=>{if(console.log("WEBSOCKET MESSAGE",{message:t,websocket_client_connection:e}),t&&t.type&&t.type==="BUILD_ERROR")return location.reload();window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let i=Object.assign({},{scrollTop:window.scrollY}),n=t&&t.type&&t.type==="FILE_CHANGE",r=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),a=document.body.querySelector('script[src="/_joystick/index.client.js"]');t?.index_html_changed&&location.reload(),t?.i18n&&(window.__joystick_i18n__=t?.i18n),t?.settings&&(window.__joystick_settings__=t?.settings,window.joystick.settings=t?.settings),a&&t?.index_client_changed&&g(a),s&&t?.index_css_changed&&w(s),n&&r&&y(e),n&&!r&&u(e),window.scrollTo(0,i.scrollTop),e.send&&e.send({type:"HMR_UPDATE_COMPLETE"})}}),m=j;export{m as default};
1
+ var i=null,c=0,l=(t={},e=null)=>{let o=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(t.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:o,send:(n={})=>(t.queryParams&&(n={...n,...t.queryParams}),o.send(JSON.stringify(n)))};return o.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,e&&e(_)}),o.addEventListener("message",n=>{n?.data&&t.onMessage&&t.onMessage(JSON.parse(n.data),_)}),o.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),o=null,t.autoReconnect&&!i&&(i=setInterval(()=>{o=null,c<12?(l(t,e),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},u=async()=>{let t=await d();window.joystick.mount(t,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},d=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,p=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,y=async()=>{let t=await p(),e=await d();window.joystick.mount(t,Object.assign({page:e},window.__joystick_ssr_props__),document.getElementById("app"))},w=t=>{let e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(e,t)},g=(t={})=>{let e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src","/_joystick/index.client.js"),t.parentNode.replaceChild(e,t)},m=l({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(t={},e={})=>{if(t&&t.type&&t.type==="BUILD_ERROR")return location.reload();window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let _=Object.assign({},{scrollTop:window.scrollY}),n=t&&t.type&&t.type==="FILE_CHANGE",r=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),a=document.body.querySelector('script[src="/_joystick/index.client.js"]');t?.index_html_changed&&location.reload(),t?.i18n&&(window.__joystick_i18n__=t?.i18n),t?.settings&&(window.__joystick_settings__=t?.settings,window.joystick.settings=t?.settings),a&&t?.index_client_changed&&g(a),s&&t?.index_css_changed&&w(s),n&&r&&y(e),n&&!r&&u(e),window.scrollTo(0,_.scrollTop),e.send&&e.send({type:"HMR_UPDATE_COMPLETE"})}}),j=m;export{j as default};
@@ -1,32 +1,32 @@
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:g}=p("<div></div>"),j=(e={})=>e?.base_html.replace("${css}",`<style type="text/css" js-css>${e?.css}</style>`).replace('<div id="app"></div>',`
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 f from"./set_head_tags_in_html.js";import i from"../../lib/path_exists.js";import w from"../accounts/get_browser_safe_user.js";const{readFile:a}=u.promises,_=h(),s=process.env.NODE_ENV==="development",{document:g}=p("<div></div>"),j=(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 = {
5
5
  settings: {
6
- global: ${JSON.stringify(r?.global)},
7
- public: ${JSON.stringify(r?.public)},
6
+ global: ${JSON.stringify(_?.global)},
7
+ public: ${JSON.stringify(_?.public)},
8
8
  },
9
9
  };
10
10
 
11
- window.__joystick_data__ = ${JSON.stringify(e?.data)};
11
+ window.__joystick_data__ = ${Buffer.from(JSON.stringify(e?.data)).toString("base64")};
12
12
  window.__joystick_i18n__ = ${JSON.stringify(e?.translations)};
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
16
  window.__joystick_request__ = ${JSON.stringify($(e?.req))};
17
- window.__joystick_settings__ = ${JSON.stringify({global:r?.global,public:r?.public})};
17
+ window.__joystick_settings__ = ${JSON.stringify({global:_?.global,public:_?.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(f(e?.req?.context?.user))};
22
+ window.__joystick_user__ = ${JSON.stringify(w(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
- `),k=(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>`),v=(e={})=>e?.is_email?k(e):j(e),N=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`),""),O=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`),""),q=(e=null,t={})=>e(t),J=async(e={})=>{const t=q(e?.component_to_render,e?.component_options),c=y(e?.req,e?.api_schema),l=[],_=await t.render_for_ssr(c,e?.req,l,{linkedom_document:g,is_email:e?.is_email}),n=e?.is_email?await O(e?.email_options?.base_html_name):null,o=e?.is_email?await N(e?.email_options?.base_html_name):null,m=v({is_email:e?.is_email,attributes:e?.attributes,base_html:e?.is_email?o:e?.base_html,component_instance:t,css:e?.is_email?`
29
+ `),k=(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>`),v=(e={})=>e?.is_email?k(e):j(e),N=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`),""),O=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`),""),S=(e=null,t={})=>e(t),q=async(e={})=>{const t=S(e?.component_to_render,e?.component_options),c=y(e?.req,e?.api_schema),l=[],r=await t.render_for_ssr(c,e?.req,l,{linkedom_document:g,is_email:e?.is_email}),n=e?.is_email?await O(e?.email_options?.base_html_name):null,o=e?.is_email?await N(e?.email_options?.base_html_name):null,m=v({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
- ${_?.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=w(m,e?.head,e?.req);return b(d,e?.attributes)};var M=J;export{M as default};
31
+ ${r?.css}
32
+ `:r?.css,data:r?.data,email_options:e?.email_options,head:e?.head,html:r?.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=f(m,e?.head,e?.req);return b(d,e?.attributes)};var L=q;export{L as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.381",
4
+ "version": "0.0.0-canary.383",
5
5
  "description": "The Node.js framework for Joystick.",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {
@@ -29,7 +29,6 @@ const websocket_client = (options = {}, on_connect = null) => {
29
29
  });
30
30
 
31
31
  client.addEventListener("message", (event) => {
32
- console.log('FROM SERVER', {event, options});
33
32
  if (event?.data && options.onMessage) {
34
33
  options.onMessage(JSON.parse(event.data), connection);
35
34
  }
@@ -137,7 +136,6 @@ const hmr_client = (() =>
137
136
  page_component_path: window.__joystick_page_url__?.replace('/_joystick/', ''),
138
137
  },
139
138
  onMessage: async (message = {}, websocket_client_connection = {}) => {
140
- console.log('WEBSOCKET MESSAGE', { message, websocket_client_connection });
141
139
  const is_build_error = message && message.type && message.type === "BUILD_ERROR";
142
140
 
143
141
  if (is_build_error) {
@@ -29,7 +29,7 @@ const build_html_response_for_browser = (options = {}) => {
29
29
  },
30
30
  };
31
31
 
32
- window.__joystick_data__ = ${JSON.stringify(options?.data)};
32
+ window.__joystick_data__ = ${Buffer.from(JSON.stringify(options?.data)).toString('base64')};
33
33
  window.__joystick_i18n__ = ${JSON.stringify(options?.translations)};
34
34
  ${is_development ? `window.__joystick_hmr_port__ = ${parseInt(process.env.PORT, 10) + 1}` : ''}
35
35
  window.__joystick_layout_url__ = ${options?.render_layout_path ? `"/_joystick/${options?.render_layout_path}"` : null};