@tecsinapse/cortex-react 1.5.1 → 1.5.3

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.
@@ -17,18 +17,21 @@ const SelectMultiCheckAllOptions = ({
17
17
  );
18
18
  const checkAll = React.useCallback(() => {
19
19
  {
20
- let updateSelected = [...currentValue];
20
+ const updateSelected = Array.from(currentValue);
21
21
  if (!isChecked) {
22
- updateSelected = [
23
- .../* @__PURE__ */ new Set([...updateSelected, ...options ?? []])
24
- ];
25
- } else {
26
- const optionKeys = new Set(
27
- options?.map((option2) => keyExtractor(option2))
28
- );
29
- updateSelected = updateSelected.filter(
30
- (item) => !optionKeys.has(keyExtractor(item))
22
+ const notSelected = options?.filter(
23
+ (option2) => !updateSelected.find(
24
+ (it) => keyExtractor(it) === keyExtractor(option2)
25
+ )
31
26
  );
27
+ updateSelected.push(...notSelected ?? []);
28
+ } else {
29
+ const elementsToDelete = updateSelected.map(
30
+ (it) => options?.find((option2) => keyExtractor(option2) === keyExtractor(it))
31
+ ).filter((it) => it);
32
+ elementsToDelete.map((it) => {
33
+ updateSelected.splice(updateSelected.indexOf(it), 1);
34
+ });
32
35
  }
33
36
  onSelect(updateSelected);
34
37
  }
@@ -5,8 +5,11 @@ var sonner = require('sonner');
5
5
  var SnackbarSonner = require('../service/SnackbarSonner.js');
6
6
 
7
7
  const SnackbarContext = React.createContext(null);
8
- const SnackbarProvider = ({ children }) => {
9
- const snackbar = new SnackbarSonner.SnackbarSonner();
8
+ const SnackbarProvider = ({
9
+ children,
10
+ options
11
+ }) => {
12
+ const snackbar = new SnackbarSonner.SnackbarSonner(options);
10
13
  return /* @__PURE__ */ React.createElement(SnackbarContext.Provider, { value: { snackbar } }, children, /* @__PURE__ */ React.createElement(sonner.Toaster, null));
11
14
  };
12
15
  const useSnackbar = () => {
@@ -5,10 +5,14 @@ var sonner = require('sonner');
5
5
  var DefaultSnack = require('../components/Snackbar/DefaultSnack.js');
6
6
 
7
7
  class SnackbarSonner {
8
+ _options;
9
+ constructor(options) {
10
+ this._options = { ...options, duration: options?.duration ?? 5e3 };
11
+ }
8
12
  custom(Component, options) {
9
13
  return sonner.toast.custom(() => Component, {
10
- ...options,
11
- duration: options?.duration ?? 5e3
14
+ ...this._options,
15
+ ...options
12
16
  });
13
17
  }
14
18
  show(type, message, options) {
@@ -23,7 +27,7 @@ class SnackbarSonner {
23
27
  }
24
28
  );
25
29
  },
26
- { ...options, duration: options?.duration ?? 5e3 }
30
+ { ...this._options, ...options }
27
31
  );
28
32
  }
29
33
  }
@@ -15,18 +15,21 @@ const SelectMultiCheckAllOptions = ({
15
15
  );
16
16
  const checkAll = useCallback(() => {
17
17
  {
18
- let updateSelected = [...currentValue];
18
+ const updateSelected = Array.from(currentValue);
19
19
  if (!isChecked) {
20
- updateSelected = [
21
- .../* @__PURE__ */ new Set([...updateSelected, ...options ?? []])
22
- ];
23
- } else {
24
- const optionKeys = new Set(
25
- options?.map((option2) => keyExtractor(option2))
26
- );
27
- updateSelected = updateSelected.filter(
28
- (item) => !optionKeys.has(keyExtractor(item))
20
+ const notSelected = options?.filter(
21
+ (option2) => !updateSelected.find(
22
+ (it) => keyExtractor(it) === keyExtractor(option2)
23
+ )
29
24
  );
25
+ updateSelected.push(...notSelected ?? []);
26
+ } else {
27
+ const elementsToDelete = updateSelected.map(
28
+ (it) => options?.find((option2) => keyExtractor(option2) === keyExtractor(it))
29
+ ).filter((it) => it);
30
+ elementsToDelete.map((it) => {
31
+ updateSelected.splice(updateSelected.indexOf(it), 1);
32
+ });
30
33
  }
31
34
  onSelect(updateSelected);
32
35
  }
@@ -3,8 +3,11 @@ import { Toaster } from 'sonner';
3
3
  import { SnackbarSonner } from '../service/SnackbarSonner.js';
4
4
 
5
5
  const SnackbarContext = createContext(null);
6
- const SnackbarProvider = ({ children }) => {
7
- const snackbar = new SnackbarSonner();
6
+ const SnackbarProvider = ({
7
+ children,
8
+ options
9
+ }) => {
10
+ const snackbar = new SnackbarSonner(options);
8
11
  return /* @__PURE__ */ React__default.createElement(SnackbarContext.Provider, { value: { snackbar } }, children, /* @__PURE__ */ React__default.createElement(Toaster, null));
9
12
  };
10
13
  const useSnackbar = () => {
@@ -3,10 +3,14 @@ import { toast } from 'sonner';
3
3
  import { DefaultSnack } from '../components/Snackbar/DefaultSnack.js';
4
4
 
5
5
  class SnackbarSonner {
6
+ _options;
7
+ constructor(options) {
8
+ this._options = { ...options, duration: options?.duration ?? 5e3 };
9
+ }
6
10
  custom(Component, options) {
7
11
  return toast.custom(() => Component, {
8
- ...options,
9
- duration: options?.duration ?? 5e3
12
+ ...this._options,
13
+ ...options
10
14
  });
11
15
  }
12
16
  show(type, message, options) {
@@ -21,7 +25,7 @@ class SnackbarSonner {
21
25
  }
22
26
  );
23
27
  },
24
- { ...options, duration: options?.duration ?? 5e3 }
28
+ { ...this._options, ...options }
25
29
  );
26
30
  }
27
31
  }
@@ -1,10 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
+ import { type ExternalToast } from 'sonner';
2
3
  import { SnackbarSonner } from '../service/SnackbarSonner';
3
4
  interface SnackbarProviderProps {
4
5
  snackbar: SnackbarSonner;
5
6
  }
6
- export declare const SnackbarProvider: ({ children }: {
7
+ export declare const SnackbarProvider: ({ children, options, }: {
7
8
  children: ReactNode;
9
+ options?: ExternalToast;
8
10
  }) => JSX.Element;
9
11
  export declare const useSnackbar: () => SnackbarProviderProps;
10
12
  export {};
@@ -1,7 +1,8 @@
1
- import { ReactElement } from 'react';
2
1
  import { SnackbarVariants } from '@tecsinapse/cortex-core';
2
+ import { ReactElement } from 'react';
3
3
  export type TypeSnack = SnackbarVariants['intent'];
4
4
  export interface ISnackbar<T> {
5
+ _options?: T;
5
6
  show(type: TypeSnack, message: string, options?: T): any;
6
7
  custom(component: ReactElement, options?: T): any;
7
8
  }
@@ -2,6 +2,8 @@ import React from 'react';
2
2
  import { ExternalToast } from 'sonner';
3
3
  import { ISnackbar, TypeSnack } from './ISnackbar';
4
4
  export declare class SnackbarSonner implements ISnackbar<ExternalToast> {
5
+ _options?: ExternalToast;
6
+ constructor(options?: ExternalToast);
5
7
  custom(Component: React.ReactElement, options?: ExternalToast): string | number;
6
8
  show(type: TypeSnack, message: string, options?: Omit<ExternalToast, 'className' | 'style'>): string | number;
7
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tecsinapse/cortex-react",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "React components based in @tecsinapse/cortex-core",
5
5
  "license": "MIT",
6
6
  "main": "dist/esm/index.js",
@@ -45,5 +45,5 @@
45
45
  "react-dom": ">=18.0.0",
46
46
  "tailwind": ">=3.3.0"
47
47
  },
48
- "gitHead": "cf0f1a6cda80b413d079a13c2545a0b9244d0805"
48
+ "gitHead": "86b8794105cbdf611c6f54784f028cb73f5947b3"
49
49
  }