@dr.pogodin/react-utils 1.33.2 → 1.33.4

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 (42) hide show
  1. package/build/development/server/index.js +2 -0
  2. package/build/development/server/index.js.map +1 -1
  3. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  4. package/build/development/shared/components/selectors/CustomDropdown/index.js +1 -1
  5. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  6. package/build/development/shared/components/selectors/NativeDropdown/index.js +1 -1
  7. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  8. package/build/development/shared/components/selectors/Switch/index.js +1 -1
  9. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  10. package/build/development/shared/components/selectors/common.js +11 -6
  11. package/build/development/shared/components/selectors/common.js.map +1 -1
  12. package/build/development/shared/utils/webpack.js +5 -2
  13. package/build/development/shared/utils/webpack.js.map +1 -1
  14. package/build/development/web.bundle.js +5 -5
  15. package/build/production/server/index.js +1 -1
  16. package/build/production/server/index.js.map +1 -1
  17. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  18. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  19. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  20. package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
  21. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  22. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  23. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  24. package/build/production/shared/components/selectors/common.js +2 -2
  25. package/build/production/shared/components/selectors/common.js.map +1 -1
  26. package/build/production/shared/utils/webpack.js +1 -1
  27. package/build/production/shared/utils/webpack.js.map +1 -1
  28. package/build/production/web.bundle.js +1 -1
  29. package/build/production/web.bundle.js.map +1 -1
  30. package/build/types-code/server/index.d.ts +5 -3
  31. package/build/types-code/shared/components/selectors/CustomDropdown/Options/index.d.ts +3 -3
  32. package/build/types-code/shared/components/selectors/CustomDropdown/index.d.ts +2 -2
  33. package/build/types-code/shared/components/selectors/Switch/index.d.ts +3 -3
  34. package/build/types-code/shared/components/selectors/common.d.ts +11 -9
  35. package/package.json +3 -3
  36. package/src/server/index.ts +9 -5
  37. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +3 -2
  38. package/src/shared/components/selectors/CustomDropdown/index.tsx +4 -2
  39. package/src/shared/components/selectors/NativeDropdown/index.tsx +2 -1
  40. package/src/shared/components/selectors/Switch/index.tsx +10 -4
  41. package/src/shared/components/selectors/common.ts +25 -11
  42. package/src/shared/utils/webpack.ts +5 -2
@@ -4,9 +4,9 @@ import 'source-map-support/register';
4
4
  import http from 'http';
5
5
  import 'raf/polyfill';
6
6
  import { type Configuration } from 'webpack';
7
- import { type OptionsT as ServerOptionsT } from './server';
8
- export { getDefaultCspSettings, } from './server';
9
- export { errors } from './utils';
7
+ import { type OptionsT as ServerOptionsT, getDefaultCspSettings } from './server';
8
+ import { errors } from './utils';
9
+ export { errors, getDefaultCspSettings };
10
10
  type OptionsT = ServerOptionsT & {
11
11
  https?: {
12
12
  cert: string;
@@ -141,5 +141,7 @@ declare function launchServer(webpackConfig: Configuration, options: OptionsT):
141
141
  }>;
142
142
  declare namespace launchServer {
143
143
  var SCRIPT_LOCATIONS: typeof import("./renderer").SCRIPT_LOCATIONS;
144
+ var getDefaultCspSettings: typeof import("./server").getDefaultCspSettings;
145
+ var errors: typeof import("./utils/errors");
144
146
  }
145
147
  export default launchServer;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { type OptionT, type OptionsT } from '../../common';
2
+ import { type OptionT, type OptionsT, type ValueT } from '../../common';
3
3
  export type ContainerPosT = {
4
4
  left: number;
5
5
  top: number;
@@ -12,11 +12,11 @@ export type RefT = {
12
12
  type PropsT = {
13
13
  containerClass: string;
14
14
  containerStyle?: ContainerPosT;
15
- filter?: (item: OptionT<React.ReactNode> | string) => boolean;
15
+ filter?: (item: OptionT<React.ReactNode> | ValueT) => boolean;
16
16
  optionClass: string;
17
17
  options: OptionsT<React.ReactNode>;
18
18
  onCancel: () => void;
19
- onChange: (value: string) => void;
19
+ onChange: (value: ValueT) => void;
20
20
  };
21
21
  declare const Options: React.ForwardRefExoticComponent<PropsT & React.RefAttributes<RefT>>;
22
22
  export default Options;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { type PropsT } from '../common';
3
- declare const ThemedCustomDropdown: import("@dr.pogodin/react-themes").ThemedComponent<PropsT<React.ReactNode, (value: string) => void>>;
2
+ import { type PropsT, type ValueT } from '../common';
3
+ declare const ThemedCustomDropdown: import("@dr.pogodin/react-themes").ThemedComponent<PropsT<React.ReactNode, (value: ValueT) => void>>;
4
4
  export default ThemedCustomDropdown;
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
- import { type OptionsT } from '../common';
3
+ import { type OptionsT, type ValueT } from '../common';
4
4
  declare const validThemeKeys: readonly ["container", "label", "option", "options", "selected"];
5
5
  type PropsT = {
6
6
  label?: React.ReactNode;
7
- onChange?: (value: string) => void;
7
+ onChange?: (value: ValueT) => void;
8
8
  options?: Readonly<OptionsT<React.ReactNode>>;
9
9
  theme: Theme<typeof validThemeKeys>;
10
- value?: string;
10
+ value?: ValueT;
11
11
  };
12
12
  declare const ThemedSwitch: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
13
13
  export default ThemedSwitch;
@@ -2,22 +2,24 @@
2
2
  import PT from 'prop-types';
3
3
  import type { Theme } from '@dr.pogodin/react-themes';
4
4
  export declare const validThemeKeys: readonly ["active", "arrow", "container", "dropdown", "hiddenOption", "label", "option", "select", "upward"];
5
+ export type ValueT = number | string;
6
+ export declare const valueValidator: PT.Requireable<ValueT>;
5
7
  export type OptionT<NameT> = {
6
8
  name?: NameT | null;
7
- value: string;
9
+ value: ValueT;
8
10
  };
9
- export type OptionsT<NameT> = Array<OptionT<NameT> | string>;
11
+ export type OptionsT<NameT> = Array<OptionT<NameT> | ValueT>;
10
12
  export type PropsT<NameT, OnChangeT = React.ChangeEventHandler<HTMLSelectElement>> = {
11
- filter?: (item: OptionT<NameT> | string) => boolean;
13
+ filter?: (item: OptionT<NameT> | ValueT) => boolean;
12
14
  label?: React.ReactNode;
13
15
  onChange?: OnChangeT;
14
16
  options?: OptionsT<NameT>;
15
17
  theme: Theme<typeof validThemeKeys>;
16
- value?: string;
18
+ value?: ValueT;
17
19
  };
18
- export declare const optionValidator: PT.Requireable<OptionT<React.ReactNode> | string>;
19
- export declare const optionsValidator: PT.Requireable<NonNullable<string | OptionT<React.ReactNode>>[]>;
20
- export declare const stringOptionValidator: PT.Requireable<OptionT<string> | string>;
21
- export declare const stringOptionsValidator: PT.Requireable<NonNullable<string | OptionT<string>>[]>;
20
+ export declare const optionValidator: PT.Requireable<OptionT<React.ReactNode> | ValueT>;
21
+ export declare const optionsValidator: PT.Requireable<NonNullable<ValueT | OptionT<React.ReactNode>>[]>;
22
+ export declare const stringOptionValidator: PT.Requireable<OptionT<string> | ValueT>;
23
+ export declare const stringOptionsValidator: PT.Requireable<NonNullable<ValueT | OptionT<string>>[]>;
22
24
  /** Returns option value and name as a tuple. */
23
- export declare function optionValueName<NameT>(option: OptionT<NameT> | string): [string, NameT | string];
25
+ export declare function optionValueName<NameT>(option: OptionT<NameT> | ValueT): [ValueT, NameT | ValueT];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.33.2",
2
+ "version": "1.33.4",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -88,7 +88,7 @@
88
88
  "babel-loader": "^9.1.3",
89
89
  "babel-plugin-module-resolver": "^5.0.0",
90
90
  "core-js": "^3.36.1",
91
- "css-loader": "^7.0.0",
91
+ "css-loader": "^7.1.0",
92
92
  "css-minimizer-webpack-plugin": "^6.0.0",
93
93
  "eslint": "^8.57.0",
94
94
  "eslint-config-airbnb": "^19.0.4",
@@ -123,7 +123,7 @@
123
123
  "tsc-alias": "^1.8.8",
124
124
  "typed-scss-modules": "^8.0.1",
125
125
  "typescript": "^5.4.4",
126
- "typescript-eslint": "^7.5.0",
126
+ "typescript-eslint": "^7.6.0",
127
127
  "webpack": "^5.91.0",
128
128
  "webpack-dev-middleware": "^7.2.1",
129
129
  "webpack-hot-middleware": "^2.26.1",
@@ -17,14 +17,16 @@ import 'raf/polyfill';
17
17
 
18
18
  import { type Configuration } from 'webpack';
19
19
 
20
- import serverFactory, { type OptionsT as ServerOptionsT } from './server';
21
- import { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';
22
-
23
- export {
20
+ import serverFactory, {
21
+ type OptionsT as ServerOptionsT,
24
22
  getDefaultCspSettings,
25
23
  } from './server';
26
24
 
27
- export { errors } from './utils';
25
+ import { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';
26
+
27
+ import { errors } from './utils';
28
+
29
+ export { errors, getDefaultCspSettings };
28
30
 
29
31
  /**
30
32
  * Normalizes a port into a number, string, or false.
@@ -228,3 +230,5 @@ export default async function launchServer(webpackConfig: Configuration, options
228
230
  }
229
231
 
230
232
  launchServer.SCRIPT_LOCATIONS = SCRIPT_LOCATIONS;
233
+ launchServer.getDefaultCspSettings = getDefaultCspSettings;
234
+ launchServer.errors = errors;
@@ -8,6 +8,7 @@ import S from './style.scss';
8
8
  import {
9
9
  type OptionT,
10
10
  type OptionsT,
11
+ type ValueT,
11
12
  optionsValidator,
12
13
  optionValueName,
13
14
  } from '../../common';
@@ -29,11 +30,11 @@ export type RefT = {
29
30
  type PropsT = {
30
31
  containerClass: string;
31
32
  containerStyle?: ContainerPosT;
32
- filter?: (item: OptionT<React.ReactNode> | string) => boolean;
33
+ filter?: (item: OptionT<React.ReactNode> | ValueT) => boolean;
33
34
  optionClass: string;
34
35
  options: OptionsT<React.ReactNode>;
35
36
  onCancel: () => void;
36
- onChange: (value: string) => void;
37
+ onChange: (value: ValueT) => void;
37
38
  };
38
39
 
39
40
  const Options = forwardRef<RefT, PropsT>(({
@@ -9,13 +9,15 @@ import defaultTheme from './theme.scss';
9
9
 
10
10
  import {
11
11
  type PropsT,
12
+ type ValueT,
12
13
  optionValidator,
13
14
  optionValueName,
14
15
  validThemeKeys,
16
+ valueValidator,
15
17
  } from '../common';
16
18
 
17
19
  const BaseCustomDropdown: React.FunctionComponent<
18
- PropsT<React.ReactNode, (value: string) => void>
20
+ PropsT<React.ReactNode, (value: ValueT) => void>
19
21
  > = ({
20
22
  filter,
21
23
  label,
@@ -166,7 +168,7 @@ BaseCustomDropdown.propTypes = {
166
168
  onChange: PT.func,
167
169
  options: PT.arrayOf(optionValidator.isRequired),
168
170
  theme: ThemedCustomDropdown.themeType.isRequired,
169
- value: PT.string,
171
+ value: valueValidator,
170
172
  };
171
173
 
172
174
  BaseCustomDropdown.defaultProps = {
@@ -11,6 +11,7 @@ import {
11
11
  optionValueName,
12
12
  stringOptionsValidator,
13
13
  validThemeKeys,
14
+ valueValidator,
14
15
  } from '../common';
15
16
 
16
17
  /**
@@ -104,7 +105,7 @@ Dropdown.propTypes = {
104
105
  onChange: PT.func,
105
106
  options: stringOptionsValidator,
106
107
  theme: ThemedDropdown.themeType.isRequired,
107
- value: PT.string,
108
+ value: valueValidator,
108
109
  };
109
110
 
110
111
  Dropdown.defaultProps = {
@@ -1,7 +1,13 @@
1
1
  import PT from 'prop-types';
2
2
  import themed, { type Theme } from '@dr.pogodin/react-themes';
3
3
 
4
- import { type OptionsT, optionsValidator, optionValueName } from '../common';
4
+ import {
5
+ type OptionsT,
6
+ type ValueT,
7
+ optionsValidator,
8
+ optionValueName,
9
+ valueValidator,
10
+ } from '../common';
5
11
 
6
12
  import defaultTheme from './theme.scss';
7
13
 
@@ -15,10 +21,10 @@ const validThemeKeys = [
15
21
 
16
22
  type PropsT = {
17
23
  label?: React.ReactNode;
18
- onChange?: (value: string) => void;
24
+ onChange?: (value: ValueT) => void;
19
25
  options?: Readonly<OptionsT<React.ReactNode>>;
20
26
  theme: Theme<typeof validThemeKeys>;
21
- value?: string;
27
+ value?: ValueT;
22
28
  };
23
29
 
24
30
  const BaseSwitch: React.FunctionComponent<PropsT> = ({
@@ -81,7 +87,7 @@ BaseSwitch.propTypes = {
81
87
  onChange: PT.func,
82
88
  options: optionsValidator,
83
89
  theme: ThemedSwitch.themeType.isRequired,
84
- value: PT.string,
90
+ value: valueValidator,
85
91
  };
86
92
 
87
93
  BaseSwitch.defaultProps = {
@@ -19,52 +19,66 @@ export const validThemeKeys = [
19
19
  'upward',
20
20
  ] as const;
21
21
 
22
+ export type ValueT = number | string;
23
+
24
+ export const valueValidator: PT.Requireable<ValueT> = PT.oneOfType([
25
+ PT.number.isRequired,
26
+ PT.string.isRequired,
27
+ ]);
28
+
22
29
  export type OptionT<NameT> = {
23
30
  name?: NameT | null;
24
- value: string;
31
+ value: ValueT;
25
32
  };
26
33
 
27
- export type OptionsT<NameT> = Array<OptionT<NameT> | string>;
34
+ export type OptionsT<NameT> = Array<OptionT<NameT> | ValueT>;
28
35
 
29
36
  export type PropsT<
30
37
  NameT,
31
38
  OnChangeT = React.ChangeEventHandler<HTMLSelectElement>,
32
39
  > = {
33
- filter?: (item: OptionT<NameT> | string) => boolean;
40
+ filter?: (item: OptionT<NameT> | ValueT) => boolean;
34
41
  label?: React.ReactNode;
35
42
  onChange?: OnChangeT;
36
43
  options?: OptionsT<NameT>;
37
44
  theme: Theme<typeof validThemeKeys>;
38
- value?: string;
45
+ value?: ValueT;
39
46
  };
40
47
 
41
48
  export const optionValidator:
42
- PT.Requireable<OptionT<React.ReactNode> | string> = PT.oneOfType([
49
+ PT.Requireable<OptionT<React.ReactNode> | ValueT> = PT.oneOfType([
43
50
  PT.shape({
44
51
  name: PT.node,
45
- value: PT.string.isRequired,
52
+ value: valueValidator.isRequired,
46
53
  }).isRequired,
54
+ PT.number.isRequired,
47
55
  PT.string.isRequired,
48
56
  ]);
49
57
 
50
58
  export const optionsValidator = PT.arrayOf(optionValidator.isRequired);
51
59
 
52
60
  export const stringOptionValidator:
53
- PT.Requireable<OptionT<string> | string> = PT.oneOfType([
61
+ PT.Requireable<OptionT<string> | ValueT> = PT.oneOfType([
54
62
  PT.shape({
55
63
  name: PT.string,
56
- value: PT.string.isRequired,
64
+ value: valueValidator.isRequired,
57
65
  }).isRequired,
66
+ PT.number.isRequired,
58
67
  PT.string.isRequired,
59
68
  ]);
60
69
 
61
70
  export const stringOptionsValidator = PT.arrayOf(stringOptionValidator.isRequired);
62
71
 
72
+ function isValue<T>(x: OptionT<T> | ValueT): x is ValueT {
73
+ const type = typeof x;
74
+ return type === 'number' || type === 'string';
75
+ }
76
+
63
77
  /** Returns option value and name as a tuple. */
64
78
  export function optionValueName<NameT>(
65
- option: OptionT<NameT> | string,
66
- ): [string, NameT | string] {
67
- return typeof option === 'string'
79
+ option: OptionT<NameT> | ValueT,
80
+ ): [ValueT, NameT | ValueT] {
81
+ return isValue(option)
68
82
  ? [option, option]
69
83
  : [option.value, option.name ?? option.value];
70
84
  }
@@ -23,8 +23,11 @@ export function requireWeak(
23
23
  if (!def) return named;
24
24
 
25
25
  Object.entries(named).forEach(([key, value]) => {
26
- if (def[key]) throw Error('Conflict between default and named exports');
27
- def[key] = value;
26
+ if (def[key]) {
27
+ if (def[key] !== value) {
28
+ throw Error('Conflict between default and named exports');
29
+ }
30
+ } else def[key] = value;
28
31
  });
29
32
  return def;
30
33
  } catch {