@machinemetrics/mm-react-tools 5.2.3 → 5.3.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/README.md +23 -1
- package/dist/MMProvider.d.ts.map +1 -1
- package/dist/hooks.d.ts +2 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/mm-react-tools.es.js +3378 -3359
- package/dist/settings.d.ts +130 -0
- package/dist/settings.d.ts.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export declare const DATE_RANGE_PRESETS: readonly ["today", "yesterday", "last7Days", "last30Days", "last90Days", "lastWeek", "last2Weeks", "lastMonth", "lastYear", "weekToDate", "monthToDate", "quarterToDate", "yearToDate"];
|
|
2
|
+
export type DateRangePreset = (typeof DATE_RANGE_PRESETS)[number];
|
|
3
|
+
/** Offered by the host when a dateRange setting has no `options`. */
|
|
4
|
+
export declare const DEFAULT_DATE_RANGE_PRESETS: readonly ["today", "yesterday", "last7Days", "last30Days", "weekToDate", "monthToDate"];
|
|
5
|
+
/**
|
|
6
|
+
* `start` and `end` are ISO instants on shop-day boundaries; `end` is
|
|
7
|
+
* exclusive. `startDay` and `endDay` are inclusive shop-day dates
|
|
8
|
+
* (yyyy-MM-dd) in the company's time zone.
|
|
9
|
+
*/
|
|
10
|
+
export interface DateRangeValue {
|
|
11
|
+
preset: DateRangePreset;
|
|
12
|
+
start: string;
|
|
13
|
+
end: string;
|
|
14
|
+
startDay: string;
|
|
15
|
+
endDay: string;
|
|
16
|
+
}
|
|
17
|
+
/** Valid: `true`, `null` or nothing. Invalid: the message, as a string or `{ message }`. */
|
|
18
|
+
export type MMAppSettingValidateResult = true | string | {
|
|
19
|
+
message: string;
|
|
20
|
+
} | null | undefined | void;
|
|
21
|
+
export interface MMAppSettingOption {
|
|
22
|
+
label: string;
|
|
23
|
+
value: unknown;
|
|
24
|
+
}
|
|
25
|
+
export type MMAppSettingOptions = readonly MMAppSettingOption[] | ((args: {
|
|
26
|
+
filter?: string;
|
|
27
|
+
}) => readonly MMAppSettingOption[] | Promise<readonly MMAppSettingOption[]>);
|
|
28
|
+
interface MMAppSettingBase {
|
|
29
|
+
label?: string;
|
|
30
|
+
isRequired?: boolean;
|
|
31
|
+
helperText?: string;
|
|
32
|
+
visible?: boolean;
|
|
33
|
+
default?: unknown;
|
|
34
|
+
validate?: (args: {
|
|
35
|
+
value: any;
|
|
36
|
+
}) => MMAppSettingValidateResult | Promise<MMAppSettingValidateResult>;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface MMAppInputSetting extends MMAppSettingBase {
|
|
40
|
+
type: 'input';
|
|
41
|
+
default?: string | number;
|
|
42
|
+
}
|
|
43
|
+
export interface MMAppSelectSetting extends MMAppSettingBase {
|
|
44
|
+
type: 'select';
|
|
45
|
+
options?: MMAppSettingOptions;
|
|
46
|
+
isMulti?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface MMAppRadioSetting extends MMAppSettingBase {
|
|
49
|
+
type: 'radio';
|
|
50
|
+
options?: MMAppSettingOptions;
|
|
51
|
+
}
|
|
52
|
+
export interface MMAppThresholdField {
|
|
53
|
+
name: string;
|
|
54
|
+
label: string;
|
|
55
|
+
color?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
value?: number;
|
|
58
|
+
min?: number;
|
|
59
|
+
max?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface MMAppThresholdsSetting extends MMAppSettingBase {
|
|
62
|
+
type: 'thresholds';
|
|
63
|
+
fields: MMAppThresholdField[];
|
|
64
|
+
}
|
|
65
|
+
export interface MMAppCustomSetting extends MMAppSettingBase {
|
|
66
|
+
type: 'custom';
|
|
67
|
+
url: string;
|
|
68
|
+
isMulti?: boolean;
|
|
69
|
+
drawerTitle?: string;
|
|
70
|
+
emptyLabel?: string;
|
|
71
|
+
}
|
|
72
|
+
/** The host resolves the chosen preset and delivers a {@link DateRangeValue}. */
|
|
73
|
+
export interface MMAppDateRangeSetting extends MMAppSettingBase {
|
|
74
|
+
type: 'dateRange';
|
|
75
|
+
options?: readonly DateRangePreset[];
|
|
76
|
+
default?: DateRangePreset;
|
|
77
|
+
acceptGlobalOverride?: 'dateRange';
|
|
78
|
+
}
|
|
79
|
+
export type MMAppSettingConfig = MMAppInputSetting | MMAppSelectSetting | MMAppRadioSetting | MMAppThresholdsSetting | MMAppCustomSetting | MMAppDateRangeSetting;
|
|
80
|
+
/**
|
|
81
|
+
* What `useMMAppSetting` accepts for any type but `dateRange`: any config, as
|
|
82
|
+
* before 5.3.0. The other `MMApp*Setting` types document the shapes hosts
|
|
83
|
+
* read, without enforcing them.
|
|
84
|
+
*
|
|
85
|
+
* @internal Exported only so a consumer's declarations can name the hook's
|
|
86
|
+
* signature.
|
|
87
|
+
*/
|
|
88
|
+
export interface MMAppLooseSetting {
|
|
89
|
+
type?: string | null | undefined;
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The part of every config read before its `type` is known: the `type` itself
|
|
94
|
+
* and the callbacks, so their parameters are typed whatever the setting.
|
|
95
|
+
*
|
|
96
|
+
* @internal Exported only so a consumer's declarations can name the hook's
|
|
97
|
+
* signature.
|
|
98
|
+
*/
|
|
99
|
+
export interface MMAppSettingCallbacks<T extends string> {
|
|
100
|
+
type?: T | null | undefined;
|
|
101
|
+
options?: readonly any[] | ((args: {
|
|
102
|
+
filter?: string;
|
|
103
|
+
}) => any) | null | false | undefined;
|
|
104
|
+
validate?: ((args: {
|
|
105
|
+
value: any;
|
|
106
|
+
}) => any) | null | false | undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The config `useMMAppSetting` checks for a given `type`.
|
|
110
|
+
*
|
|
111
|
+
* @internal Exported only so a consumer's declarations can name the hook's
|
|
112
|
+
* signature.
|
|
113
|
+
*/
|
|
114
|
+
export type MMAppSettingConfigFor<T extends string> = T extends 'dateRange' ? MMAppDateRangeDeclaration : MMAppLooseSetting;
|
|
115
|
+
/**
|
|
116
|
+
* {@link MMAppDateRangeSetting} without the open index signature, so a
|
|
117
|
+
* misspelled option is caught.
|
|
118
|
+
*/
|
|
119
|
+
export interface MMAppDateRangeDeclaration {
|
|
120
|
+
type: 'dateRange';
|
|
121
|
+
label?: string | undefined;
|
|
122
|
+
isRequired?: boolean | undefined;
|
|
123
|
+
helperText?: string | undefined;
|
|
124
|
+
visible?: boolean | undefined;
|
|
125
|
+
options?: readonly DateRangePreset[] | undefined;
|
|
126
|
+
default?: DateRangePreset | undefined;
|
|
127
|
+
acceptGlobalOverride?: 'dateRange' | undefined;
|
|
128
|
+
}
|
|
129
|
+
export {};
|
|
130
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,yLAcpB,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,qEAAqE;AACrE,eAAO,MAAM,0BAA0B,yFAOS,CAAC;AAEjD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4FAA4F;AAC5F,MAAM,MAAM,0BAA0B,GAClC,IAAI,GACJ,MAAM,GACN;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GACnB,IAAI,GACJ,SAAS,GACT,IAAI,CAAC;AAET,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,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CAAC,GAAG,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;CACvE;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,WAAW,GACvE,yBAAyB,GACzB,iBAAiB,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,CAAC;IACjD,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;IACtC,oBAAoB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@machinemetrics/mm-react-tools",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Components, hooks, and helper functions for writing React apps using MachineMetrics APIs.",
|
|
5
5
|
"author": "machinemetrics",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"test:coverage": "vitest run --coverage",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
29
|
"type-check": "tsc --noEmit",
|
|
30
|
+
"type-check:consumer": "node scripts/check-consumer-types.mjs",
|
|
30
31
|
"lint": "eslint . --color --max-warnings 19",
|
|
31
32
|
"lint:fix": "eslint --max-warnings 19 . --color --fix",
|
|
32
33
|
"prettier": "prettier --list-different '{*.(js|ts),**/*.(js|ts)}'",
|