efront 4.22.3 → 4.22.5

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.
@@ -14,57 +14,36 @@ var pagehash_reg = /#([\/\w\:@\.\_\(\)\+\-\*\$@!~_'\?,&~%]+)$/;
14
14
  var locationInitHash = location.hash;
15
15
  var isFirstTimeLoad = sessionInitHash === null;
16
16
  var isSimpleRefresh = sessionInitHash === locationInitHash;
17
- var isWithHashLoad = !!location.hash;
18
17
  var preventNextHashChange = false;
19
18
  window_history.scrollRestoration = 'manual';
20
- if (isWithHashLoad && !isSimpleRefresh) {
21
- //带hash加载,吃掉hash
22
- location.replace("#");
23
- }
24
-
25
- if (/MSIE\s*[2-7]/.test(navigator.userAgent)) {
26
- window.onhistorychange = function (url) {
27
- // 如果是返回事件,一定不是第一次改变hash
28
- // 这里刚好可以屏蔽首次手动改变url可能产生的hashchange事件
29
- if (preventNextHashChange) return preventNextHashChange = false, window_history.go(-1);
30
- if (preventNextHashChange === void 0 ? onback && onback() === true : preventNextHashChange = void 0) { }
31
- };
32
- onselectstart(body, function (e) {
33
- return e.preventDefault();
34
- });
35
- var frame = document.createElement("iframe");
36
- css(frame, "display:none");
37
- appendChild.insert(body, frame);
38
- var doc = frame.contentWindow.document;
39
- var backman = function (isloaded) {
40
- doc.open();
41
- doc.write(isloaded !== false ? "" : "<script>result=parent.onhistorychange();onload=function(){history.forward()}</script>");
42
- doc.close();
43
- };
44
- backman(false);
45
- backman();
46
- } else {
47
- onhashchange(window, function (event) {
48
- if (fixurl.ing) return;
49
- // 如果是返回事件,一定不是第一次改变hash
50
- // 这里刚好可以屏蔽首次手动改变url可能产生的hashchange事件
51
- var targetHash = location.hash;
52
- sessionStorage.setItem(sessionSavedHashKey, targetHash);
53
- if (pagehash_reg.test(targetHash)) {
54
- var currentHash = getCurrentHash();
55
- if (currentHash && currentHash === targetHash) return;
56
- var targetHashIndex = targetHash.indexOf("#" + current_history);
57
- if (targetHashIndex < 0) return;
58
- var targetpath = targetHash.slice(targetHashIndex + current_history.replace(/\/$/, '').length + 1);
59
- targetpath = decodeURI(targetpath);
60
- go(targetpath);
61
- return;
62
- }
63
- if (preventNextHashChange) return preventNextHashChange = false;
64
- event.preventDefault();
65
- onback();
66
- });
19
+ var pathFromHash = function (targetHash) {
20
+ var targetHashIndex = targetHash.indexOf("#" + current_history);
21
+ if (targetHashIndex < 0) return;
22
+ var targetpath = targetHash.slice(targetHashIndex + current_history.replace(/\/$/, '').length + 1);
23
+ if (targetpath === '/') {
24
+ preventNextHashChange = true;
25
+ window_history.go(-1);
26
+ return;
27
+ }
28
+ targetpath = decodeURI(targetpath);
29
+ return targetpath;
67
30
  }
31
+ onhashchange(window, function (event) {
32
+ if (preventNextHashChange) return preventNextHashChange = false;
33
+ // 如果是返回事件,一定不是第一次改变hash
34
+ // 这里刚好可以屏蔽首次手动改变url可能产生的hashchange事件
35
+ var targetHash = location.hash;
36
+ sessionStorage.setItem(sessionSavedHashKey, targetHash);
37
+ if (pagehash_reg.test(targetHash)) {
38
+ var currentHash = getCurrentHash();
39
+ if (currentHash && currentHash === targetHash) return;
40
+ var targetpath = pathFromHash(targetHash);
41
+ forward(targetpath);
42
+ return;
43
+ }
44
+ event.preventDefault();
45
+ backward();
46
+ });
68
47
  // body
69
48
  var location_pathname = location.pathname;
70
49
  var _zimoli_params_key = `_zimoli_parameters:${location_pathname}#`;
@@ -113,8 +92,8 @@ function go(pagepath, args, history_name, oldpagepath) {
113
92
  if (isNumber(pagepath)) {
114
93
  if (isString(history_name)) {
115
94
  var _history = history[history_name] || [];
116
- pagepath = _history[pagepath < 1 ? _history.length + pagepath - 1 : pagepath];
117
- oldpagepath = _history[_history.length - 1];
95
+ pagepath = _history[pagepath < 2 ? _history.index + pagepath : pagepath];
96
+ oldpagepath = _history[_history.index];
118
97
  if (arguments.length === 1) {
119
98
  args = getZimoliParams(pagepath).data;
120
99
  }
@@ -171,7 +150,7 @@ function go(pagepath, args, history_name, oldpagepath) {
171
150
  addGlobal(_page, history_name, isRecover);
172
151
  page_object.prepares.splice(0, page_object.prepares.length).forEach(function (url) {
173
152
  if (isNumber(url)) {
174
- url = _history[url < 1 ? _history.length + url - 1 : url];
153
+ url = _history[url < 2 ? _history.index + url : url];
175
154
  }
176
155
  if (isString(url)) prepare(url);
177
156
  });
@@ -427,15 +406,24 @@ function create(pagepath, args, from, needroles) {
427
406
  return _page;
428
407
 
429
408
  }
430
-
409
+ var createEmptyHistory = function (emptyState) {
410
+ var h = [emptyState];
411
+ h.index = 0;
412
+ return h;
413
+ }
431
414
  var zimoliid = 0, zimoliad = 0;
432
415
  function zimoli(pagepath, args, history_name, oldpagepath) {
433
416
  if (arguments.length === 0) {
434
417
  if (zimoliid !== zimoliad) return;
435
418
  history_name = current_history;
436
- var _history = history[history_name] || [];
437
- root_path = _history[0] || "/main";
438
- pagepath = _history[_history.length - 1] || "/main";
419
+ var _history = history[history_name] || createEmptyHistory('/main');
420
+ root_path = _history[0];
421
+ pagepath = location.hash;
422
+ if (pagepath) {
423
+ if (_history.index > 0) pagepath = pathFromHash(pagepath);
424
+ else pagepath = '';
425
+ }
426
+ if (!pagepath) pagepath = _history[_history.index];
439
427
  try {
440
428
  var saveddata = JSAM.parse(hostoryStorage.getItem(_zimoli_params_key + pagepath)) || {};
441
429
  } catch (e) {
@@ -448,8 +436,6 @@ function zimoli(pagepath, args, history_name, oldpagepath) {
448
436
  if (isNode(history_name))
449
437
  var zid = history_name.zimoliid = (history_name.zimoliid | 0) + 1;
450
438
  else var zid = arguments.length ? ++zimoliid : zimoliid;
451
-
452
- if (page_generators[pagepath]) return go(pagepath, args, history_name, oldpagepath);
453
439
  return prepare(pagepath, function () {
454
440
  if (isNode(history_name)) {
455
441
  if (history_name.zimoliid !== zid) return;
@@ -460,7 +446,7 @@ function zimoli(pagepath, args, history_name, oldpagepath) {
460
446
  var global = {};
461
447
  var history = {};
462
448
  var current_history, default_history = current_history = "";
463
- history[current_history] = [];
449
+ history[current_history] = createEmptyHistory('/main');
464
450
  var history_session_object_key = `_zimoli_history_key:${location_pathname}`;
465
451
  try {
466
452
  history = JSAM.parse(hostoryStorage.getItem(history_session_object_key)) || history;
@@ -474,18 +460,25 @@ var pushstate = function (path_name, history_name) {
474
460
  }
475
461
  if (!isString(history_name)) return;
476
462
  if (!history[history_name]) {
477
- history[history_name] = [path_name];
463
+ history[history_name] = createEmptyHistory(path_name);
478
464
  } else {
479
465
  var _history = history[history_name];
480
- for (var cx = 0, dx = _history.length; cx < dx; cx++) {
466
+ var prevIndex = _history.index;
467
+ for (var cx = 0, dx = _history.index + 1; cx < dx; cx++) {
481
468
  if (_history[cx] === path_name) {
482
- _history.splice(cx, dx - cx);
469
+ _history.index = cx;
483
470
  isBack = cx < dx - 1;
484
471
  break;
485
472
  }
486
473
  }
487
- _history.push(path_name);
488
- if (_history.length) fixurl();
474
+ if (_history.index !== cx) {
475
+ _history.index++;
476
+ }
477
+ if (_history[_history.index] !== path_name) {
478
+ _history.splice(_history.index, _history.length - _history.index);
479
+ _history[_history.index] = path_name;
480
+ }
481
+ if (_history.index >= 0) fixurl(_history.index - prevIndex);
489
482
  }
490
483
  hostoryStorage.setItem(history_session_object_key, JSAM.stringify(history) || null);
491
484
  return isBack;
@@ -495,38 +488,47 @@ var popstate = function (path_name, history_name) {
495
488
  if (!isString(history_name)) return;
496
489
  if (!history[history_name]) return;
497
490
  var _history = history[history_name];
498
- for (var cx = 0, dx = _history.length; cx < dx; cx++) {
491
+ for (var cx = 0, dx = _history.index; cx < dx; cx++) {
499
492
  if (_history[cx] === path_name) {
500
- _history.splice(cx, dx - cx);
493
+ _history.index = cx;
501
494
  break;
502
495
  }
503
496
  }
504
497
  };
505
498
  var getCurrentHash = function () {
506
- var _historylist = history[current_history] || [];
507
499
  var history_name = current_history.replace(/\/$/, '');
508
500
  if (rootElements.length) {
509
501
  return `#${history_name}/`;
510
502
  }
511
- if (_historylist.length < 2) return "";
512
- var targeturl = `#${history_name}${_historylist.length ? _historylist[_historylist.length - 1] : ""}`;
503
+ var _historylist = history[current_history];
504
+ if (!_historylist || _historylist.index < 1) return "";
505
+ var targeturl = `#${history_name}${_historylist.length ? _historylist[_historylist.index] : ""}`;
513
506
  return encodeURI(targeturl);
514
507
  };
515
508
 
516
- var fixurl = function () {
517
- if (fixurl.ing) return;
518
- fixurl.ing = setTimeout(function () {
519
- fixurl.ing = false;
520
- var targeturl = getCurrentHash();
521
- if (pagehash_reg.test(targeturl)) {
522
- targeturl = location.href.replace(/\#[\s\S]*$/, '') + targeturl;
523
- if (!pagehash_reg.test(location.href)) location.href = targeturl;
524
- else if (location.hash !== targeturl) location.replace(targeturl);
525
- } else if (pagehash_reg.test(location.href)) {
526
- preventNextHashChange = true;
527
- window_history.go(-1);
528
- }
529
- }, 0);
509
+ var fixurl = function (historyDelta) {
510
+ preventNextHashChange = false;
511
+ var hash = getCurrentHash();
512
+ if (pagehash_reg.test(hash)) {
513
+ hash = location.href.replace(/\#[\s\S]*$/, '') + hash;
514
+ if (!pagehash_reg.test(location.href)) location.href = hash;
515
+ else if (location.href !== hash) {
516
+ if (historyDelta) {
517
+ preventNextHashChange = true;
518
+ window_history.go(historyDelta);
519
+ preventNextHashChange = false;
520
+ if (location.href !== hash) {
521
+ location.href = hash;
522
+ }
523
+ }
524
+ else location.replace(hash);
525
+ }
526
+ }
527
+ else if (pagehash_reg.test(location.hash)) {
528
+ preventNextHashChange = true;
529
+ window_history.go(-1);
530
+ preventNextHashChange = false;
531
+ }
530
532
  };
531
533
  var checkonback = function (elements) {
532
534
  for (var cx = 0, dx = elements.length; cx < dx; cx++) {
@@ -545,8 +547,16 @@ var checkonback = function (elements) {
545
547
  put(":empty", function () {
546
548
  return null;
547
549
  });
548
-
549
- var onback = function () {
550
+ var forward = function (pgpath) {
551
+ var hty = history[current_history];
552
+ if (hty[hty.index + 1] === pgpath) {
553
+ go(1);
554
+ }
555
+ else if (hty[hty.index - 1] === pgpath) {
556
+ go(-1);
557
+ }
558
+ };
559
+ var backward = function () {
550
560
  if (rootElements.length) {
551
561
  var onback = checkonback(rootElements.slice(rootElements.length - 1));
552
562
  fixurl();
@@ -632,7 +642,7 @@ var _switch = zimoli.switch = function (history_name = default_history, target_b
632
642
  }
633
643
  if (target_body) body = target_body;
634
644
  }
635
- if (emptyState !== false && !history[current_history]) root_path = (history[current_history] = [].concat(emptyState || ":empty"))[0];
645
+ if (emptyState !== false && !history[current_history]) root_path = (history[current_history] = createEmptyHistory(emptyState))[0];
636
646
  };
637
647
  popup.global = zimoli.global = addGlobal;
638
648
  popup.go = zimoli.go = go;
@@ -666,7 +676,7 @@ zimoli.setStorage = function (storage) {
666
676
  };
667
677
  zimoli.register = function (pathlike) {
668
678
  var params = [];
669
- pathlike = pathlike.replace(/\/\:(^[^\/]+)?/g, function (_, id) {
679
+ pathlike = pathlike.replace(/\/\:([^\/\:\-]+)/g, function (_, id) {
670
680
  params.push(id);
671
681
  return '';
672
682
  });
@@ -677,64 +687,100 @@ zimoli.clearHistory = function () {
677
687
  history = {};
678
688
  };
679
689
  zimoli.getCurrentHistory = function () {
680
- if (!history[current_history]) history[current_history] = [];
690
+ if (!history[current_history]) history[current_history] = createEmptyHistory();
681
691
  return history[current_history];
682
692
  };
683
693
  zimoli.inithash = locationInitHash;
684
694
  zimoli.createState = createState;
695
+ var touchEnabled = false;
685
696
  zimoli.enableTouchBack = function () {
686
- var touchTarget, currentTarget, history_name, historyList;
697
+ if (touchEnabled) return;
698
+ touchEnabled = true;
699
+ var backwardTarget, forwardTarget, currentTarget, history_name, historyList;
687
700
  var touchId = 0;
688
701
  var ratio = 0;
689
702
  var deltaX = 0;
690
703
  bindtouch(body, {
691
704
  start(event) {
692
705
  event.preventDefault();
706
+ touchId++;
693
707
  ratio = null;
694
708
  },
695
709
  move(a, event) {
696
710
  event.preventDefault();
697
711
  if (a !== null) {
712
+ ratio = a.x / body.clientWidth;
713
+ if (ratio <= -1) ratio = -0.999;
714
+ if (ratio >= 1) ratio = 0.999;
698
715
  if (!currentTarget) {
699
- var id = ++touchId;
700
716
  history_name = current_history;
701
717
  historyList = history[history_name];
702
718
  if (historyList.length < 2) return;
703
- var path1 = historyList[historyList.length - 1];
704
- var path0 = historyList[historyList.length - 2];
705
719
  currentTarget = global[history_name];
720
+ }
721
+ if (ratio > 0) a: {
722
+ if (backwardTarget) break a;
723
+ var id = ++touchId;
724
+ if (historyList.index < 1) return;
725
+ var path1 = historyList[historyList.index];
726
+ var path0 = historyList[historyList.index - 1];
706
727
  prepare(path0, function () {
707
728
  if (id !== touchId) return;
708
729
  var args = getZimoliParams(path0).data;
709
- touchTarget = create(path0, args, path1);
710
- setWithStyle(touchTarget, true);
711
- appendChild.insert(body, touchTarget);
730
+ backwardTarget = create(path0, args, path1);
731
+ setWithStyle(backwardTarget, true);
732
+ appendChild.insert(body, backwardTarget);
712
733
  });
734
+ if (forwardTarget) remove(forwardTarget, false), forwardTarget = null;
735
+ }
736
+ else if (ratio < 0) a: {
737
+ if (forwardTarget) break a;
738
+ var id = ++touchId;
739
+ if (historyList.index >= historyList.length - 1) return;
740
+ var path2 = historyList[historyList.index + 1];
741
+ prepare(path2, function () {
742
+ if (id !== touchId) return;
743
+ var args = getZimoliParams(path2).data;
744
+ forwardTarget = create(path2, args, path1);
745
+ setWithStyle(forwardTarget, false);
746
+ appendChild.insert(body, forwardTarget);
747
+ });
748
+ if (backwardTarget) remove(backwardTarget, false), backwardTarget = null;
713
749
  }
714
- ratio = a.x / body.clientWidth;
715
- if (ratio <= 0) ratio = 0.001;
716
- if (ratio >= 1) ratio = 0.999;
717
750
  deltaX = a.deltax;
718
751
  transition(currentTarget, ratio);
719
- transition(touchTarget, ratio - 1);
752
+ if (backwardTarget) transition(backwardTarget, ratio - 1);
753
+ if (forwardTarget) transition(forwardTarget, ratio + 1);
720
754
  }
721
755
  return { x: ratio * body.clientWidth };
722
756
  },
723
757
  end() {
724
- if (ratio === null || !touchTarget) return;
725
- if (deltaX > 0 && ratio > .1 || deltaX < 0 && ratio > .9 || deltaX === 0 && ratio > .4) {
726
- pushstate(historyList[historyList.length - 2], history_name);
758
+ if (ratio === null) return;
759
+ if (historyList.index >= 1 && (deltaX > 0 && ratio > .1 || deltaX < 0 && ratio > .9 || deltaX === 0 && ratio > .4)) {
760
+ setWithStyle(currentTarget, true);
761
+ pushstate(historyList[historyList.index - 1], history_name);
762
+ remove(currentTarget);
763
+ remove(forwardTarget, false);
764
+ transition(backwardTarget, 1);
765
+ global[history_name] = backwardTarget;
766
+ }
767
+ else if (historyList.index < historyList.length - 1 && (deltaX < 0 && ratio < -.1 || deltaX > 0 && ratio < -.9 || deltaX === 0 && ratio < -.4)) {
768
+ pushstate(historyList[historyList.index + 1], history_name);
769
+ setWithStyle(currentTarget, false);
727
770
  remove(currentTarget);
728
- transition(touchTarget, 1);
729
- global[history_name] = touchTarget;
771
+ remove(backwardTarget, false);
772
+ transition(forwardTarget, 1);
773
+ global[history_name] = forwardTarget;
730
774
  }
731
775
  else {
732
- setWithStyle(touchTarget, false);
733
- remove(touchTarget);
776
+ if (backwardTarget) setWithStyle(backwardTarget, false), remove(backwardTarget);
777
+ if (forwardTarget) setWithStyle(forwardTarget, true), remove(forwardTarget);
734
778
  transition(currentTarget, 1);
735
779
  }
736
780
  currentTarget = null;
737
- touchTarget = null;
781
+ backwardTarget = null;
782
+ historyList = null;
783
+ forwardTarget = null;
738
784
  ratio = null;
739
785
  }
740
786
  }, 'x')
@@ -221,7 +221,8 @@
221
221
  }
222
222
  if (anchorOffset >= anchorNode.nodeValue.length) {
223
223
  followChar = anchorNode.nextSibling || anchorNode.parentNode.nextSibling;
224
- if (followChar.nodeType === 1) {
224
+ if (!followChar) followChar = '';
225
+ else if (followChar.nodeType === 1) {
225
226
  beforeText = /^text$/i.test(followChar.tagName);
226
227
  followChar = followChar.innerText.charAt(0);
227
228
  }
@@ -263,7 +264,6 @@
263
264
  var { data, inputType } = event;
264
265
  coderid++;
265
266
  var patchAfter = '';
266
- console.log("follow-char", followChar, 'data', data, 'anchor-char', anchorChar);
267
267
  switch (inputType) {
268
268
  case "insertText":
269
269
  if (data === ' ') return;
@@ -289,10 +289,7 @@
289
289
  if (anchorChar in pairsmap && followChar === pairsmap[anchorChar]) {
290
290
  document.execCommand('forwardDelete');
291
291
  }
292
- if (inText) return;
293
- updatechar();
294
- if (inText) return;
295
- break;
292
+ return;
296
293
 
297
294
  }
298
295
  markAnchorOffset(光标 + patchAfter);
@@ -307,7 +304,6 @@
307
304
  markedText = await 上色.text(coder.type, markedText);
308
305
  if (coderid !== id) return;
309
306
  更新(markedText);
310
- dispatch(coder, 'change');
311
307
  return;
312
308
  }, -60);
313
309
  var keytab = function (direction) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.22.3",
3
+ "version": "4.22.5",
4
4
  "description": "一个开发环境,提供一种自由的前端开发模式,也可作为辅助工具使用。",
5
5
  "main": "public/efront.js",
6
6
  "directories": {