@sunggang/ui-lib 0.4.47 → 0.4.49

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.
@@ -728,15 +728,15 @@ var LiffProvider = function(param) {
728
728
  // 初始化 LIFF
729
729
  var initializeLiff = function() {
730
730
  var _ref = _async_to_generator(function(isValid) {
731
- var customFetch, liff, originalFetch, profile, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
731
+ var customFetch, liff, redirectUri, originalFetch, profile, lineToken, tempFriendship, friendship, friendFlag, error, err;
732
732
  return _ts_generator(this, function(_state) {
733
733
  switch(_state.label){
734
734
  case 0:
735
735
  _state.trys.push([
736
736
  0,
737
- 10,
737
+ 12,
738
738
  ,
739
- 11
739
+ 13
740
740
  ]);
741
741
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
742
742
  // eslint-disable-next-line no-inner-declarations
@@ -746,15 +746,46 @@ var LiffProvider = function(param) {
746
746
  }
747
747
  return originalFetch(url, options);
748
748
  };
749
+ if (!liffId) {
750
+ console.warn("liffId 未提供,無法初始化 LIFF");
751
+ return [
752
+ 2
753
+ ];
754
+ }
749
755
  return [
750
756
  4,
751
757
  Promise.resolve().then(function () { return require('./index.cjs3.js'); })
752
758
  ];
753
759
  case 1:
754
760
  liff = _state.sent().liff;
761
+ // 未登入先進行登入
762
+ if (!liff.isLoggedIn()) {
763
+ redirectUri = customerRedirectUrl || "".concat(window.location.href);
764
+ if (liffLogin) {
765
+ liff.login({
766
+ redirectUri: redirectUri
767
+ });
768
+ return [
769
+ 2
770
+ ];
771
+ }
772
+ if (loginByUser || ignoreRoute) return [
773
+ 2
774
+ ];
775
+ liff.login({
776
+ redirectUri: redirectUri
777
+ });
778
+ return [
779
+ 2
780
+ ];
781
+ }
755
782
  originalFetch = window.fetch;
756
783
  window.fetch = customFetch;
757
784
  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);
785
+ if (!!liff.isLoggedIn()) return [
786
+ 3,
787
+ 4
788
+ ];
758
789
  return [
759
790
  4,
760
791
  liff.init({
@@ -774,60 +805,50 @@ var LiffProvider = function(param) {
774
805
  profile = _state.sent();
775
806
  setLiffProfile(profile);
776
807
  saveLiffUserInfoToStorage(profile);
808
+ _state.label = 4;
809
+ case 4:
777
810
  lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
778
- // 未登入先進行登入
779
- if (!liff.isLoggedIn()) {
780
- redirectUri = customerRedirectUrl || "".concat(window.location.href);
781
- if (liffLogin) {
782
- liff.login({
783
- redirectUri: redirectUri
784
- });
785
- return [
786
- 2
787
- ];
788
- }
789
- if (loginByUser || ignoreRoute) return [
790
- 2
791
- ];
792
- liff.login({
793
- redirectUri: redirectUri
794
- });
795
- }
796
811
  tempFriendship = null;
797
812
  if (!lineToken) return [
798
813
  3,
799
- 9
814
+ 11
800
815
  ];
801
- _state.label = 4;
802
- case 4:
816
+ _state.label = 5;
817
+ case 5:
803
818
  _state.trys.push([
804
- 4,
805
- 6,
819
+ 5,
820
+ 8,
806
821
  ,
807
- 7
822
+ 9
808
823
  ]);
824
+ if (!!liff.isLoggedIn()) return [
825
+ 3,
826
+ 7
827
+ ];
809
828
  return [
810
829
  4,
811
830
  liff.getFriendship()
812
831
  ];
813
- case 5:
832
+ case 6:
814
833
  friendship = _state.sent();
815
834
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
816
835
  setFriendship(friendFlag);
817
836
  tempFriendship = friendFlag;
818
837
  console.log("isFriendship", friendFlag);
838
+ _state.label = 7;
839
+ case 7:
819
840
  return [
820
841
  3,
821
- 7
842
+ 9
822
843
  ];
823
- case 6:
844
+ case 8:
824
845
  error = _state.sent();
825
846
  console.error("Error in liff.getFriendship():", error);
826
847
  return [
827
848
  3,
828
- 7
849
+ 9
829
850
  ];
830
- case 7:
851
+ case 9:
831
852
  console.log("isValid", isValid);
832
853
  if (tempFriendship && isValid) return [
833
854
  2
@@ -836,23 +857,23 @@ var LiffProvider = function(param) {
836
857
  4,
837
858
  loginInit(lineToken)
838
859
  ];
839
- case 8:
860
+ case 10:
840
861
  _state.sent();
841
- _state.label = 9;
842
- case 9:
862
+ _state.label = 11;
863
+ case 11:
843
864
  return [
844
865
  3,
845
- 11
866
+ 13
846
867
  ];
847
- case 10:
868
+ case 12:
848
869
  err = _state.sent();
849
870
  setLiffError(err.toString());
850
871
  console.log("LIFF init failed.", err);
851
872
  return [
852
873
  3,
853
- 11
874
+ 13
854
875
  ];
855
- case 11:
876
+ case 13:
856
877
  return [
857
878
  2
858
879
  ];
@@ -724,15 +724,15 @@ var LiffProvider = function(param) {
724
724
  // 初始化 LIFF
725
725
  var initializeLiff = function() {
726
726
  var _ref = _async_to_generator(function(isValid) {
727
- var customFetch, liff, originalFetch, profile, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
727
+ var customFetch, liff, redirectUri, originalFetch, profile, lineToken, tempFriendship, friendship, friendFlag, error, err;
728
728
  return _ts_generator(this, function(_state) {
729
729
  switch(_state.label){
730
730
  case 0:
731
731
  _state.trys.push([
732
732
  0,
733
- 10,
733
+ 12,
734
734
  ,
735
- 11
735
+ 13
736
736
  ]);
737
737
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
738
738
  // eslint-disable-next-line no-inner-declarations
@@ -742,15 +742,46 @@ var LiffProvider = function(param) {
742
742
  }
743
743
  return originalFetch(url, options);
744
744
  };
745
+ if (!liffId) {
746
+ console.warn("liffId 未提供,無法初始化 LIFF");
747
+ return [
748
+ 2
749
+ ];
750
+ }
745
751
  return [
746
752
  4,
747
753
  import('./index.esm3.js')
748
754
  ];
749
755
  case 1:
750
756
  liff = _state.sent().liff;
757
+ // 未登入先進行登入
758
+ if (!liff.isLoggedIn()) {
759
+ redirectUri = customerRedirectUrl || "".concat(window.location.href);
760
+ if (liffLogin) {
761
+ liff.login({
762
+ redirectUri: redirectUri
763
+ });
764
+ return [
765
+ 2
766
+ ];
767
+ }
768
+ if (loginByUser || ignoreRoute) return [
769
+ 2
770
+ ];
771
+ liff.login({
772
+ redirectUri: redirectUri
773
+ });
774
+ return [
775
+ 2
776
+ ];
777
+ }
751
778
  originalFetch = window.fetch;
752
779
  window.fetch = customFetch;
753
780
  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);
781
+ if (!!liff.isLoggedIn()) return [
782
+ 3,
783
+ 4
784
+ ];
754
785
  return [
755
786
  4,
756
787
  liff.init({
@@ -770,60 +801,50 @@ var LiffProvider = function(param) {
770
801
  profile = _state.sent();
771
802
  setLiffProfile(profile);
772
803
  saveLiffUserInfoToStorage(profile);
804
+ _state.label = 4;
805
+ case 4:
773
806
  lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
774
- // 未登入先進行登入
775
- if (!liff.isLoggedIn()) {
776
- redirectUri = customerRedirectUrl || "".concat(window.location.href);
777
- if (liffLogin) {
778
- liff.login({
779
- redirectUri: redirectUri
780
- });
781
- return [
782
- 2
783
- ];
784
- }
785
- if (loginByUser || ignoreRoute) return [
786
- 2
787
- ];
788
- liff.login({
789
- redirectUri: redirectUri
790
- });
791
- }
792
807
  tempFriendship = null;
793
808
  if (!lineToken) return [
794
809
  3,
795
- 9
810
+ 11
796
811
  ];
797
- _state.label = 4;
798
- case 4:
812
+ _state.label = 5;
813
+ case 5:
799
814
  _state.trys.push([
800
- 4,
801
- 6,
815
+ 5,
816
+ 8,
802
817
  ,
803
- 7
818
+ 9
804
819
  ]);
820
+ if (!!liff.isLoggedIn()) return [
821
+ 3,
822
+ 7
823
+ ];
805
824
  return [
806
825
  4,
807
826
  liff.getFriendship()
808
827
  ];
809
- case 5:
828
+ case 6:
810
829
  friendship = _state.sent();
811
830
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
812
831
  setFriendship(friendFlag);
813
832
  tempFriendship = friendFlag;
814
833
  console.log("isFriendship", friendFlag);
834
+ _state.label = 7;
835
+ case 7:
815
836
  return [
816
837
  3,
817
- 7
838
+ 9
818
839
  ];
819
- case 6:
840
+ case 8:
820
841
  error = _state.sent();
821
842
  console.error("Error in liff.getFriendship():", error);
822
843
  return [
823
844
  3,
824
- 7
845
+ 9
825
846
  ];
826
- case 7:
847
+ case 9:
827
848
  console.log("isValid", isValid);
828
849
  if (tempFriendship && isValid) return [
829
850
  2
@@ -832,23 +853,23 @@ var LiffProvider = function(param) {
832
853
  4,
833
854
  loginInit(lineToken)
834
855
  ];
835
- case 8:
856
+ case 10:
836
857
  _state.sent();
837
- _state.label = 9;
838
- case 9:
858
+ _state.label = 11;
859
+ case 11:
839
860
  return [
840
861
  3,
841
- 11
862
+ 13
842
863
  ];
843
- case 10:
864
+ case 12:
844
865
  err = _state.sent();
845
866
  setLiffError(err.toString());
846
867
  console.log("LIFF init failed.", err);
847
868
  return [
848
869
  3,
849
- 11
870
+ 13
850
871
  ];
851
- case 11:
872
+ case 13:
852
873
  return [
853
874
  2
854
875
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.4.47",
3
+ "version": "0.4.49",
4
4
  "sideEffects": [
5
5
  "*.css",
6
6
  "./src/style.css",