wapplr 1.0.68 → 1.0.70

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.
@@ -29,7 +29,7 @@ var _config = _interopRequireDefault(require("./config"));
29
29
 
30
30
  var _utils = require("../common/utils");
31
31
 
32
- var _excluded = ["disableUseDefaultMiddlewares"];
32
+ var _excluded = ["disableUseDefaultMiddlewares", "styles"];
33
33
 
34
34
  function createClient() {
35
35
  var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -41,7 +41,11 @@ function createClient() {
41
41
  var clientConfig = config.client || {};
42
42
  var _clientConfig$disable = clientConfig.disableUseDefaultMiddlewares,
43
43
  disableUseDefaultMiddlewares = _clientConfig$disable === void 0 ? false : _clientConfig$disable,
44
+ _clientConfig$styles = clientConfig.styles,
45
+ styles = _clientConfig$styles === void 0 ? {} : _clientConfig$styles,
44
46
  rest = (0, _objectWithoutProperties2["default"])(clientConfig, _excluded);
47
+ var _styles$disableClearM = styles.disableClearMainStyle,
48
+ disableClearMainStyle = _styles$disableClearM === void 0 ? false : _styles$disableClearM;
45
49
  var defaultConfig = Object.create(Object.prototype, {
46
50
  disableUseDefaultMiddlewares: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
47
51
  value: disableUseDefaultMiddlewares
@@ -85,13 +89,16 @@ function createClient() {
85
89
  }, {}, function out() {
86
90
  var globals = wapp.globals;
87
91
  var WAPP = globals.WAPP;
88
- setTimeout(function () {
89
- var elem = document.getElementById("css_" + WAPP);
90
92
 
91
- if (elem) {
92
- elem.parentNode.removeChild(elem);
93
- }
94
- }, 2000);
93
+ if (!disableClearMainStyle) {
94
+ setTimeout(function () {
95
+ var elem = document.getElementById("css_" + WAPP);
96
+
97
+ if (elem) {
98
+ elem.parentNode.removeChild(elem);
99
+ }
100
+ }, 2000);
101
+ }
95
102
  });
96
103
  }
97
104
 
@@ -188,12 +188,20 @@ function createStyleManager() {
188
188
  styleManager = _p$styleManager === void 0 ? createDefaultStyleManager(p) : _p$styleManager;
189
189
 
190
190
  function defaultHandle(req, res, next) {
191
+ var _targetObject$config2, _targetObject$config3, _targetObject$config4, _targetObject$config5, _targetObject$config6;
192
+
191
193
  var targetObject = wapp.getTargetObject ? wapp.getTargetObject() : wapp;
192
194
 
193
- if (!targetObject.config || targetObject.config && !targetObject.config.styles || targetObject.config && targetObject.config.styles && !targetObject.config.styles.disableClearStyles) {
195
+ if (!(targetObject !== null && targetObject !== void 0 && (_targetObject$config2 = targetObject.config) !== null && _targetObject$config2 !== void 0 && (_targetObject$config3 = _targetObject$config2.styles) !== null && _targetObject$config3 !== void 0 && _targetObject$config3.disableClearStyles)) {
194
196
  stylesMiddleware.styleManager.clear();
195
197
  }
196
198
 
199
+ if (targetObject !== null && targetObject !== void 0 && (_targetObject$config4 = targetObject.config) !== null && _targetObject$config4 !== void 0 && (_targetObject$config5 = _targetObject$config4.assets) !== null && _targetObject$config5 !== void 0 && (_targetObject$config6 = _targetObject$config5.cssToInlineStyle) !== null && _targetObject$config6 !== void 0 && _targetObject$config6._getCss) {
200
+ wapp.styles.add({
201
+ _getCss: targetObject.config.assets.cssToInlineStyle._getCss
202
+ });
203
+ }
204
+
197
205
  next();
198
206
  }
199
207
 
@@ -19,9 +19,13 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
19
19
 
20
20
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
21
21
 
22
- var _http = _interopRequireDefault(require("http"));
22
+ var _nodeHttp = _interopRequireDefault(require("node:http"));
23
23
 
24
- var _http2 = _interopRequireDefault(require("http2"));
24
+ var _nodeHttp2 = _interopRequireDefault(require("node:http2"));
25
+
26
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
27
+
28
+ var _nodePath = _interopRequireDefault(require("node:path"));
25
29
 
26
30
  var _common = _interopRequireDefault(require("../common"));
27
31
 
@@ -74,11 +78,13 @@ function createServer() {
74
78
 
75
79
  if (assets && assets.chunks) {
76
80
  Object.keys(assets.chunks).forEach(function (key) {
77
- assets.chunks[key].forEach(function (script) {
78
- if (script.match(".js") && chunks.indexOf(script) === -1) {
79
- chunks.push(script);
80
- }
81
- });
81
+ if (key === 'client') {
82
+ assets.chunks[key].forEach(function (script) {
83
+ if (script && script.match(".js") && chunks.indexOf(script) === -1) {
84
+ chunks.push(script);
85
+ }
86
+ });
87
+ }
82
88
  });
83
89
  }
84
90
 
@@ -87,7 +93,7 @@ function createServer() {
87
93
  if (assets) {
88
94
  Object.keys(assets).forEach(function (key) {
89
95
  if (key !== "chunks" && scripts.indexOf(assets[key]) === -1) {
90
- if (assets[key].match(".js")) {
96
+ if (assets[key] && assets[key].match(".js")) {
91
97
  scripts.push(assets[key]);
92
98
  }
93
99
  }
@@ -96,7 +102,101 @@ function createServer() {
96
102
 
97
103
  return scripts;
98
104
  }
99
- })
105
+ }),
106
+ cssToInlineStyle: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
107
+ enumerable: false,
108
+ value: {
109
+ loadCssToStyle: function loadCssToStyle(a) {
110
+ if (Array.isArray(a) && a.length) {
111
+ var getThemeCss = function getThemeCss() {
112
+ var themeCss = [];
113
+
114
+ if (assets && assets.chunks) {
115
+ Object.keys(assets.chunks).forEach(function (key) {
116
+ if (key === 'client') {
117
+ var files = assets.chunks[key].sort();
118
+ files.forEach(function (style) {
119
+ if (style && style.match(".css") && a.indexOf(style) > -1 && !(themeCss.indexOf(style) > -1)) {
120
+ themeCss.push(style);
121
+ }
122
+ });
123
+ }
124
+ });
125
+ }
126
+
127
+ return themeCss;
128
+ };
129
+
130
+ var intersection = a.filter(function (x) {
131
+ return assets.cssToInlineStyle.css.includes(x);
132
+ });
133
+
134
+ if (intersection.length === a.length) {
135
+ return;
136
+ }
137
+
138
+ var themeCss = getThemeCss();
139
+ var text = "";
140
+ var css = [];
141
+ themeCss.forEach(function (cssPath) {
142
+ if (_nodeFs["default"].existsSync(_nodePath["default"].join(publicPath, cssPath))) {
143
+ var cssContent = _nodeFs["default"].readFileSync(_nodePath["default"].join(publicPath, cssPath));
144
+
145
+ if (cssContent) {
146
+ text = [text, cssContent].filter(function (t) {
147
+ return t;
148
+ }).join(" ");
149
+ css.push(cssPath);
150
+ }
151
+ }
152
+ });
153
+ assets.cssToInlineStyle.text = text;
154
+ assets.cssToInlineStyle.css = css;
155
+ }
156
+ },
157
+ _getCss: function _getCss() {
158
+ return assets.cssToInlineStyle.cssText || "";
159
+ },
160
+ text: '',
161
+ css: []
162
+ }
163
+ }),
164
+ getCsStyles: {
165
+ value: function value() {
166
+ var chunks = [];
167
+
168
+ if (assets && assets.chunks) {
169
+ Object.keys(assets.chunks).forEach(function (key) {
170
+ if (key === 'client') {
171
+ var files = assets.chunks[key].sort();
172
+ files.forEach(function (style) {
173
+ var _assets$cssToInlineSt;
174
+
175
+ if (style && style.match(".css") && chunks.indexOf(style) === -1 && !(((_assets$cssToInlineSt = assets.cssToInlineStyle.css) === null || _assets$cssToInlineSt === void 0 ? void 0 : _assets$cssToInlineSt.indexOf(style)) > -1)) {
176
+ chunks.push(style);
177
+ }
178
+ });
179
+ }
180
+ });
181
+ }
182
+
183
+ var styles = [].concat(chunks);
184
+
185
+ if (assets) {
186
+ Object.keys(assets).forEach(function (key) {
187
+ if (key !== "chunks" && styles.indexOf(assets[key]) === -1) {
188
+ var _assets$cssToInlineSt2;
189
+
190
+ if (assets[key] && assets[key].match(".css") && !(((_assets$cssToInlineSt2 = assets.cssToInlineStyle.css) === null || _assets$cssToInlineSt2 === void 0 ? void 0 : _assets$cssToInlineSt2.indexOf(assets[key])) > -1)) {
191
+ styles.push(assets[key]);
192
+ }
193
+ }
194
+ });
195
+ }
196
+
197
+ return styles;
198
+ }
199
+ }
100
200
  });
101
201
  var defaultCredentials = Object.create(Object.prototype, {
102
202
  key: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
@@ -132,7 +232,7 @@ function createServer() {
132
232
  (0, _utils.mergeProperties)(defaultConfig, rest);
133
233
  var defaultServers = Object.create(Object.prototype, {
134
234
  "80": (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
135
- value: _http["default"].createServer(app)
235
+ value: _nodeHttp["default"].createServer(app)
136
236
  })
137
237
  });
138
238
 
@@ -160,7 +260,7 @@ function createServer() {
160
260
 
161
261
  if (port) {
162
262
  if (!httpServer) {
163
- httpServer = _http["default"].createServer(app);
263
+ httpServer = _nodeHttp["default"].createServer(app);
164
264
  wapplrServer.servers[port] = httpServer;
165
265
  }
166
266
 
@@ -197,7 +297,7 @@ function createServer() {
197
297
 
198
298
  if (key && cert && portSSL) {
199
299
  if (!httpsServer) {
200
- httpsServer = _http2["default"].createSecureServer({
300
+ httpsServer = _nodeHttp2["default"].createSecureServer({
201
301
  key: key,
202
302
  cert: cert,
203
303
  allowHTTP1: true
@@ -87,22 +87,26 @@ function html(_ref) {
87
87
  });
88
88
  }
89
89
 
90
+ wapp.styles.use(appStyle);
91
+ var styles = wapp.styles.getCssText();
92
+ var styleText = styles.map(function (style) {
93
+ return "<style id=\"".concat(style.id, "\">").concat(style.cssText, "</style>");
94
+ }).join("");
95
+ var csStyles = assets.getCsStyles();
96
+ var cssText = csStyles.map(function (css) {
97
+ return "<link rel=\"stylesheet\" as=\"style\" type=\"text/css\" href=\"".concat(css, "\" />");
98
+ }).join("");
99
+ var stateText = "<script>window[\"".concat(appStateName, "\"] = ").concat(JSON.stringify(state || {}), "</script>");
90
100
  var scripts = assets.getScripts();
91
101
  var scriptText = scripts.map(function (script) {
92
102
  if (script) {
93
- return "<script key=\"".concat(script, "\" src=\"").concat(script, "\" ></script>");
103
+ return "<script src=\"".concat(script, "\" ></script>");
94
104
  }
95
105
 
96
106
  return "";
97
107
  }).join(" ");
98
- var stateText = "<script>window[\"".concat(appStateName, "\"] = ").concat(JSON.stringify(state || {}), "</script>");
99
- wapp.styles.use(appStyle);
100
- var styles = wapp.styles.getCssText();
101
- var styleText = styles.map(function (style) {
102
- return "<style id=\"".concat(style.id, "\">").concat(style.cssText, "</style>");
103
- }).join("");
104
108
  var headComponent = wapp.contents.getComponent("head");
105
109
  var headText = headComponent ? headComponent.render(wapp) : "";
106
110
  var htmlLang = lang.split("_")[0];
107
- return "<!DOCTYPE html>\n<html lang=\"".concat(htmlLang, "\">\n <head>\n <meta charset=\"utf-8\">\n <title>").concat(title, "</title>\n <meta name=\"description\" content=\"").concat(description, "\">\n <meta name=\"author\" content=\"").concat(author, "\">\n <meta name=\"viewport\" content=\"").concat(viewport, "\">\n <meta name=\"theme-color\" content=\"").concat(themeColor, "\">\n <link rel=\"manifest\" href=\"").concat(manifest, "\" />\n <link rel=\"icon\" href=").concat(icon, ">\n <link rel=\"apple-touch-icon\" href=\"").concat(appleTouchIcon || icon, "\">\n ").concat(styleText, "\n ").concat(headText, "\n </head>\n <body>\n <div class=\"").concat(appStyle.app, "\" id=\"").concat(containerElementId, "\">").concat(render, "</div>\n ").concat(stateText, "\n ").concat(scriptText, "\n </body>\n</html>\n");
111
+ return "<!DOCTYPE html>\n<html lang=\"".concat(htmlLang, "\">\n <head>\n <meta charset=\"utf-8\">\n <title>").concat(title, "</title>\n <meta name=\"description\" content=\"").concat(description, "\">\n <meta name=\"author\" content=\"").concat(author, "\">\n <meta name=\"viewport\" content=\"").concat(viewport, "\">\n <meta name=\"theme-color\" content=\"").concat(themeColor, "\">\n <link rel=\"manifest\" href=\"").concat(manifest, "\" />\n <link rel=\"icon\" href=").concat(icon, ">\n <link rel=\"apple-touch-icon\" href=\"").concat(appleTouchIcon || icon, "\">\n ").concat(styleText, "\n ").concat(cssText, "\n ").concat(headText, "\n </head>\n <body>\n <div class=\"").concat(appStyle.app, "\" id=\"").concat(containerElementId, "\">").concat(render, "</div>\n ").concat(stateText, "\n ").concat(scriptText, "\n </body>\n</html>\n");
108
112
  }
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "files": [
23
23
  "dist/*"
24
24
  ],
25
- "version": "1.0.68",
25
+ "version": "1.0.70",
26
26
  "main": "dist/server",
27
27
  "browser": "dist/client",
28
28
  "repository": {