@servicetitan/anvil2-ext-common 0.4.0 → 0.5.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/CHANGELOG.md +22 -0
- package/dist/Suggestions-ChGGcGuO.js +47 -0
- package/dist/Suggestions-ChGGcGuO.js.map +1 -0
- package/dist/Suggestions.d.ts +1 -0
- package/dist/Suggestions.js +2 -0
- package/dist/Suggestions.js.map +1 -0
- package/dist/index.js +8 -35313
- package/dist/index.js.map +1 -1
- package/dist/src/components/Suggestions/Suggestions.d.ts +59 -0
- package/dist/src/components/Suggestions/index.d.ts +2 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/form/components/FormMultiSelect/FormMultiSelect.d.ts +1 -1
- package/dist/src/form/components/FormSelect/FormSelect.d.ts +1 -1
- package/package.json +5 -4
- package/dist/index.css +0 -2911
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type Handler = (...args: any[]) => void;
|
|
3
|
+
type Handlers = Record<string, Handler | undefined>;
|
|
4
|
+
export interface SuggestionsApi {
|
|
5
|
+
/**
|
|
6
|
+
* Props for a field that should be highlighted while it holds a suggested
|
|
7
|
+
* value. Returns `isHighlighted` plus copies of any handlers you pass, each
|
|
8
|
+
* wrapped to clear the highlight on the first user edit. Pass the handler
|
|
9
|
+
* under the field's own prop name (`onChange`, `onSelectedOptionChange`, ...).
|
|
10
|
+
*
|
|
11
|
+
* @example <TextField {...suggestable("city", { onChange: setCity })} />
|
|
12
|
+
*/
|
|
13
|
+
suggestable: <O extends Handlers>(key: string, handlers?: O) => {
|
|
14
|
+
isHighlighted: boolean;
|
|
15
|
+
} & O;
|
|
16
|
+
/**
|
|
17
|
+
* Props for the field whose selection populates the others. Returns copies of
|
|
18
|
+
* the handlers you pass, each wrapped to first mark the suggestable fields as
|
|
19
|
+
* highlighted. Your handler still does the value population.
|
|
20
|
+
*
|
|
21
|
+
* @param keys which fields to highlight; defaults to every registered key.
|
|
22
|
+
* @example <TypeaheadTextField {...suggestor({ onSelectOption: apply })} />
|
|
23
|
+
*/
|
|
24
|
+
suggestor: <O extends Handlers>(handlers?: O, keys?: string[]) => O;
|
|
25
|
+
/** Imperatively highlight fields (defaults to every registered key). */
|
|
26
|
+
markSuggested: (keys?: string[]) => void;
|
|
27
|
+
/** Imperatively clear a field's highlight. */
|
|
28
|
+
clearHighlight: (key: string) => void;
|
|
29
|
+
/** Whether a field is currently holding a suggested value. */
|
|
30
|
+
isHighlighted: (key: string) => boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface SuggestionsProps {
|
|
33
|
+
children: (api: SuggestionsApi) => ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Coordinates the "highlight fields populated by a suggestion until edited"
|
|
37
|
+
* behavior for a group of fields, without per-field state wiring.
|
|
38
|
+
*
|
|
39
|
+
* Relies on the fact that a controlled field's change handler fires only on
|
|
40
|
+
* user input, never when its `value` prop changes programmatically — so we
|
|
41
|
+
* track provenance per field rather than comparing values. A field stays
|
|
42
|
+
* un-highlighted after an edit even if the suggested value is re-entered,
|
|
43
|
+
* because typing still fires the handler.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* <Suggestions>
|
|
47
|
+
* {({ suggestor, suggestable }) => (
|
|
48
|
+
* <>
|
|
49
|
+
* <TypeaheadTextField
|
|
50
|
+
* {...suggestor({ onSelectOption: (opt) => applyAddress(opt.value) })}
|
|
51
|
+
* loadOptions={lookupAddresses}
|
|
52
|
+
* />
|
|
53
|
+
* <TextField {...suggestable("city", { onChange: handleCity })} />
|
|
54
|
+
* </>
|
|
55
|
+
* )}
|
|
56
|
+
* </Suggestions>
|
|
57
|
+
*/
|
|
58
|
+
export declare function Suggestions({ children }: SuggestionsProps): import("react/jsx-runtime").JSX.Element;
|
|
59
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MultiSelectFieldOption, MultiSelectFieldProps } from '@servicetitan/anvil2
|
|
1
|
+
import { MultiSelectFieldOption, MultiSelectFieldProps } from '@servicetitan/anvil2';
|
|
2
2
|
import { A2InputFieldState, DistributiveOmit } from '../../state';
|
|
3
3
|
/**
|
|
4
4
|
* FormMultiSelect wraps the beta MultiSelectField and binds it to an
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SelectFieldOption, SelectFieldProps } from '@servicetitan/anvil2
|
|
1
|
+
import { SelectFieldOption, SelectFieldProps } from '@servicetitan/anvil2';
|
|
2
2
|
import { A2InputFieldState, DistributiveOmit } from '../../state';
|
|
3
3
|
/**
|
|
4
4
|
* FormSelect wraps the beta SelectField and binds it to an A2InputFieldState.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/anvil2-ext-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"classnames": "^2.5.1",
|
|
31
31
|
"tabbable": "^6.2.0",
|
|
32
32
|
"tinycolor2": "^1.6.0",
|
|
33
|
-
"uuid": "^14.0.0"
|
|
34
|
-
"@servicetitan/anvil2": "3.1.0"
|
|
33
|
+
"uuid": "^14.0.0"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
36
|
+
"@servicetitan/anvil2": "^3.3.0",
|
|
37
37
|
"@types/react": "^18 || ^19",
|
|
38
38
|
"@types/react-dom": "^18 || ^19",
|
|
39
39
|
"formstate": "^2.1.0",
|
|
@@ -83,7 +83,8 @@
|
|
|
83
83
|
"unified": "^11.0.5",
|
|
84
84
|
"vite": "6.4.2",
|
|
85
85
|
"vitest": "^3.2.4",
|
|
86
|
-
"vitest-axe": "^0.1.0"
|
|
86
|
+
"vitest-axe": "^0.1.0",
|
|
87
|
+
"@servicetitan/anvil2": "3.3.0"
|
|
87
88
|
},
|
|
88
89
|
"scripts": {
|
|
89
90
|
"dev": "vite",
|