wapplr 1.0.75 → 1.0.76

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,51 +1,35 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = createClient;
9
-
10
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
9
  var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
13
-
14
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
11
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
-
18
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
19
-
20
13
  var _common = _interopRequireDefault(require("../common"));
21
-
22
14
  var _app = _interopRequireDefault(require("./app"));
23
-
24
15
  var _history = _interopRequireDefault(require("./history"));
25
-
26
16
  var _middlewares = _interopRequireDefault(require("./middlewares"));
27
-
28
17
  var _config = _interopRequireDefault(require("./config"));
29
-
30
18
  var _utils = require("../common/utils");
31
-
32
19
  var _excluded = ["disableUseDefaultMiddlewares", "styles"];
33
-
34
20
  function createClient() {
35
21
  var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
36
22
  var wapp = p.wapp || (0, _common["default"])(p);
37
-
38
23
  var _createConfig = (0, _config["default"])(p),
39
- config = _createConfig.config;
40
-
24
+ config = _createConfig.config;
41
25
  var clientConfig = config.client || {};
42
26
  var _clientConfig$disable = clientConfig.disableUseDefaultMiddlewares,
43
- disableUseDefaultMiddlewares = _clientConfig$disable === void 0 ? false : _clientConfig$disable,
44
- _clientConfig$styles = clientConfig.styles,
45
- styles = _clientConfig$styles === void 0 ? {} : _clientConfig$styles,
46
- rest = (0, _objectWithoutProperties2["default"])(clientConfig, _excluded);
27
+ disableUseDefaultMiddlewares = _clientConfig$disable === void 0 ? false : _clientConfig$disable,
28
+ _clientConfig$styles = clientConfig.styles,
29
+ styles = _clientConfig$styles === void 0 ? {} : _clientConfig$styles,
30
+ rest = (0, _objectWithoutProperties2["default"])(clientConfig, _excluded);
47
31
  var _styles$disableClearM = styles.disableClearMainStyle,
48
- disableClearMainStyle = _styles$disableClearM === void 0 ? false : _styles$disableClearM;
32
+ disableClearMainStyle = _styles$disableClearM === void 0 ? false : _styles$disableClearM;
49
33
  var defaultConfig = Object.create(Object.prototype, {
50
34
  disableUseDefaultMiddlewares: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
51
35
  value: disableUseDefaultMiddlewares
@@ -59,13 +43,12 @@ function createClient() {
59
43
  var history = (0, _history["default"])({
60
44
  wapp: wapp
61
45
  });
62
-
63
46
  function defaultListen() {
64
47
  wapplrClient.close();
65
48
  wapplrClient.history.listen(function (_ref) {
66
49
  var action = _ref.action,
67
- location = _ref.location,
68
- state = _ref.state;
50
+ location = _ref.location,
51
+ state = _ref.state;
69
52
  wapplrClient.app({
70
53
  history: {
71
54
  action: action,
@@ -89,11 +72,9 @@ function createClient() {
89
72
  }, {}, function out() {
90
73
  var globals = wapp.globals;
91
74
  var WAPP = globals.WAPP;
92
-
93
75
  if (!disableClearMainStyle) {
94
76
  setTimeout(function () {
95
77
  var elem = document.getElementById("css_" + WAPP);
96
-
97
78
  if (elem) {
98
79
  elem.parentNode.removeChild(elem);
99
80
  }
@@ -101,11 +82,9 @@ function createClient() {
101
82
  }
102
83
  });
103
84
  }
104
-
105
85
  function defaultClose() {
106
86
  wapplrClient.history.close();
107
87
  }
108
-
109
88
  var defaultMiddlewares = (0, _middlewares["default"])((0, _objectSpread2["default"])({
110
89
  wapp: wapp
111
90
  }, p));
@@ -142,119 +121,94 @@ function createClient() {
142
121
  var _defaultMiddlewaresWrapper = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee3(req, res, out) {
143
122
  var next, middlewares, index;
144
123
  return (0, _regeneratorRuntime2["default"])().wrap(function _callee3$(_context3) {
145
- while (1) {
146
- switch (_context3.prev = _context3.next) {
147
- case 0:
148
- if (wapplrClient.config.disableUseDefaultMiddlewares) {
149
- _context3.next = 7;
150
- break;
151
- }
152
-
153
- next = /*#__PURE__*/function () {
154
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(err) {
155
- var func, defaultArgs, args;
156
- return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
157
- while (1) {
158
- switch (_context2.prev = _context2.next) {
159
- case 0:
160
- if (!middlewares[index]) {
161
- _context2.next = 19;
162
- break;
163
- }
164
-
165
- func = middlewares[index];
166
- index = index + 1;
167
- defaultArgs = [req, res, err ? /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
168
- return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
169
- while (1) {
170
- switch (_context.prev = _context.next) {
171
- case 0:
172
- _context.next = 2;
173
- return next(err);
174
-
175
- case 2:
176
- case "end":
177
- return _context.stop();
178
- }
179
- }
180
- }, _callee);
181
- })) : next];
182
- args = func.length === 4 && err ? [err].concat(defaultArgs) : defaultArgs;
183
- _context2.prev = 5;
184
- _context2.next = 8;
185
- return func.apply(void 0, (0, _toConsumableArray2["default"])(args));
186
-
187
- case 8:
188
- return _context2.abrupt("return", _context2.sent);
189
-
190
- case 11:
191
- _context2.prev = 11;
192
- _context2.t0 = _context2["catch"](5);
193
- res.wappResponse.status(500, _context2.t0);
194
- _context2.next = 16;
195
- return next(_context2.t0);
196
-
197
- case 16:
198
- return _context2.abrupt("return", _context2.sent);
199
-
200
- case 17:
201
- _context2.next = 22;
202
- break;
203
-
204
- case 19:
205
- if (!(typeof out === "function")) {
206
- _context2.next = 22;
207
- break;
124
+ while (1) switch (_context3.prev = _context3.next) {
125
+ case 0:
126
+ if (wapplrClient.config.disableUseDefaultMiddlewares) {
127
+ _context3.next = 7;
128
+ break;
129
+ }
130
+ next = /*#__PURE__*/function () {
131
+ var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2(err) {
132
+ var func, defaultArgs, args;
133
+ return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
134
+ while (1) switch (_context2.prev = _context2.next) {
135
+ case 0:
136
+ if (!middlewares[index]) {
137
+ _context2.next = 19;
138
+ break;
139
+ }
140
+ func = middlewares[index];
141
+ index = index + 1;
142
+ defaultArgs = [req, res, err ? /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
143
+ return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
144
+ while (1) switch (_context.prev = _context.next) {
145
+ case 0:
146
+ _context.next = 2;
147
+ return next(err);
148
+ case 2:
149
+ case "end":
150
+ return _context.stop();
208
151
  }
209
-
210
- index = 0;
211
- return _context2.abrupt("return", out(err));
212
-
213
- case 22:
214
- return _context2.abrupt("return", null);
215
-
216
- case 23:
217
- case "end":
218
- return _context2.stop();
152
+ }, _callee);
153
+ })) : next];
154
+ args = func.length === 4 && err ? [err].concat(defaultArgs) : defaultArgs;
155
+ _context2.prev = 5;
156
+ _context2.next = 8;
157
+ return func.apply(void 0, (0, _toConsumableArray2["default"])(args));
158
+ case 8:
159
+ return _context2.abrupt("return", _context2.sent);
160
+ case 11:
161
+ _context2.prev = 11;
162
+ _context2.t0 = _context2["catch"](5);
163
+ res.wappResponse.status(500, _context2.t0);
164
+ _context2.next = 16;
165
+ return next(_context2.t0);
166
+ case 16:
167
+ return _context2.abrupt("return", _context2.sent);
168
+ case 17:
169
+ _context2.next = 22;
170
+ break;
171
+ case 19:
172
+ if (!(typeof out === "function")) {
173
+ _context2.next = 22;
174
+ break;
219
175
  }
220
- }
221
- }, _callee2, null, [[5, 11]]);
222
- }));
223
-
224
- return function next(_x4) {
225
- return _ref2.apply(this, arguments);
226
- };
227
- }();
228
-
229
- middlewares = Object.keys(wapplrClient.middlewares).map(function (key) {
230
- return wapplrClient.middlewares[key];
231
- });
232
- index = 0;
233
- _context3.next = 6;
234
- return next();
235
-
236
- case 6:
237
- return _context3.abrupt("return", _context3.sent);
238
-
239
- case 7:
240
- _context3.next = 9;
241
- return out();
242
-
243
- case 9:
244
- return _context3.abrupt("return", _context3.sent);
245
-
246
- case 10:
247
- case "end":
248
- return _context3.stop();
249
- }
176
+ index = 0;
177
+ return _context2.abrupt("return", out(err));
178
+ case 22:
179
+ return _context2.abrupt("return", null);
180
+ case 23:
181
+ case "end":
182
+ return _context2.stop();
183
+ }
184
+ }, _callee2, null, [[5, 11]]);
185
+ }));
186
+ return function next(_x4) {
187
+ return _ref2.apply(this, arguments);
188
+ };
189
+ }();
190
+ middlewares = Object.keys(wapplrClient.middlewares).map(function (key) {
191
+ return wapplrClient.middlewares[key];
192
+ });
193
+ index = 0;
194
+ _context3.next = 6;
195
+ return next();
196
+ case 6:
197
+ return _context3.abrupt("return", _context3.sent);
198
+ case 7:
199
+ _context3.next = 9;
200
+ return out();
201
+ case 9:
202
+ return _context3.abrupt("return", _context3.sent);
203
+ case 10:
204
+ case "end":
205
+ return _context3.stop();
250
206
  }
251
207
  }, _callee3);
252
208
  }));
253
-
254
209
  function defaultMiddlewaresWrapper(_x, _x2, _x3) {
255
210
  return _defaultMiddlewaresWrapper.apply(this, arguments);
256
211
  }
257
-
258
212
  return defaultMiddlewaresWrapper;
259
213
  }());
260
214
  return wapp;
@@ -1,38 +1,30 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = createHistory;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _utils = require("../common/utils");
13
-
14
10
  function createPath(_ref) {
15
11
  var _ref$pathname = _ref.pathname,
16
- pathname = _ref$pathname === void 0 ? "/" : _ref$pathname,
17
- _ref$search = _ref.search,
18
- search = _ref$search === void 0 ? "" : _ref$search,
19
- _ref$hash = _ref.hash,
20
- hash = _ref$hash === void 0 ? "" : _ref$hash;
12
+ pathname = _ref$pathname === void 0 ? "/" : _ref$pathname,
13
+ _ref$search = _ref.search,
14
+ search = _ref$search === void 0 ? "" : _ref$search,
15
+ _ref$hash = _ref.hash,
16
+ hash = _ref$hash === void 0 ? "" : _ref$hash;
21
17
  return pathname + search + hash;
22
18
  }
23
-
24
19
  function createHref(to) {
25
20
  return typeof to === "string" ? to : createPath(to);
26
21
  }
27
-
28
22
  function createKey() {
29
23
  return Math.random().toString(36).substr(2, 8);
30
24
  }
31
-
32
25
  function createHistoryManager() {
33
26
  var globalHistory = window.history;
34
27
  var li = 0;
35
-
36
28
  function defaultAddListener(handle) {
37
29
  if (typeof handle == "function") {
38
30
  var handleName = li.toString();
@@ -42,26 +34,22 @@ function createHistoryManager() {
42
34
  delete history.listeners[handleName];
43
35
  };
44
36
  }
45
-
46
37
  return function removeListener() {};
47
38
  }
48
-
49
39
  function defaultRunListeners(args) {
50
40
  var listeners = history.listeners;
51
41
  Object.keys(listeners).forEach(function (key) {
52
42
  var fn = listeners[key];
53
-
54
43
  if (typeof fn == "function") {
55
44
  fn(args);
56
45
  }
57
46
  });
58
47
  }
59
-
60
48
  function defaultHandlePop() {
61
49
  var _window$location = window.location,
62
- pathname = _window$location.pathname,
63
- search = _window$location.search,
64
- hash = _window$location.hash;
50
+ pathname = _window$location.pathname,
51
+ search = _window$location.search,
52
+ hash = _window$location.hash;
65
53
  var state = globalHistory.state || {};
66
54
  var newLocation = {
67
55
  pathname: pathname,
@@ -75,52 +63,40 @@ function createHistoryManager() {
75
63
  state: state
76
64
  });
77
65
  }
78
-
79
66
  function defaultInit() {
80
67
  if (!history.initialized) {
81
68
  window.addEventListener("popstate", history.handlePop);
82
69
  history.initialized = true;
83
70
  }
84
-
85
71
  return history;
86
72
  }
87
-
88
73
  function defaultClose() {
89
74
  if (history.initialized) {
90
75
  window.removeEventListener("popstate", history.handlePop);
91
76
  history.initialized = false;
92
77
  }
93
-
94
78
  history.listeners = {};
95
79
  return history;
96
80
  }
97
-
98
81
  function defaultParsePath(path) {
99
82
  var partialPath = {};
100
-
101
83
  if (path) {
102
84
  var hashIndex = path.indexOf("#");
103
-
104
85
  if (hashIndex >= 0) {
105
86
  partialPath.hash = path.substr(hashIndex);
106
87
  path = path.substr(0, hashIndex);
107
88
  }
108
-
109
89
  var searchIndex = path.indexOf("?");
110
-
111
90
  if (searchIndex >= 0) {
112
91
  partialPath.search = path.substr(searchIndex);
113
92
  path = path.substr(0, searchIndex);
114
93
  }
115
-
116
94
  if (path) {
117
95
  partialPath.pathname = path;
118
96
  }
119
97
  }
120
-
121
98
  return partialPath;
122
99
  }
123
-
124
100
  function defaultPush(to, inputState) {
125
101
  var pathname = window.location.pathname;
126
102
  var newLocation = (0, _objectSpread2["default"])({
@@ -138,21 +114,17 @@ function createHistoryManager() {
138
114
  state: state
139
115
  });
140
116
  }
141
-
142
117
  function defaultGo(delta) {
143
118
  globalHistory.go(delta);
144
119
  }
145
-
146
120
  function defaultListen() {
147
121
  var fn = (arguments.length <= 0 ? undefined : arguments[0]) ? arguments.length <= 0 ? undefined : arguments[0] : null;
148
122
  history.init();
149
123
  return history.addListener(fn);
150
124
  }
151
-
152
125
  function defaultGetState() {
153
126
  return history.globalHistory.state || {};
154
127
  }
155
-
156
128
  var history = Object.create(Object.prototype, {
157
129
  globalHistory: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
158
130
  writable: false,
@@ -202,12 +174,11 @@ function createHistoryManager() {
202
174
  });
203
175
  return history;
204
176
  }
205
-
206
177
  function createHistory() {
207
178
  var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
208
179
  var wapp = p.wapp,
209
- _p$history = p.history,
210
- history = _p$history === void 0 ? createHistoryManager() : _p$history;
180
+ _p$history = p.history,
181
+ history = _p$history === void 0 ? createHistoryManager() : _p$history;
211
182
  var historyProperties = Object.create(Object.prototype, {});
212
183
  (0, _utils.mergeProperties)(history, historyProperties);
213
184
  Object.defineProperty(history, "wapp", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
@@ -1,34 +1,26 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createMiddleware = createMiddleware;
9
8
  exports["default"] = _default;
10
9
  exports.run = run;
11
-
12
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
-
14
11
  var _createClient = _interopRequireDefault(require("./createClient"));
15
-
16
12
  var _config = _interopRequireDefault(require("./config"));
17
-
18
13
  // eslint-disable-next-line import/no-anonymous-default-export
19
14
  function _default() {
20
15
  var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
21
16
  return p.wapp || (0, _createClient["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, (0, _config["default"])(p)), p));
22
17
  }
23
-
24
18
  ;
25
-
26
19
  function createMiddleware() {
27
20
  var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
21
  var wapp = p.wapp || (0, _createClient["default"])(p);
29
22
  return wapp.client.app;
30
23
  }
31
-
32
24
  var defaultConfig = {
33
25
  config: {
34
26
  globals: {
@@ -41,30 +33,23 @@ var defaultConfig = {
41
33
  }
42
34
  }
43
35
  };
44
-
45
36
  function run(p) {
46
37
  var _p$config;
47
-
48
38
  if (p !== null && p !== void 0 && (_p$config = p.config) !== null && _p$config !== void 0 && _p$config.globals && !p.config.globals.RUN) {
49
39
  var _p$config2;
50
-
51
40
  p.config.globals.RUN = ((_p$config2 = p.config) === null || _p$config2 === void 0 ? void 0 : _p$config2.globals.NAME) || "wapplr";
52
41
  }
53
-
54
42
  var wapp = (0, _createClient["default"])(p);
55
43
  var globals = wapp.globals;
56
44
  var DEV = globals.DEV;
57
45
  var app = wapp.client.app;
58
46
  wapp.client.listen();
59
-
60
47
  if (typeof DEV !== "undefined" && DEV && module.hot) {
61
48
  app.hot = module.hot;
62
49
  module.hot.accept();
63
50
  }
64
-
65
51
  return wapp;
66
52
  }
67
-
68
53
  if (typeof RUN !== "undefined" && RUN === "wapplr") {
69
54
  run();
70
55
  }