@sunggang/ui-lib 0.3.16 → 0.3.18

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.
Files changed (2) hide show
  1. package/index.esm2.js +89 -27
  2. package/package.json +1 -1
package/index.esm2.js CHANGED
@@ -69811,6 +69811,57 @@ var LiffProvider = function(param) {
69811
69811
  return _ref.apply(this, arguments);
69812
69812
  };
69813
69813
  }();
69814
+ var ensureLiffTokenValid = useCallback$1(/*#__PURE__*/ _async_to_generator(function() {
69815
+ var err;
69816
+ return _ts_generator(this, function(_state) {
69817
+ switch(_state.label){
69818
+ case 0:
69819
+ _state.trys.push([
69820
+ 0,
69821
+ 2,
69822
+ ,
69823
+ 3
69824
+ ]);
69825
+ // 1. SDK 還沒初始化
69826
+ if (!liffObject) return [
69827
+ 2,
69828
+ false
69829
+ ];
69830
+ // 2. 如果 LIFF 本身判為未登入
69831
+ if (!liffObject.isLoggedIn()) return [
69832
+ 2,
69833
+ false
69834
+ ];
69835
+ // 3. 嘗試用現有的 token 呼叫 getProfile()
69836
+ // 如果 token 過期或無效,這裡會 throw
69837
+ return [
69838
+ 4,
69839
+ liffObject.getProfile()
69840
+ ];
69841
+ case 1:
69842
+ _state.sent();
69843
+ // 4. 都正常,代表 token 仍然有效
69844
+ return [
69845
+ 2,
69846
+ true
69847
+ ];
69848
+ case 2:
69849
+ err = _state.sent();
69850
+ // token 失效或其他問題
69851
+ console.warn("LIFF token 驗證失敗,需重新登入", err);
69852
+ return [
69853
+ 2,
69854
+ false
69855
+ ];
69856
+ case 3:
69857
+ return [
69858
+ 2
69859
+ ];
69860
+ }
69861
+ });
69862
+ }), [
69863
+ liffObject
69864
+ ]);
69814
69865
  // 客戶端初始化 LIFF
69815
69866
  useEffect(function() {
69816
69867
  var checkAndInitialize = function() {
@@ -69877,7 +69928,8 @@ var LiffProvider = function(param) {
69877
69928
  initializeLiff: function() {
69878
69929
  return initializeLiff(false);
69879
69930
  },
69880
- isFriendship: isFriendship
69931
+ isFriendship: isFriendship,
69932
+ ensureLiffTokenValid: ensureLiffTokenValid
69881
69933
  };
69882
69934
  }, [
69883
69935
  liffObject,
@@ -69885,7 +69937,8 @@ var LiffProvider = function(param) {
69885
69937
  userInfo,
69886
69938
  accessToken,
69887
69939
  liffError,
69888
- isFriendship
69940
+ isFriendship,
69941
+ ensureLiffTokenValid
69889
69942
  ]);
69890
69943
  return /*#__PURE__*/ jsx(LiffContext.Provider, {
69891
69944
  value: contextValue,
@@ -77263,8 +77316,7 @@ var TextField = function(param) {
77263
77316
  };
77264
77317
  var SingleSelect = function(param) {
77265
77318
  var item = param.item;
77266
- var _item_option;
77267
- var _useFormContext = useFormContext(), register = _useFormContext.register, errors = _useFormContext.formState.errors;
77319
+ var _useFormContext = useFormContext(), register = _useFormContext.register, control = _useFormContext.control, errors = _useFormContext.formState.errors;
77268
77320
  return /*#__PURE__*/ jsx("div", {
77269
77321
  className: [
77270
77322
  (item === null || item === void 0 ? void 0 : item.className) || "w-full h-24"
@@ -77285,30 +77337,40 @@ var SingleSelect = function(param) {
77285
77337
  color: "6f6f6f"
77286
77338
  })
77287
77339
  }),
77288
- /*#__PURE__*/ jsx("select", _object_spread_props(_object_spread({
77289
- className: [
77290
- (item === null || item === void 0 ? void 0 : item.disable) || (item === null || item === void 0 ? void 0 : item.disabled) ? "text-[#B0B0B0] bg-[#e5e7eb] cursor-not-allowed" : "bg-white text-[#6f6f6f]",
77291
- "customSelect w-full h-11 py-2 pr-4 rounded-lg border border-solid border-gray-300 pl-4"
77292
- ].join(" "),
77293
- style: item.style
77294
- }, register(item.name, _object_spread({}, item === null || item === void 0 ? void 0 : item.validateOption))), {
77295
- id: item === null || item === void 0 ? void 0 : item.id,
77296
- disabled: (item === null || item === void 0 ? void 0 : item.disable) || (item === null || item === void 0 ? void 0 : item.disabled),
77297
- children: item === null || item === void 0 ? void 0 : (_item_option = item.option) === null || _item_option === void 0 ? void 0 : _item_option.map(function(group) {
77298
- return "label" in group ? /*#__PURE__*/ jsx("optgroup", {
77299
- label: group.label,
77300
- children: group.options.map(function(o) {
77301
- return /*#__PURE__*/ jsx("option", {
77302
- value: o.value,
77303
- children: o.name
77304
- }, o.value);
77340
+ /*#__PURE__*/ jsx(Controller$2, {
77341
+ name: item.name,
77342
+ control: control,
77343
+ rules: item.validateOption,
77344
+ render: function(param) {
77345
+ var field = param.field;
77346
+ var _item_option;
77347
+ return /*#__PURE__*/ jsx("select", _object_spread_props(_object_spread(_object_spread_props(_object_spread({
77348
+ className: [
77349
+ (item === null || item === void 0 ? void 0 : item.disable) || (item === null || item === void 0 ? void 0 : item.disabled) ? "text-[#B0B0B0] bg-[#e5e7eb] cursor-not-allowed" : "bg-white text-[#6f6f6f]",
77350
+ "customSelect w-full h-11 py-2 pr-4 rounded-lg border border-solid border-gray-300 pl-4"
77351
+ ].join(" "),
77352
+ style: item.style
77353
+ }, register(item.name, _object_spread({}, item === null || item === void 0 ? void 0 : item.validateOption))), {
77354
+ id: item === null || item === void 0 ? void 0 : item.id,
77355
+ disabled: (item === null || item === void 0 ? void 0 : item.disable) || (item === null || item === void 0 ? void 0 : item.disabled)
77356
+ }), field), {
77357
+ children: item === null || item === void 0 ? void 0 : (_item_option = item.option) === null || _item_option === void 0 ? void 0 : _item_option.map(function(group) {
77358
+ return "label" in group ? /*#__PURE__*/ jsx("optgroup", {
77359
+ label: group.label,
77360
+ children: group.options.map(function(o) {
77361
+ return /*#__PURE__*/ jsx("option", {
77362
+ value: o.value,
77363
+ children: o.name
77364
+ }, o.value);
77365
+ })
77366
+ }, group.label) : /*#__PURE__*/ jsx("option", {
77367
+ value: group.value,
77368
+ children: group.name
77369
+ }, "".concat(group.value, "-").concat(v4()));
77305
77370
  })
77306
- }, group.label) : /*#__PURE__*/ jsx("option", {
77307
- value: group.value,
77308
- children: group.name
77309
- }, "".concat(group.value, "-").concat(v4()));
77310
- })
77311
- })),
77371
+ }));
77372
+ }
77373
+ }),
77312
77374
  validateMsg(errors, item) && /*#__PURE__*/ jsxs("div", {
77313
77375
  className: "text-left pt-1 text-xs text-[#EF5533]",
77314
77376
  children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
4
4
  "dependencies": {
5
5
  "@emotion/react": "^11.14.0",
6
6
  "@emotion/styled": "^11.14.0",