@sunggang/ui-lib 0.4.41 → 0.4.43

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.
@@ -703,15 +703,15 @@ var LiffProvider = function(param) {
703
703
  // 初始化 LIFF
704
704
  var initializeLiff = function() {
705
705
  var _ref = _async_to_generator(function(isValid) {
706
- var customFetch, liff, originalFetch, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
706
+ var customFetch, liff, originalFetch, lineToken, redirectUri, e, tempFriendship, friendship, friendFlag, error, err;
707
707
  return _ts_generator(this, function(_state) {
708
708
  switch(_state.label){
709
709
  case 0:
710
710
  _state.trys.push([
711
711
  0,
712
- 9,
712
+ 16,
713
713
  ,
714
- 10
714
+ 17
715
715
  ]);
716
716
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
717
717
  // eslint-disable-next-line no-inner-declarations
@@ -730,19 +730,10 @@ var LiffProvider = function(param) {
730
730
  originalFetch = window.fetch;
731
731
  window.fetch = customFetch;
732
732
  if (openInApp && !(liff === null || liff === void 0 ? void 0 : liff.isInClient()) && (liff === null || liff === void 0 ? void 0 : liff.getOS()) !== "web") window.location.href = "line://app/".concat(liffId);
733
- return [
734
- 4,
735
- liff.init({
736
- liffId: liffId,
737
- withLoginOnExternalBrowser: false
738
- })
739
- ];
740
- case 2:
741
- _state.sent();
742
733
  console.log("LIFF init succeeded.");
743
734
  setLiffObject(liff);
744
735
  lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
745
- // 未登入先進行登入
736
+ // 未登入先進行登入(呼叫 login 後立即 return,避免後續執行 init)
746
737
  if (!liff.isLoggedIn()) {
747
738
  redirectUri = customerRedirectUrl || "".concat(window.location.href);
748
739
  if (liffLogin) {
@@ -759,12 +750,24 @@ var LiffProvider = function(param) {
759
750
  liff.login({
760
751
  redirectUri: redirectUri
761
752
  });
753
+ return [
754
+ 2
755
+ ];
762
756
  }
763
- tempFriendship = null;
764
- if (!lineToken) return [
757
+ if (!!liffId) return [
758
+ 3,
759
+ 2
760
+ ];
761
+ console.warn("liffId 未提供,跳過 liff.init()。");
762
+ return [
765
763
  3,
766
764
  8
767
765
  ];
766
+ case 2:
767
+ if (!!liff.isLoggedIn()) return [
768
+ 3,
769
+ 7
770
+ ];
768
771
  _state.label = 3;
769
772
  case 3:
770
773
  _state.trys.push([
@@ -775,26 +778,74 @@ var LiffProvider = function(param) {
775
778
  ]);
776
779
  return [
777
780
  4,
778
- liff.getFriendship()
781
+ liff.init({
782
+ liffId: liffId,
783
+ withLoginOnExternalBrowser: false
784
+ })
779
785
  ];
780
786
  case 4:
787
+ _state.sent();
788
+ return [
789
+ 3,
790
+ 6
791
+ ];
792
+ case 5:
793
+ e = _state.sent();
794
+ console.error("liff.init() 失敗:", e);
795
+ return [
796
+ 3,
797
+ 6
798
+ ];
799
+ case 6:
800
+ return [
801
+ 3,
802
+ 8
803
+ ];
804
+ case 7:
805
+ console.log("LIFF 已登入,跳過 liff.init() 以避免重複的 verify/profile 呼叫。");
806
+ _state.label = 8;
807
+ case 8:
808
+ tempFriendship = null;
809
+ if (!lineToken) return [
810
+ 3,
811
+ 15
812
+ ];
813
+ _state.label = 9;
814
+ case 9:
815
+ _state.trys.push([
816
+ 9,
817
+ 12,
818
+ ,
819
+ 13
820
+ ]);
821
+ if (!!liff.isLoggedIn()) return [
822
+ 3,
823
+ 11
824
+ ];
825
+ return [
826
+ 4,
827
+ liff.getFriendship()
828
+ ];
829
+ case 10:
781
830
  friendship = _state.sent();
782
831
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
783
832
  setFriendship(friendFlag);
784
833
  tempFriendship = friendFlag;
785
834
  console.log("isFriendship", friendFlag);
835
+ _state.label = 11;
836
+ case 11:
786
837
  return [
787
838
  3,
788
- 6
839
+ 13
789
840
  ];
790
- case 5:
841
+ case 12:
791
842
  error = _state.sent();
792
843
  console.error("Error in liff.getFriendship():", error);
793
844
  return [
794
845
  3,
795
- 6
846
+ 13
796
847
  ];
797
- case 6:
848
+ case 13:
798
849
  console.log("isValid", isValid);
799
850
  if (tempFriendship && isValid) return [
800
851
  2
@@ -803,23 +854,23 @@ var LiffProvider = function(param) {
803
854
  4,
804
855
  loginInit(lineToken)
805
856
  ];
806
- case 7:
857
+ case 14:
807
858
  _state.sent();
808
- _state.label = 8;
809
- case 8:
859
+ _state.label = 15;
860
+ case 15:
810
861
  return [
811
862
  3,
812
- 10
863
+ 17
813
864
  ];
814
- case 9:
865
+ case 16:
815
866
  err = _state.sent();
816
867
  setLiffError(err.toString());
817
868
  console.log("LIFF init failed.", err);
818
869
  return [
819
870
  3,
820
- 10
871
+ 17
821
872
  ];
822
- case 10:
873
+ case 17:
823
874
  return [
824
875
  2
825
876
  ];
@@ -699,15 +699,15 @@ var LiffProvider = function(param) {
699
699
  // 初始化 LIFF
700
700
  var initializeLiff = function() {
701
701
  var _ref = _async_to_generator(function(isValid) {
702
- var customFetch, liff, originalFetch, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
702
+ var customFetch, liff, originalFetch, lineToken, redirectUri, e, tempFriendship, friendship, friendFlag, error, err;
703
703
  return _ts_generator(this, function(_state) {
704
704
  switch(_state.label){
705
705
  case 0:
706
706
  _state.trys.push([
707
707
  0,
708
- 9,
708
+ 16,
709
709
  ,
710
- 10
710
+ 17
711
711
  ]);
712
712
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
713
713
  // eslint-disable-next-line no-inner-declarations
@@ -726,19 +726,10 @@ var LiffProvider = function(param) {
726
726
  originalFetch = window.fetch;
727
727
  window.fetch = customFetch;
728
728
  if (openInApp && !(liff === null || liff === void 0 ? void 0 : liff.isInClient()) && (liff === null || liff === void 0 ? void 0 : liff.getOS()) !== "web") window.location.href = "line://app/".concat(liffId);
729
- return [
730
- 4,
731
- liff.init({
732
- liffId: liffId,
733
- withLoginOnExternalBrowser: false
734
- })
735
- ];
736
- case 2:
737
- _state.sent();
738
729
  console.log("LIFF init succeeded.");
739
730
  setLiffObject(liff);
740
731
  lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
741
- // 未登入先進行登入
732
+ // 未登入先進行登入(呼叫 login 後立即 return,避免後續執行 init)
742
733
  if (!liff.isLoggedIn()) {
743
734
  redirectUri = customerRedirectUrl || "".concat(window.location.href);
744
735
  if (liffLogin) {
@@ -755,12 +746,24 @@ var LiffProvider = function(param) {
755
746
  liff.login({
756
747
  redirectUri: redirectUri
757
748
  });
749
+ return [
750
+ 2
751
+ ];
758
752
  }
759
- tempFriendship = null;
760
- if (!lineToken) return [
753
+ if (!!liffId) return [
754
+ 3,
755
+ 2
756
+ ];
757
+ console.warn("liffId 未提供,跳過 liff.init()。");
758
+ return [
761
759
  3,
762
760
  8
763
761
  ];
762
+ case 2:
763
+ if (!!liff.isLoggedIn()) return [
764
+ 3,
765
+ 7
766
+ ];
764
767
  _state.label = 3;
765
768
  case 3:
766
769
  _state.trys.push([
@@ -771,26 +774,74 @@ var LiffProvider = function(param) {
771
774
  ]);
772
775
  return [
773
776
  4,
774
- liff.getFriendship()
777
+ liff.init({
778
+ liffId: liffId,
779
+ withLoginOnExternalBrowser: false
780
+ })
775
781
  ];
776
782
  case 4:
783
+ _state.sent();
784
+ return [
785
+ 3,
786
+ 6
787
+ ];
788
+ case 5:
789
+ e = _state.sent();
790
+ console.error("liff.init() 失敗:", e);
791
+ return [
792
+ 3,
793
+ 6
794
+ ];
795
+ case 6:
796
+ return [
797
+ 3,
798
+ 8
799
+ ];
800
+ case 7:
801
+ console.log("LIFF 已登入,跳過 liff.init() 以避免重複的 verify/profile 呼叫。");
802
+ _state.label = 8;
803
+ case 8:
804
+ tempFriendship = null;
805
+ if (!lineToken) return [
806
+ 3,
807
+ 15
808
+ ];
809
+ _state.label = 9;
810
+ case 9:
811
+ _state.trys.push([
812
+ 9,
813
+ 12,
814
+ ,
815
+ 13
816
+ ]);
817
+ if (!!liff.isLoggedIn()) return [
818
+ 3,
819
+ 11
820
+ ];
821
+ return [
822
+ 4,
823
+ liff.getFriendship()
824
+ ];
825
+ case 10:
777
826
  friendship = _state.sent();
778
827
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
779
828
  setFriendship(friendFlag);
780
829
  tempFriendship = friendFlag;
781
830
  console.log("isFriendship", friendFlag);
831
+ _state.label = 11;
832
+ case 11:
782
833
  return [
783
834
  3,
784
- 6
835
+ 13
785
836
  ];
786
- case 5:
837
+ case 12:
787
838
  error = _state.sent();
788
839
  console.error("Error in liff.getFriendship():", error);
789
840
  return [
790
841
  3,
791
- 6
842
+ 13
792
843
  ];
793
- case 6:
844
+ case 13:
794
845
  console.log("isValid", isValid);
795
846
  if (tempFriendship && isValid) return [
796
847
  2
@@ -799,23 +850,23 @@ var LiffProvider = function(param) {
799
850
  4,
800
851
  loginInit(lineToken)
801
852
  ];
802
- case 7:
853
+ case 14:
803
854
  _state.sent();
804
- _state.label = 8;
805
- case 8:
855
+ _state.label = 15;
856
+ case 15:
806
857
  return [
807
858
  3,
808
- 10
859
+ 17
809
860
  ];
810
- case 9:
861
+ case 16:
811
862
  err = _state.sent();
812
863
  setLiffError(err.toString());
813
864
  console.log("LIFF init failed.", err);
814
865
  return [
815
866
  3,
816
- 10
867
+ 17
817
868
  ];
818
- case 10:
869
+ case 17:
819
870
  return [
820
871
  2
821
872
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.4.41",
3
+ "version": "0.4.43",
4
4
  "sideEffects": [
5
5
  "*.css",
6
6
  "./src/style.css",