@dartcom/ui-kit 10.3.0 → 10.3.1

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/dist/index.cjs CHANGED
@@ -16471,7 +16471,7 @@ const encodeString = (string) => {
16471
16471
  return encoded;
16472
16472
  };
16473
16473
  const getUrlencodedBody = (body) => {
16474
- const urlencodedBody = Object.keys(body).reduce((request, key, index) => `${request}${index === 0 ? '' : '&'}${key}=${body[key]}`, '');
16474
+ const urlencodedBody = new URLSearchParams(Object.entries(body).map(([key, value]) => [key, String(value)])).toString();
16475
16475
  return urlencodedBody;
16476
16476
  };
16477
16477
  const showSnackbar = ({ variant, message, }) => {
@@ -16534,6 +16534,27 @@ const getImageSrc = (path) => {
16534
16534
  const imageSrc = `${"$VITE_API_HOST/api-image/images"}/${path}`;
16535
16535
  return imageSrc;
16536
16536
  };
16537
+ const loadState = (name) => {
16538
+ try {
16539
+ const serializedState = localStorage.getItem(name);
16540
+ return serializedState ? JSON.parse(serializedState) : null;
16541
+ }
16542
+ catch {
16543
+ return null;
16544
+ }
16545
+ };
16546
+ const saveState = (name, state) => {
16547
+ try {
16548
+ const serializedState = JSON.stringify(state);
16549
+ localStorage.setItem(name, serializedState);
16550
+ }
16551
+ catch {
16552
+ return;
16553
+ }
16554
+ };
16555
+ const removeState = (name) => {
16556
+ localStorage.removeItem(name);
16557
+ };
16537
16558
 
16538
16559
  var niceErrors = {
16539
16560
  0: "Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'",
@@ -17833,6 +17854,14 @@ function _endAction(runInfo) {
17833
17854
  }
17834
17855
  globalState.suppressReactionErrors = false;
17835
17856
  }
17857
+ function allowStateChanges(allowStateChanges, func) {
17858
+ var prev = allowStateChangesStart(allowStateChanges);
17859
+ try {
17860
+ return func();
17861
+ } finally {
17862
+ allowStateChangesEnd(prev);
17863
+ }
17864
+ }
17836
17865
  function allowStateChangesStart(allowStateChanges) {
17837
17866
  var prev = globalState.allowStateChanges;
17838
17867
  globalState.allowStateChanges = allowStateChanges;
@@ -19298,6 +19327,70 @@ function createSchedulerFromOptions(opts) {
19298
19327
  return setTimeout(f, opts.delay);
19299
19328
  } : run;
19300
19329
  }
19330
+ function reaction(expression, effect, opts) {
19331
+ var _opts$name2, _opts4, _opts5;
19332
+ if (opts === void 0) {
19333
+ opts = EMPTY_OBJECT;
19334
+ }
19335
+ if (process.env.NODE_ENV !== "production") {
19336
+ if (!isFunction$1(expression) || !isFunction$1(effect)) {
19337
+ die("First and second argument to reaction should be functions");
19338
+ }
19339
+ if (!isPlainObject$2(opts)) {
19340
+ die("Third argument of reactions should be an object");
19341
+ }
19342
+ }
19343
+ var name = (_opts$name2 = opts.name) != null ? _opts$name2 : process.env.NODE_ENV !== "production" ? "Reaction@" + getNextId() : "Reaction";
19344
+ var effectAction = action(name, opts.onError ? wrapErrorHandler(opts.onError, effect) : effect);
19345
+ var runSync = !opts.scheduler && !opts.delay;
19346
+ var scheduler = createSchedulerFromOptions(opts);
19347
+ var firstTime = true;
19348
+ var isScheduled = false;
19349
+ var value;
19350
+ var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
19351
+ var r = new Reaction(name, function () {
19352
+ if (firstTime || runSync) {
19353
+ reactionRunner();
19354
+ } else if (!isScheduled) {
19355
+ isScheduled = true;
19356
+ scheduler(reactionRunner);
19357
+ }
19358
+ }, opts.onError, opts.requiresObservable);
19359
+ function reactionRunner() {
19360
+ isScheduled = false;
19361
+ if (r.isDisposed) {
19362
+ return;
19363
+ }
19364
+ var changed = false;
19365
+ var oldValue = value;
19366
+ r.track(function () {
19367
+ var nextValue = allowStateChanges(false, function () {
19368
+ return expression(r);
19369
+ });
19370
+ changed = firstTime || !equals(value, nextValue);
19371
+ value = nextValue;
19372
+ });
19373
+ if (firstTime && opts.fireImmediately) {
19374
+ effectAction(value, oldValue, r);
19375
+ } else if (!firstTime && changed) {
19376
+ effectAction(value, oldValue, r);
19377
+ }
19378
+ firstTime = false;
19379
+ }
19380
+ if (!((_opts4 = opts) != null && (_opts4 = _opts4.signal) != null && _opts4.aborted)) {
19381
+ r.schedule_();
19382
+ }
19383
+ return r.getDisposer_((_opts5 = opts) == null ? void 0 : _opts5.signal);
19384
+ }
19385
+ function wrapErrorHandler(errorHandler, baseFn) {
19386
+ return function () {
19387
+ try {
19388
+ return baseFn.apply(this, arguments);
19389
+ } catch (e) {
19390
+ errorHandler.call(this, e);
19391
+ }
19392
+ };
19393
+ }
19301
19394
 
19302
19395
  var ON_BECOME_OBSERVED = "onBO";
19303
19396
  var ON_BECOME_UNOBSERVED = "onBUO";
@@ -21990,6 +22083,12 @@ const alertStore = new AlertStore();
21990
22083
  class AuthStore {
21991
22084
  constructor() {
21992
22085
  makeAutoObservable(this);
22086
+ reaction(() => this.isUnauthorized, (value) => {
22087
+ if (value) {
22088
+ removeState('access_token');
22089
+ removeState('token_type');
22090
+ }
22091
+ });
21993
22092
  }
21994
22093
  _isUnauthorized = false;
21995
22094
  get isUnauthorized() {
@@ -22053,10 +22152,14 @@ class ApiService {
22053
22152
  this.setupInterceptors();
22054
22153
  }
22055
22154
  setupInterceptors() {
22056
- // Interceptor для запросов
22057
22155
  this.client.interceptors.request.use((config) => {
22058
22156
  rootStore.authStore.isUnauthorized = false;
22059
22157
  const headers = this.config?.getHeaders?.();
22158
+ const access_token = loadState('access_token');
22159
+ const token_type = loadState('token_type');
22160
+ if (access_token && token_type) {
22161
+ config.headers['Authorization'] = `${token_type} ${access_token}`;
22162
+ }
22060
22163
  if (headers) {
22061
22164
  Object.entries(headers).forEach(([key, value]) => {
22062
22165
  config.headers[key] = value;
@@ -22070,7 +22173,6 @@ class ApiService {
22070
22173
  });
22071
22174
  return Promise.reject(error);
22072
22175
  });
22073
- // Interceptor для ответов с обработкой ошибок
22074
22176
  this.client.interceptors.response.use((response) => response, (error) => {
22075
22177
  showSnackbar({
22076
22178
  message: error.message,
@@ -24962,20 +25064,28 @@ function useMutation(options, queryClient) {
24962
25064
  }
24963
25065
 
24964
25066
  const useGetUser = () => {
24965
- return useQuery({
25067
+ const query = useQuery({
24966
25068
  queryKey: ['user'],
24967
25069
  queryFn: async () => {
24968
25070
  const response = await GlobalConfig.instance.apiService.get({
24969
25071
  url: `user/`,
24970
- config: {
24971
- // TODO Заглушка
24972
- baseURL: 'http://89.108.118.23:2292',
24973
- },
24974
25072
  });
24975
25073
  return response;
24976
25074
  },
24977
- staleTime: 5 * 60 * 1000,
24978
25075
  });
25076
+ return query;
25077
+ };
25078
+ const useLazyGetUser = () => {
25079
+ const mutation = useMutation({
25080
+ mutationKey: ['user'],
25081
+ mutationFn: async () => {
25082
+ const response = await GlobalConfig.instance.apiService.get({
25083
+ url: `user/`,
25084
+ });
25085
+ return response;
25086
+ },
25087
+ });
25088
+ return mutation;
24979
25089
  };
24980
25090
 
24981
25091
  const useShowSnackbar = () => {
@@ -25029,7 +25139,6 @@ const useSignIn = () => {
25029
25139
  url: 'token',
25030
25140
  body,
25031
25141
  config: {
25032
- withCredentials: true,
25033
25142
  headers: {
25034
25143
  'Content-Type': 'application/x-www-form-urlencoded',
25035
25144
  },
@@ -25037,6 +25146,10 @@ const useSignIn = () => {
25037
25146
  });
25038
25147
  return response;
25039
25148
  },
25149
+ onSuccess: ({ access_token, token_type }) => {
25150
+ saveState('access_token', access_token);
25151
+ saveState('token_type', token_type);
25152
+ },
25040
25153
  });
25041
25154
  return mutation;
25042
25155
  };
@@ -48024,6 +48137,7 @@ exports.getUrlencodedBody = getUrlencodedBody;
48024
48137
  exports.getValidLayer = getValidLayer;
48025
48138
  exports.getWaterAreaLayers = getWaterAreaLayers;
48026
48139
  exports.getWaterLinkLayers = getWaterLinkLayers;
48140
+ exports.loadState = loadState;
48027
48141
  exports.loggerService = loggerService;
48028
48142
  exports.modalStore = modalStore;
48029
48143
  exports.modalStyle = modalStyle;
@@ -48032,7 +48146,9 @@ exports.numberSchema = numberSchema;
48032
48146
  exports.parseTrafficSignCSVFile = parseTrafficSignCSVFile;
48033
48147
  exports.pillarConfig = pillarConfig;
48034
48148
  exports.queryClient = queryClient;
48149
+ exports.removeState = removeState;
48035
48150
  exports.rootStore = rootStore;
48151
+ exports.saveState = saveState;
48036
48152
  exports.showSnackbar = showSnackbar;
48037
48153
  exports.sourceUrl = sourceUrl;
48038
48154
  exports.text_source = text_source;
@@ -48044,6 +48160,7 @@ exports.trafficSignsDop = trafficSignsDop;
48044
48160
  exports.useFormContext = useFormContext;
48045
48161
  exports.useGetLeafletLayer = useGetLeafletLayer;
48046
48162
  exports.useGetUser = useGetUser;
48163
+ exports.useLazyGetUser = useLazyGetUser;
48047
48164
  exports.useShowErrorSnackbar = useShowErrorSnackbar;
48048
48165
  exports.useShowSnackbar = useShowSnackbar;
48049
48166
  exports.useSignIn = useSignIn;