efront 3.9.16 → 3.10.7

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,25 +1,14 @@
1
- var FormData = this.FormData;
2
- var { cookiesMap, getCookies, addCookie } = cookie;
1
+ var { cookiesMap, saveCookie } = cookie;
3
2
  var saveCookie = lazy(function () {
4
3
  sessionStorage.setItem(cookieItemsInSessionStorageKey, JSON.stringify(cookiesMap));
5
4
  }, 20);
6
- // ///// 1 ////////// 2 /////// 3 //// 4 //
7
- var domainReg = /^(?:(https?)\:)?\/\/(.*?)(?:\/(.*?))?([\?#].*)?$/i;
8
- var base = domainReg.test(location.href) ? '/' : "http://efront.cc/";
9
- var location_host = location.href.replace(domainReg, '$1://$2/');
10
- var setHost = function (host) {
11
- var parsed = parseURL(host);
12
- if (!host) return console.error("cross_host格式不正确", host);
13
- var host = parsed.host + (parsed.pathname || '/');
14
- host = (/^https/.test(location_host) ? "https://" : "http://") + host;
15
- base = host;
16
- };
17
5
  var { efrontURI, cross_host = efrontURI } = this;
18
- if (cross_host) setHost(cross_host);
19
- var HeadersKeys = ["Content-Type"];
6
+ var location_href = parseURL(location.href);
7
+ location_href = `${location_href.protocol}//${location_href.host}/`;
8
+ _cross.setLocation(location_href);
9
+
20
10
  var cookieItemsInSessionStorageKey = "--zimoli-coms-cross";
21
11
  var cookiesData = sessionStorage.getItem(cookieItemsInSessionStorageKey);
22
- var cors_hosts = [];
23
12
  if (cookiesData) {
24
13
  try {
25
14
  extend(cookiesMap, JSON.parse(cookiesData));
@@ -27,300 +16,45 @@ if (cookiesData) {
27
16
  console.warn("加载cookie出错!");
28
17
  }
29
18
  }
30
- function getDomainPath(url) {
31
- return url.replace(domainReg, "$2/$3");
32
- }
33
- function getRequestProtocol(url) {
34
- if (/^https:/i.test(url)) {
35
- return "https:";
36
- }
37
- return "http:";
38
- }
39
- function isChildPath(relative, path) {
40
- return relative.replace(/^(.*\/)[^\/]*$/, path);
41
- }
19
+
42
20
  var digest = function () {
43
21
  dispatch('render', window);
44
22
  };
45
23
 
46
- var getCrossUrl = function (domain, headers) {
47
- if (notCross(domain)) return domain;
48
- var originDomain = getDomainPath(domain);
49
- var _cookies = getCookies(originDomain);
50
- var _headers = {};
51
- if (_cookies) {
52
- _headers.Cookie = _cookies;
53
- }
54
- extend(_headers, headers);
55
- _headers = serialize(_headers);
56
- if (_headers) _headers = "," + _headers;
57
- return domain
58
- .replace(/^(s?)(\/\/)/i, "http$1:$2")
59
- .replace(domainReg, base + `*${/^(https\:|s\/\/)/i.test(domain) ? "*" : ""}$2${_headers}/$3$4`);
60
- };
61
- function cross(method, url, headers) {
62
- var originDomain = getDomainPath(url);
63
- if (!originDomain) throw new Error("Unsupposed url format!");
64
- var _cookies = getCookies(originDomain);
65
- var _headers = {};
66
- if (_cookies) {
67
- _headers.Cookie = _cookies;
68
- }
69
- extend(_headers, headers);
70
- if (/^[mc]/i.test(method)) {
71
- _headers["User-Agent"] = /^m/i.test(method)
72
- ? "Efront/1.9 (iPhone) Safari/602.1"
73
- : "Efront/1.9 (Windows) Chrome/77.0.3865.90";
74
- method = method.slice(1);
75
- }
76
- if (/^jsonp/i.test(method)) {
77
- var cb = method.split('\-')[1] || 'callback';
78
- setTimeout(function () {
79
- if (!isEmpty(jsondata) && isEmpty(datas)) {
80
- datas = serialize(jsondata);
81
- }
82
- if (datas) {
83
- xhr.src += "&" + datas;
84
- }
85
- });
86
- var xhr = jsonp(url, {
87
- [cb](a) {
88
- xhr.response = xhr.responseText = JSON.stringify(a);
89
- onload(xhr);
90
- }
91
- });
92
- xhr.onerror = function (e) {
93
- onerror(e);
94
- };
95
- xhr.abort = function () {
96
- removeFromList(requests, this);
97
- remove(this);
98
- };
99
- } else {
100
- var nocross = notCross(url);
101
- var xhr = new XMLHttpRequest;
102
- var abort = xhr.abort;
103
- xhr.abort = function () {
104
- xhr.onreadystatechange = null;
105
- removeFromList(requests, this);
106
- abort.call(this);
107
- clearTimeout(sendtimer);
108
- };
24
+ var cross = _cross.bind(function (callback, onerror) {
25
+ var xhr = new XMLHttpRequest;
26
+ var abort = xhr.abort;
27
+ xhr.abort = function () {
28
+ xhr.onreadystatechange = null;
29
+ abort.call(this);
30
+ };
31
+ xhr.onerror = onerror;
109
32
 
110
- xhr.onreadystatechange = function () {
111
- if (xhr.readyState === 4) {
112
- if (xhr.getResponseHeader && !nocross) {
113
- var cookie = xhr.getResponseHeader("efront-cookie");
114
- addCookie(cookie, originDomain);
115
- saveCookie();
116
- }
117
- switch (xhr.status) {
118
- case 0:
119
- if (!navigator.onLine) {
120
- onerror({ status: "网络断开" });
121
- break;
122
- }
123
- if (!xhr.response) {
124
- onerror({ status: "无法访问服务器" });
125
- break;
126
- }
127
- case 200:
128
- case 201:
129
- case 304:
130
- onload(xhr);
131
- break;
132
- case 302:
133
- case 301:
134
- if (xhr.isRedirected > 2 || nocross) break;
135
- var location = xhr.getResponseHeader("efront-location");
136
- if (!domainReg.test(location)) {
137
- if (/^\//.test(location)) {
138
- location = originDomain.replace(/\/.*$/, location);
139
- } else {
140
- location = originDomain.replace(/[^\/+]$/, location);
141
- }
142
- location = getRequestProtocol(url) + "//" + location;
143
- }
144
- var crs = cross("get", location, headers);
145
- crs.isRedirected = (xhr.isRedirected || 0) + 1;
146
- crs.done(onload, false);
147
- crs.error(onerror, false);
33
+ xhr.onreadystatechange = function () {
34
+ if (xhr.readyState === 4) {
35
+ dispatch(window, 'render');
36
+ switch (xhr.status) {
37
+ case 0:
38
+ if (!navigator.onLine) {
39
+ onerror({ status: "网络断开" });
148
40
  break;
149
- default:
150
- onerror(xhr);
151
- }
152
- dispatch(window, 'render');
153
- }
154
- };
155
- var setRequestHeader = xhr.setRequestHeader;
156
- var realHeaders = Object.create(null);
157
- xhr.setRequestHeader = function (key, value) {
158
- realHeaders[key] = value;
159
- };
160
- xhr.then = function (ok, oh) {
161
- onloads.push(ok);
162
- onerrors.push(oh);
163
- flush();
164
- };
165
- var fire = function () {
166
- var isform = /^f/i.test(method);
167
- if (isform) {
168
- if (method === 'form') method = 'post';
169
- else method = method.slice(1);
170
- }
171
- if (!isEmpty(jsondata) && isEmpty(datas)) {
172
- if (/^(get|head|trace)$/i.test(method)) {
173
- url = url.replace(/#[\s\S]*/, '');
174
- datas = serialize(jsondata);
175
- if (datas) url += (/\?/.test(url) ? "&" : "?") + datas;
176
- } else if (isform) {
177
- xhr.form(jsondata);
178
- } else {
179
- datas = JSON.stringify(jsondata);
180
- if (datas === "{}" || datas === "[]") {
181
- datas = '';
182
- } else {
183
- realHeaders["Content-Type"] = "application/json;charset=UTF-8";
184
41
  }
185
- }
186
- }
187
- if (nocross) {
188
- extend(realHeaders, _headers);
189
- xhr.open(method, url);
190
- } else {
191
- xhr.open(method, getCrossUrl(url, _headers));
192
- }
193
- Object.keys(realHeaders).forEach(key => setRequestHeader.call(xhr, key, realHeaders[key]));
194
- send.call(xhr, datas);
195
- digest();
196
- };
197
- var sendtimer = setTimeout(fire, 0);
198
- }
199
- var loaded, errored;
200
- var onload = function (xhr) {
201
- removeFromList(requests, xhr);
202
- if (xhr.decoder) {
203
- xhr = xhr.decoder(xhr);
204
- }
205
- loaded = xhr;
206
- flush();
207
- digest();
208
- };
209
- var onerror1 = function (e) {
210
- removeFromList(requests, e);
211
- errored = e || "未知错误!";
212
- flush();
213
- digest();
214
- };
215
- var onerror = async function (e) {
216
- for (var r of reforms) {
217
- var r = await reform(r, { method, url, status: xhr.status, headers: _headers }, fire, onerror1, e);
218
- if (r === false) return;
219
- }
220
- onerror1(e);
221
- };
222
- var flush = function () {
223
- var then = xhr.then;
224
- delete xhr.then;
225
- if (loaded) onloads.splice(0, onloads.length).map(e => e instanceof Function && e(xhr));
226
- if (errored) onerrors.splice(0, onerrors.length).map(e => e instanceof Function && e(errored));
227
- xhr.then = then;
228
- };
229
- var onloads = [], onerrors = [];
230
- xhr.done = xhr.success = function (on, asqueue = true) {
231
- if (!asqueue) onloads.splice(0, onloads.length);
232
- onloads.push(on);
233
- flush();
234
- return xhr;
235
- };
236
- var send = xhr.send;
237
- var datas = "";
238
- var jsondata = null;
239
- xhr.json = xhr.data = xhr.send = function (data, value) {
240
- if (!jsondata && !(isEmpty(data) && isEmpty(value))) jsondata = data instanceof Array ? [] : {};
241
- if (FormData && data instanceof FormData) {
242
- datas = data;
243
- } else if (isObject(data) && !isFile(data)) {
244
- extend(jsondata, data);
245
- } else if (!isEmpty(value)) {
246
- extend(jsondata, { [data]: value });
247
- } else if (isString(data) && value !== false && /^\s*\{|\=/.test(data)) {
248
- var data = /^\s*\{/.test(data) ? JSON.parse(data) : parseKV(data, "&", "=");
249
- extend(jsondata, data);
250
- } else {
251
- datas = data;
252
- }
253
- return xhr;
254
- };
255
- xhr.form = function (data) {
256
- xhr.data(data);
257
- if (FormData) {
258
- datas = new FormData;
259
- for (var k in jsondata) {
260
- datas.append(k, jsondata[k]);
42
+ break;
43
+ default:
44
+ callback();
261
45
  }
262
- } else {
263
- realHeaders["Content-Type"] = "application/x-www-form-urlencoded";
264
- datas = serialize(jsondata, "&", "=");
46
+ saveCookie();
265
47
  }
266
48
  };
267
- xhr.fail = xhr.error = function (on, asqueue = true) {
268
- if (!asqueue) {
269
- onerrors.splice(0, onerrors.length);
270
- }
271
- onerrors.push(on);
272
- flush();
273
- return xhr;
274
- };
275
- requests.push(xhr);
49
+
276
50
  return xhr;
277
- }
278
- function addDirect(a) {
279
- if (cors_hosts.indexOf(a) >= 0) return;
280
- if (typeof a === 'string' || a instanceof RegExp) cors_hosts.push(a);
281
- }
282
- function notCross(domain) {
283
- if (location_host === domain.slice(0, location_host.length) || !/^https?\:\/\/|^s?\/\//.test(domain)) return true;
284
- for (var cx = 0, dx = cors_hosts.length; cx < dx; cx++) {
285
- var host = cors_hosts[cx];
286
- if (host instanceof RegExp) {
287
- if (host.test(domain)) return true;
288
- } else {
289
- host = host.replace(domainReg, '$2/$3');
290
- if (domain.replace(domainReg, '$2/$3').slice(0, host.length) === host) return true;
291
- }
292
- }
293
- return false;
294
- }
51
+ }, jsonp, digest);
295
52
 
296
- var requests = [];
297
- var reforms = [];
298
- function reform(r, info, fire, cancel, e) {
299
- var fired = false;
300
- return r(info, function () {
301
- if (fired) return;
302
- fired = true;
303
- fire();
304
- }, function () {
305
- if (fired) return;
306
- fired = true;
307
- cancel(e);
308
- })
309
- }
310
- function addReform(r) {
311
- if (isFunction(r)) reforms.push(r);
312
- }
313
- extend(cross, {
314
- requests,
315
- abortAll() {
316
- var rs = requests.splice(0, requests.length);
317
- for (var r of rs) r.abort();
318
- },
319
- setHost,
320
- addReform,
321
- getCookies,
322
- saveCookie,
323
- addCookie,
324
- addDirect,
325
- getCrossUrl
326
- });
53
+ cross.setHost = function (host) {
54
+ var parsed = parseURL(host);
55
+ if (!host) return console.error("cross_host格式不正确", host);
56
+ var host = parsed.host + (parsed.pathname || '/');
57
+ host = (/^https/.test(location_href) ? "https://" : "http://") + host;
58
+ _cross.setHost(host);
59
+ };
60
+ if (cross_host) cross.setHost(cross_host);
@@ -962,7 +962,7 @@ var data = {
962
962
  instanceDataMap[instanceId] = data;
963
963
  }
964
964
  setItem(instanceId, data, rememberWithStorage);
965
- fireListener(instanceId);
965
+ fireListener(instanceId, data);
966
966
  return instanceDataMap[instanceId];
967
967
  },
968
968
  patchInstance(instanceId, data, rememberWithStorage = 0) {
@@ -999,7 +999,7 @@ var data = {
999
999
  if (!~listeners.indexOf(callback)) {
1000
1000
  listeners.push(callback);
1001
1001
  }
1002
- callback(this.getInstance(instanceId));
1002
+ if (hasItem(instanceId)) callback(getItem(instanceId));
1003
1003
  },
1004
1004
  unbindInstance(instanceId, callback) {
1005
1005
  if (!instanceListenerMap[instanceId]) return;
@@ -1047,12 +1047,15 @@ function getItem(instanceId, onlyFromLocalStorage = false) {
1047
1047
  }
1048
1048
  return data;
1049
1049
  }
1050
+ function hasItem(instanceId) {
1051
+ const storageId = userPrefix + instanceId + pagePathName;
1052
+ return sessionStorage.getItem(storageId) || localStorage.getItem(storageId);
1053
+ }
1050
1054
  var instanceListenerMap = {};
1051
- var fireListener = function (instanceId) {
1055
+ var fireListener = function (instanceId, data) {
1052
1056
  var listeners = instanceListenerMap[instanceId];
1053
1057
  if (!listeners) return;
1054
- var instance = instanceDataMap[instanceId];
1055
- listeners.forEach(a => a(instance));
1058
+ listeners.forEach(a => a(data));
1056
1059
  };
1057
1060
  data.setItem = data.setInstance;
1058
1061
  data.getItem = data.getInstance;
@@ -23,5 +23,8 @@ function jsonp(url, params) {
23
23
  url += /\?/.test(url) ? "&" + search : "?" + search;
24
24
  }
25
25
  var s = script(url);
26
+ s.abort = function () {
27
+ remove(this);
28
+ };
26
29
  return s;
27
30
  }
@@ -38,6 +38,9 @@ function main(children, multiple, addable) {
38
38
  item.name = option.name || option.innerHTML;
39
39
  var icon = option.getAttribute ? option.getAttribute("icon") : option.icon;
40
40
  if (icon) {
41
+ if (!hasIcon) {
42
+ page.setAttribute('iconed', '');
43
+ }
41
44
  hasIcon = true;
42
45
  css(item, { backgroundImage: `url('${icon}')` });
43
46
  }
@@ -125,9 +128,6 @@ function main(children, multiple, addable) {
125
128
  });
126
129
  adder.setAttribute("adder", '');
127
130
  }
128
- if (hasIcon) {
129
- page.setAttribute('iconed', '');
130
- }
131
131
  page.icon = iconed;
132
132
  on('mousedown')(page, e => e.preventDefault());
133
133
  return page;
@@ -36,10 +36,22 @@
36
36
  }
37
37
 
38
38
  &[iconed] {
39
- border-left: 30px solid #f2f4f6;
39
+ padding-left: 30px;
40
+
41
+ &:before {
42
+ content: "";
43
+ display: block;
44
+ position: absolute;
45
+ height: 100%;
46
+ top: 0;
47
+ left: 0;
48
+ width: 30px;
49
+ background: #f2f4f6;
50
+ }
40
51
 
41
52
  >div {
42
53
  filter: grayscale(1);
54
+ position: relative;
43
55
 
44
56
  &:hover,
45
57
  &:active,
@@ -125,6 +125,6 @@ body>& {
125
125
  .button {
126
126
  min-width: 60px;
127
127
  padding: 0 20px;
128
- margin-right: 10px;
128
+ margin-left: 10px;
129
129
  }
130
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.9.16",
3
+ "version": "3.10.7",
4
4
  "description": "一个开发工具,开放源代码,自带组件库和编译环境,可以用来开发web组件,web应用或nodejs模块,或做为已有代码的加密工具,也可以做为静态页面服务器或跨域中转服务器使用",
5
5
  "main": "public/efront.js",
6
6
  "directories": {