@mtes-mct/monitor-ui 8.4.0 → 8.5.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtes-mct/monitor-ui",
3
3
  "description": "Common React UI components and styles for Monitorfish and Monitorenv.",
4
- "version": "8.4.0",
4
+ "version": "8.5.0",
5
5
  "license": "AGPL-3.0",
6
6
  "engines": {
7
7
  "node": ">=18"
package/src/index.d.ts CHANGED
@@ -65,13 +65,20 @@ export { CustomSearch } from './libs/CustomSearch';
65
65
  export { customDayjs } from './utils/customDayjs';
66
66
  export { getCoordinates, coordinatesAreDistinct } from './utils/coordinates';
67
67
  export { getLocalizedDayjs } from './utils/getLocalizedDayjs';
68
+ export { getOptionsFromIdAndName } from './utils/getOptionsFromIdAndName';
69
+ export { getOptionsFromLabelledEnum } from './utils/getOptionsFromLabelledEnum';
68
70
  export { getPseudoRandomString } from './utils/getPseudoRandomString';
69
71
  export { getUtcizedDayjs } from './utils/getUtcizedDayjs';
72
+ export { isArray } from './utils/isArray';
73
+ export { isDefined } from './utils/isDefined';
70
74
  export { isNumeric } from './utils/isNumeric';
75
+ export { isObject } from './utils/isObject';
71
76
  export { logSoftError } from './utils/logSoftError';
77
+ export { nullify } from './utils/nullify';
72
78
  export { stopMouseEventPropagation } from './utils/stopMouseEventPropagation';
79
+ export { undefine } from './utils/undefine';
73
80
  export type { PartialTheme, Theme } from './theme';
74
- export type { Coordinates, DateAsStringRange, DateRange, Defined, IconProps, Option, OptionValueType, Undefine } from './types';
81
+ export type { Coordinates, DateAsStringRange, DateRange, Defined, IconProps, Option, OptionValueType, Undefine, UndefineExceptArrays } from './types';
75
82
  export type { DialogProps } from './components/Dialog';
76
83
  export type { DropdownProps, DropdownItemProps } from './components/Dropdown';
77
84
  export type { NewWindowProps } from './components/NewWindow';
package/src/types.d.ts CHANGED
@@ -66,6 +66,40 @@ export type Define<T> = {
66
66
  export type Undefine<T> = {
67
67
  [K in keyof T]: T[K] | undefined;
68
68
  };
69
+ /**
70
+ * Mark all the prop types of an interface/type as `prop: <MyType> | undefined` while preserving array props.
71
+ *
72
+ * @description
73
+ * When `exactOptionalPropertyTypes` is enabled in tsconfig.json,
74
+ * this is useful to create objects allowing undefined prop values while keeping all their props required.
75
+ *
76
+ * Opposite of `Defined`.
77
+ *
78
+ * @example
79
+ * ```
80
+ * type MyType {
81
+ * aRequiredProp: string
82
+ * anOptionalProp?: string
83
+ * anArrayProp: number[]
84
+ * }
85
+ *
86
+ * // `type MyPartialType = UndefineExceptArrays<MyType>` is the same as typing:
87
+ * type MyPartialType {
88
+ * aRequiredProp: string | undefined
89
+ * anOptionalProp?: string | undefined
90
+ * anArrayProp: number[]
91
+ * }
92
+ * ```
93
+ */
94
+ export type UndefineExceptArrays<T> = {
95
+ [K in keyof T]: T[K] extends (infer U)[] ? U[] : T[K] | undefined;
96
+ };
97
+ export type Native = boolean | null | number | string | undefined;
98
+ export type NativeAny = boolean | NativeArray | NativeObject | null | number | string | undefined;
99
+ export type NativeArray = Array<NativeAny>;
100
+ export type NativeObject = {
101
+ [x: string]: NativeAny;
102
+ } | {};
69
103
  /**
70
104
  * Since Rsuite restricts `value` to `string | number`, we use this proxy type,
71
105
  * allowing us to use conventioned option values that can include objects
@@ -0,0 +1,5 @@
1
+ import type { Option } from '../types';
2
+ export declare function getOptionsFromIdAndName(collection: Array<{
3
+ id: number;
4
+ name: string;
5
+ }> | undefined): Array<Option<number>> | undefined;
@@ -0,0 +1,2 @@
1
+ import type { Option } from '../types';
2
+ export declare function getOptionsFromLabelledEnum(labelledEnum: Record<string, string>): Option[];
@@ -0,0 +1 @@
1
+ export declare function isArray<T>(value: any): value is T[];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Is the value defined and non-null?
3
+ */
4
+ export declare function isDefined<T>(value?: T | null | undefined): value is T;
@@ -0,0 +1,3 @@
1
+ export declare function isObject<T extends {
2
+ [key: string]: any;
3
+ }>(value: any): value is T;
@@ -0,0 +1,14 @@
1
+ import type { NativeAny } from '../types';
2
+ type Nullify<T> = T extends undefined ? null : T extends Array<any> ? {
3
+ [K in keyof T]: T[K] extends (infer U)[] ? Nullify<U>[] : Nullify<T[K]>;
4
+ } : T extends Record<string, any> ? {
5
+ [K in keyof T]: T[K] extends (infer U)[] ? Nullify<U>[] : Nullify<T[K]>;
6
+ } : T;
7
+ /**
8
+ * Transform all `undefined` values into `null` ones in any type of value
9
+ *
10
+ * @description
11
+ * The value must be of native type and only contains native types.
12
+ */
13
+ export declare function nullify<T extends NativeAny>(value: T): Nullify<T> | null;
14
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { NativeAny } from '../types';
2
+ type Undefine<T> = T extends null ? undefined : T extends Array<any> ? {
3
+ [K in keyof T]: T[K] extends (infer U)[] ? Undefine<U>[] : Undefine<T[K]>;
4
+ } : T extends Record<string, any> ? {
5
+ [K in keyof T]: T[K] extends (infer U)[] ? Undefine<U>[] : Undefine<T[K]>;
6
+ } : T;
7
+ /**
8
+ * Transform all `null` values into `undefined` ones in any type of value
9
+ *
10
+ * @description
11
+ * The value must be of native type and only contains native types.
12
+ */
13
+ export declare function undefine<T extends NativeAny>(value: T): Undefine<T> | undefined;
14
+ export {};