@soleil-se/app-util 1.1.0 → 1.1.2

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/index.js CHANGED
@@ -39,7 +39,15 @@ export function renderTemplate(template, values) {
39
39
  * Get HTML for rendering a Vue application.
40
40
  * @param {String} name Name of the app, has to match the name of the Vue application.
41
41
  * @param {Object} data Data that will be available in `$options`.
42
- * @param {String} [noScript=''] HTML that will be printed when JavaScript is not available.
42
+ * @param {Object} settings Settings object.
43
+ * @param {String} [settings.noScript=''] HTML that will be rendered when JavaScript
44
+ * is not available.
45
+ * @param {String} [settings.selector=`[data-vue-portlet="${portletId}"]`] Query selector for
46
+ * where the app should be mounted.
47
+ * @param {Boolean} [settings.async=true] If the app script should be loaded asynchronously.
48
+ * [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/)
49
+ * @param {Boolean} [settings.defer=false] If the app script should be loaded after DOM is ready.
50
+ * [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/)
43
51
  * @returns {String} HTML for rendering a Vue application.
44
52
  */
45
53
  export function renderVue(name, data, ref) {
@@ -51,8 +59,11 @@ export function renderVue(name, data, ref) {
51
59
 
52
60
  var options = Object.assign({}, {webapp: app, isOffline: isOffline}, data);
53
61
  var vueUri = getResourceUri('vue/index.js');
54
- var html = "\n<!-- Generated by WebappUtil.renderVue() -->\n<div data-vue-portlet=\"" + portletId + "\">" + noScript + "</div>\n<script>\n function renderVue" + portletId + "() {\n vueApps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n } \n</script>\n<script src=\"" + vueUri + "\" " + (async ? 'async' : '') + " " + (defer ? 'defer' : '') + " onload=\"renderVue" + portletId + "();\"></script>\n";
55
- return html;
62
+
63
+ if (isOffline) {
64
+ return ("\n<!-- Generated by WebappUtil.renderVue() -->\n<div data-vue-portlet=\"" + portletId + "\">" + noScript + "</div>\n<script src=\"" + vueUri + "\"></script>\n<script> \n vueApps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n</script>\n");
65
+ }
66
+ return ("\n<!-- Generated by WebappUtil.renderVue() -->\n<div data-vue-portlet=\"" + portletId + "\">" + noScript + "</div>\n<script>\n function renderVue" + portletId + "() {\n vueApps['" + name + "'].render('" + name + "', '" + selector + "', " + (JSON.stringify(options)) + ");\n } \n</script>\n<script src=\"" + vueUri + "\" " + (async && !defer ? 'async' : '') + " " + (defer ? 'defer' : '') + " onload=\"renderVue" + portletId + "();\"></script>\n");
56
67
  }
57
68
 
58
69
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/app-util",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Soleil AB",
6
6
  "license": "UNLICENSED",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable-next-line import/no-unresolved */
1
2
  import Vue from 'vue';
2
3
 
3
4
  window.vueApps = window.vueApps || {};
@@ -15,7 +16,12 @@ var offlineModeMixin = {
15
16
  }
16
17
  },
17
18
  };
18
-
19
+ /**
20
+ * Render a Vue application
21
+ * @param {String} name Name of the application, has to match both on server and client.
22
+ * @param {String} selector Selector for element where the app should be mounted.
23
+ * @param {Object} [options={}] Options for `$options`.
24
+ */
19
25
  export default function render(name, selector, options) {
20
26
  if ( options === void 0 ) options = {};
21
27
 
package/src/index.js CHANGED
@@ -56,7 +56,18 @@ export function renderVue(name, data, {
56
56
  } = {}) {
57
57
  const options = { webapp: app, isOffline, ...data };
58
58
  const vueUri = getResourceUri('vue/index.js');
59
- const html = `
59
+
60
+ if (isOffline) {
61
+ return `
62
+ <!-- Generated by WebappUtil.renderVue() -->
63
+ <div data-vue-portlet="${portletId}">${noScript}</div>
64
+ <script src="${vueUri}"></script>
65
+ <script>
66
+ vueApps['${name}'].render('${name}', '${selector}', ${JSON.stringify(options)});
67
+ </script>
68
+ `;
69
+ }
70
+ return `
60
71
  <!-- Generated by WebappUtil.renderVue() -->
61
72
  <div data-vue-portlet="${portletId}">${noScript}</div>
62
73
  <script>
@@ -64,9 +75,8 @@ export function renderVue(name, data, {
64
75
  vueApps['${name}'].render('${name}', '${selector}', ${JSON.stringify(options)});
65
76
  }
66
77
  </script>
67
- <script src="${vueUri}" ${async ? 'async' : ''} ${defer ? 'defer' : ''} onload="renderVue${portletId}();"></script>
78
+ <script src="${vueUri}" ${async && !defer ? 'async' : ''} ${defer ? 'defer' : ''} onload="renderVue${portletId}();"></script>
68
79
  `;
69
- return html;
70
80
  }
71
81
 
72
82
  /**