@sunggang/ui-lib 0.4.57 → 0.4.58
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.
- package/LiffProvider.cjs.js +93 -60
- package/LiffProvider.esm.js +93 -60
- package/package.json +1 -1
- package/src/lib/Provider/LiffProvider.d.ts +1 -0
package/LiffProvider.cjs.js
CHANGED
|
@@ -767,15 +767,15 @@ var LiffProvider = function(param) {
|
|
|
767
767
|
// 初始化 LIFF
|
|
768
768
|
var initializeLiff = function() {
|
|
769
769
|
var _ref = _async_to_generator(function(isValid) {
|
|
770
|
-
var customFetch, liff, originalFetch,
|
|
770
|
+
var customFetch, liff, originalFetch, redirectUri, tempFriendship, lineToken, profile, profileErr, friendship, friendFlag, error, err;
|
|
771
771
|
return _ts_generator(this, function(_state) {
|
|
772
772
|
switch(_state.label){
|
|
773
773
|
case 0:
|
|
774
774
|
_state.trys.push([
|
|
775
775
|
0,
|
|
776
|
-
|
|
776
|
+
13,
|
|
777
777
|
,
|
|
778
|
-
|
|
778
|
+
14
|
|
779
779
|
]);
|
|
780
780
|
customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
|
|
781
781
|
// eslint-disable-next-line no-inner-declarations
|
|
@@ -794,6 +794,9 @@ var LiffProvider = function(param) {
|
|
|
794
794
|
originalFetch = window.fetch;
|
|
795
795
|
window.fetch = customFetch;
|
|
796
796
|
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);
|
|
797
|
+
if (isValid) return [
|
|
798
|
+
2
|
|
799
|
+
];
|
|
797
800
|
return [
|
|
798
801
|
4,
|
|
799
802
|
liff.init({
|
|
@@ -805,17 +808,26 @@ var LiffProvider = function(param) {
|
|
|
805
808
|
_state.sent();
|
|
806
809
|
console.log("LIFF init succeeded.");
|
|
807
810
|
setLiffObject(liff);
|
|
808
|
-
//
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
811
|
+
// 未登入先進行登入
|
|
812
|
+
if (!liff.isLoggedIn()) {
|
|
813
|
+
redirectUri = customerRedirectUrl || "".concat(window.location.href);
|
|
814
|
+
if (liffLogin) {
|
|
815
|
+
liff.login({
|
|
816
|
+
redirectUri: redirectUri
|
|
817
|
+
});
|
|
818
|
+
return [
|
|
819
|
+
2
|
|
820
|
+
];
|
|
821
|
+
}
|
|
822
|
+
if (loginByUser || ignoreRoute) return [
|
|
823
|
+
2
|
|
824
|
+
];
|
|
825
|
+
liff.login({
|
|
826
|
+
redirectUri: redirectUri
|
|
827
|
+
});
|
|
814
828
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
7
|
|
818
|
-
];
|
|
829
|
+
tempFriendship = null;
|
|
830
|
+
lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
|
|
819
831
|
_state.label = 3;
|
|
820
832
|
case 3:
|
|
821
833
|
_state.trys.push([
|
|
@@ -838,58 +850,29 @@ var LiffProvider = function(param) {
|
|
|
838
850
|
];
|
|
839
851
|
case 5:
|
|
840
852
|
profileErr = _state.sent();
|
|
841
|
-
console.warn("取得 LIFF profile
|
|
853
|
+
console.warn("取得 LIFF profile 失敗:", profileErr);
|
|
842
854
|
return [
|
|
843
855
|
3,
|
|
844
856
|
6
|
|
845
857
|
];
|
|
846
858
|
case 6:
|
|
847
|
-
return [
|
|
848
|
-
3,
|
|
849
|
-
8
|
|
850
|
-
];
|
|
851
|
-
case 7:
|
|
852
|
-
// 已有快取,跳過呼叫
|
|
853
|
-
console.log("跳過 liff.getProfile():已由 localStorage 或 state 取得 profile");
|
|
854
|
-
_state.label = 8;
|
|
855
|
-
case 8:
|
|
856
|
-
lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
|
|
857
|
-
// 未登入先進行登入
|
|
858
|
-
if (!liff.isLoggedIn()) {
|
|
859
|
-
redirectUri = customerRedirectUrl || "".concat(window.location.href);
|
|
860
|
-
if (liffLogin) {
|
|
861
|
-
liff.login({
|
|
862
|
-
redirectUri: redirectUri
|
|
863
|
-
});
|
|
864
|
-
return [
|
|
865
|
-
2
|
|
866
|
-
];
|
|
867
|
-
}
|
|
868
|
-
if (loginByUser || ignoreRoute) return [
|
|
869
|
-
2
|
|
870
|
-
];
|
|
871
|
-
liff.login({
|
|
872
|
-
redirectUri: redirectUri
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
tempFriendship = null;
|
|
876
859
|
if (!lineToken) return [
|
|
877
860
|
3,
|
|
878
|
-
|
|
861
|
+
12
|
|
879
862
|
];
|
|
880
|
-
_state.label =
|
|
881
|
-
case
|
|
863
|
+
_state.label = 7;
|
|
864
|
+
case 7:
|
|
882
865
|
_state.trys.push([
|
|
866
|
+
7,
|
|
883
867
|
9,
|
|
884
|
-
11,
|
|
885
868
|
,
|
|
886
|
-
|
|
869
|
+
10
|
|
887
870
|
]);
|
|
888
871
|
return [
|
|
889
872
|
4,
|
|
890
873
|
liff.getFriendship()
|
|
891
874
|
];
|
|
892
|
-
case
|
|
875
|
+
case 8:
|
|
893
876
|
friendship = _state.sent();
|
|
894
877
|
friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
|
|
895
878
|
setFriendship(friendFlag);
|
|
@@ -897,16 +880,16 @@ var LiffProvider = function(param) {
|
|
|
897
880
|
console.log("isFriendship", friendFlag);
|
|
898
881
|
return [
|
|
899
882
|
3,
|
|
900
|
-
|
|
883
|
+
10
|
|
901
884
|
];
|
|
902
|
-
case
|
|
885
|
+
case 9:
|
|
903
886
|
error = _state.sent();
|
|
904
887
|
console.error("Error in liff.getFriendship():", error);
|
|
905
888
|
return [
|
|
906
889
|
3,
|
|
907
|
-
|
|
890
|
+
10
|
|
908
891
|
];
|
|
909
|
-
case
|
|
892
|
+
case 10:
|
|
910
893
|
console.log("isValid", isValid);
|
|
911
894
|
if (tempFriendship && isValid) return [
|
|
912
895
|
2
|
|
@@ -915,23 +898,23 @@ var LiffProvider = function(param) {
|
|
|
915
898
|
4,
|
|
916
899
|
loginInit(lineToken)
|
|
917
900
|
];
|
|
918
|
-
case
|
|
901
|
+
case 11:
|
|
919
902
|
_state.sent();
|
|
920
|
-
_state.label =
|
|
921
|
-
case
|
|
903
|
+
_state.label = 12;
|
|
904
|
+
case 12:
|
|
922
905
|
return [
|
|
923
906
|
3,
|
|
924
|
-
|
|
907
|
+
14
|
|
925
908
|
];
|
|
926
|
-
case
|
|
909
|
+
case 13:
|
|
927
910
|
err = _state.sent();
|
|
928
911
|
setLiffError(err.toString());
|
|
929
912
|
console.log("LIFF init failed.", err);
|
|
930
913
|
return [
|
|
931
914
|
3,
|
|
932
|
-
|
|
915
|
+
14
|
|
933
916
|
];
|
|
934
|
-
case
|
|
917
|
+
case 14:
|
|
935
918
|
return [
|
|
936
919
|
2
|
|
937
920
|
];
|
|
@@ -1198,6 +1181,56 @@ var LiffProvider = function(param) {
|
|
|
1198
1181
|
var contextValue = React.useMemo(function() {
|
|
1199
1182
|
return {
|
|
1200
1183
|
liffObject: liffObject,
|
|
1184
|
+
// 為相容性保留 liffObject,另提供 liff 屬性(直接暴露 SDK 物件)
|
|
1185
|
+
liff: liffObject,
|
|
1186
|
+
// 非同步取得 LIFF SDK 的 helper(lazy-load),使用時可以呼叫 `await getLiff()`
|
|
1187
|
+
getLiff: /*#__PURE__*/ _async_to_generator(function() {
|
|
1188
|
+
var mod, sdk, e;
|
|
1189
|
+
return _ts_generator(this, function(_state) {
|
|
1190
|
+
switch(_state.label){
|
|
1191
|
+
case 0:
|
|
1192
|
+
if (liffObject) return [
|
|
1193
|
+
2,
|
|
1194
|
+
liffObject
|
|
1195
|
+
];
|
|
1196
|
+
if (typeof window === "undefined") return [
|
|
1197
|
+
2,
|
|
1198
|
+
null
|
|
1199
|
+
];
|
|
1200
|
+
_state.label = 1;
|
|
1201
|
+
case 1:
|
|
1202
|
+
_state.trys.push([
|
|
1203
|
+
1,
|
|
1204
|
+
3,
|
|
1205
|
+
,
|
|
1206
|
+
4
|
|
1207
|
+
]);
|
|
1208
|
+
return [
|
|
1209
|
+
4,
|
|
1210
|
+
Promise.resolve().then(function () { return require('./index.cjs3.js'); })
|
|
1211
|
+
];
|
|
1212
|
+
case 2:
|
|
1213
|
+
mod = _state.sent();
|
|
1214
|
+
sdk = mod === null || mod === void 0 ? void 0 : mod.liff;
|
|
1215
|
+
if (sdk) setLiffObject(sdk);
|
|
1216
|
+
return [
|
|
1217
|
+
2,
|
|
1218
|
+
sdk || null
|
|
1219
|
+
];
|
|
1220
|
+
case 3:
|
|
1221
|
+
e = _state.sent();
|
|
1222
|
+
console.error("lazy import @line/liff failed", e);
|
|
1223
|
+
return [
|
|
1224
|
+
2,
|
|
1225
|
+
null
|
|
1226
|
+
];
|
|
1227
|
+
case 4:
|
|
1228
|
+
return [
|
|
1229
|
+
2
|
|
1230
|
+
];
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
}),
|
|
1201
1234
|
loginData: loginData,
|
|
1202
1235
|
userInfo: userInfo,
|
|
1203
1236
|
accessToken: accessToken,
|
package/LiffProvider.esm.js
CHANGED
|
@@ -763,15 +763,15 @@ var LiffProvider = function(param) {
|
|
|
763
763
|
// 初始化 LIFF
|
|
764
764
|
var initializeLiff = function() {
|
|
765
765
|
var _ref = _async_to_generator(function(isValid) {
|
|
766
|
-
var customFetch, liff, originalFetch,
|
|
766
|
+
var customFetch, liff, originalFetch, redirectUri, tempFriendship, lineToken, profile, profileErr, friendship, friendFlag, error, err;
|
|
767
767
|
return _ts_generator(this, function(_state) {
|
|
768
768
|
switch(_state.label){
|
|
769
769
|
case 0:
|
|
770
770
|
_state.trys.push([
|
|
771
771
|
0,
|
|
772
|
-
|
|
772
|
+
13,
|
|
773
773
|
,
|
|
774
|
-
|
|
774
|
+
14
|
|
775
775
|
]);
|
|
776
776
|
customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
|
|
777
777
|
// eslint-disable-next-line no-inner-declarations
|
|
@@ -790,6 +790,9 @@ var LiffProvider = function(param) {
|
|
|
790
790
|
originalFetch = window.fetch;
|
|
791
791
|
window.fetch = customFetch;
|
|
792
792
|
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);
|
|
793
|
+
if (isValid) return [
|
|
794
|
+
2
|
|
795
|
+
];
|
|
793
796
|
return [
|
|
794
797
|
4,
|
|
795
798
|
liff.init({
|
|
@@ -801,17 +804,26 @@ var LiffProvider = function(param) {
|
|
|
801
804
|
_state.sent();
|
|
802
805
|
console.log("LIFF init succeeded.");
|
|
803
806
|
setLiffObject(liff);
|
|
804
|
-
//
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
807
|
+
// 未登入先進行登入
|
|
808
|
+
if (!liff.isLoggedIn()) {
|
|
809
|
+
redirectUri = customerRedirectUrl || "".concat(window.location.href);
|
|
810
|
+
if (liffLogin) {
|
|
811
|
+
liff.login({
|
|
812
|
+
redirectUri: redirectUri
|
|
813
|
+
});
|
|
814
|
+
return [
|
|
815
|
+
2
|
|
816
|
+
];
|
|
817
|
+
}
|
|
818
|
+
if (loginByUser || ignoreRoute) return [
|
|
819
|
+
2
|
|
820
|
+
];
|
|
821
|
+
liff.login({
|
|
822
|
+
redirectUri: redirectUri
|
|
823
|
+
});
|
|
810
824
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
7
|
|
814
|
-
];
|
|
825
|
+
tempFriendship = null;
|
|
826
|
+
lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
|
|
815
827
|
_state.label = 3;
|
|
816
828
|
case 3:
|
|
817
829
|
_state.trys.push([
|
|
@@ -834,58 +846,29 @@ var LiffProvider = function(param) {
|
|
|
834
846
|
];
|
|
835
847
|
case 5:
|
|
836
848
|
profileErr = _state.sent();
|
|
837
|
-
console.warn("取得 LIFF profile
|
|
849
|
+
console.warn("取得 LIFF profile 失敗:", profileErr);
|
|
838
850
|
return [
|
|
839
851
|
3,
|
|
840
852
|
6
|
|
841
853
|
];
|
|
842
854
|
case 6:
|
|
843
|
-
return [
|
|
844
|
-
3,
|
|
845
|
-
8
|
|
846
|
-
];
|
|
847
|
-
case 7:
|
|
848
|
-
// 已有快取,跳過呼叫
|
|
849
|
-
console.log("跳過 liff.getProfile():已由 localStorage 或 state 取得 profile");
|
|
850
|
-
_state.label = 8;
|
|
851
|
-
case 8:
|
|
852
|
-
lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
|
|
853
|
-
// 未登入先進行登入
|
|
854
|
-
if (!liff.isLoggedIn()) {
|
|
855
|
-
redirectUri = customerRedirectUrl || "".concat(window.location.href);
|
|
856
|
-
if (liffLogin) {
|
|
857
|
-
liff.login({
|
|
858
|
-
redirectUri: redirectUri
|
|
859
|
-
});
|
|
860
|
-
return [
|
|
861
|
-
2
|
|
862
|
-
];
|
|
863
|
-
}
|
|
864
|
-
if (loginByUser || ignoreRoute) return [
|
|
865
|
-
2
|
|
866
|
-
];
|
|
867
|
-
liff.login({
|
|
868
|
-
redirectUri: redirectUri
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
tempFriendship = null;
|
|
872
855
|
if (!lineToken) return [
|
|
873
856
|
3,
|
|
874
|
-
|
|
857
|
+
12
|
|
875
858
|
];
|
|
876
|
-
_state.label =
|
|
877
|
-
case
|
|
859
|
+
_state.label = 7;
|
|
860
|
+
case 7:
|
|
878
861
|
_state.trys.push([
|
|
862
|
+
7,
|
|
879
863
|
9,
|
|
880
|
-
11,
|
|
881
864
|
,
|
|
882
|
-
|
|
865
|
+
10
|
|
883
866
|
]);
|
|
884
867
|
return [
|
|
885
868
|
4,
|
|
886
869
|
liff.getFriendship()
|
|
887
870
|
];
|
|
888
|
-
case
|
|
871
|
+
case 8:
|
|
889
872
|
friendship = _state.sent();
|
|
890
873
|
friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
|
|
891
874
|
setFriendship(friendFlag);
|
|
@@ -893,16 +876,16 @@ var LiffProvider = function(param) {
|
|
|
893
876
|
console.log("isFriendship", friendFlag);
|
|
894
877
|
return [
|
|
895
878
|
3,
|
|
896
|
-
|
|
879
|
+
10
|
|
897
880
|
];
|
|
898
|
-
case
|
|
881
|
+
case 9:
|
|
899
882
|
error = _state.sent();
|
|
900
883
|
console.error("Error in liff.getFriendship():", error);
|
|
901
884
|
return [
|
|
902
885
|
3,
|
|
903
|
-
|
|
886
|
+
10
|
|
904
887
|
];
|
|
905
|
-
case
|
|
888
|
+
case 10:
|
|
906
889
|
console.log("isValid", isValid);
|
|
907
890
|
if (tempFriendship && isValid) return [
|
|
908
891
|
2
|
|
@@ -911,23 +894,23 @@ var LiffProvider = function(param) {
|
|
|
911
894
|
4,
|
|
912
895
|
loginInit(lineToken)
|
|
913
896
|
];
|
|
914
|
-
case
|
|
897
|
+
case 11:
|
|
915
898
|
_state.sent();
|
|
916
|
-
_state.label =
|
|
917
|
-
case
|
|
899
|
+
_state.label = 12;
|
|
900
|
+
case 12:
|
|
918
901
|
return [
|
|
919
902
|
3,
|
|
920
|
-
|
|
903
|
+
14
|
|
921
904
|
];
|
|
922
|
-
case
|
|
905
|
+
case 13:
|
|
923
906
|
err = _state.sent();
|
|
924
907
|
setLiffError(err.toString());
|
|
925
908
|
console.log("LIFF init failed.", err);
|
|
926
909
|
return [
|
|
927
910
|
3,
|
|
928
|
-
|
|
911
|
+
14
|
|
929
912
|
];
|
|
930
|
-
case
|
|
913
|
+
case 14:
|
|
931
914
|
return [
|
|
932
915
|
2
|
|
933
916
|
];
|
|
@@ -1194,6 +1177,56 @@ var LiffProvider = function(param) {
|
|
|
1194
1177
|
var contextValue = useMemo(function() {
|
|
1195
1178
|
return {
|
|
1196
1179
|
liffObject: liffObject,
|
|
1180
|
+
// 為相容性保留 liffObject,另提供 liff 屬性(直接暴露 SDK 物件)
|
|
1181
|
+
liff: liffObject,
|
|
1182
|
+
// 非同步取得 LIFF SDK 的 helper(lazy-load),使用時可以呼叫 `await getLiff()`
|
|
1183
|
+
getLiff: /*#__PURE__*/ _async_to_generator(function() {
|
|
1184
|
+
var mod, sdk, e;
|
|
1185
|
+
return _ts_generator(this, function(_state) {
|
|
1186
|
+
switch(_state.label){
|
|
1187
|
+
case 0:
|
|
1188
|
+
if (liffObject) return [
|
|
1189
|
+
2,
|
|
1190
|
+
liffObject
|
|
1191
|
+
];
|
|
1192
|
+
if (typeof window === "undefined") return [
|
|
1193
|
+
2,
|
|
1194
|
+
null
|
|
1195
|
+
];
|
|
1196
|
+
_state.label = 1;
|
|
1197
|
+
case 1:
|
|
1198
|
+
_state.trys.push([
|
|
1199
|
+
1,
|
|
1200
|
+
3,
|
|
1201
|
+
,
|
|
1202
|
+
4
|
|
1203
|
+
]);
|
|
1204
|
+
return [
|
|
1205
|
+
4,
|
|
1206
|
+
import('./index.esm3.js')
|
|
1207
|
+
];
|
|
1208
|
+
case 2:
|
|
1209
|
+
mod = _state.sent();
|
|
1210
|
+
sdk = mod === null || mod === void 0 ? void 0 : mod.liff;
|
|
1211
|
+
if (sdk) setLiffObject(sdk);
|
|
1212
|
+
return [
|
|
1213
|
+
2,
|
|
1214
|
+
sdk || null
|
|
1215
|
+
];
|
|
1216
|
+
case 3:
|
|
1217
|
+
e = _state.sent();
|
|
1218
|
+
console.error("lazy import @line/liff failed", e);
|
|
1219
|
+
return [
|
|
1220
|
+
2,
|
|
1221
|
+
null
|
|
1222
|
+
];
|
|
1223
|
+
case 4:
|
|
1224
|
+
return [
|
|
1225
|
+
2
|
|
1226
|
+
];
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
}),
|
|
1197
1230
|
loginData: loginData,
|
|
1198
1231
|
userInfo: userInfo,
|
|
1199
1232
|
accessToken: accessToken,
|
package/package.json
CHANGED