@servicetitan/form-state 31.1.0 → 31.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/dist/async-lazy-dropdown-state/async-lazy-dropdown-state.js +61 -57
- package/dist/async-lazy-dropdown-state/async-lazy-dropdown-state.js.map +1 -1
- package/dist/async-lazy-dropdown-state/index.js +1 -0
- package/dist/async-lazy-dropdown-state/index.js.map +1 -1
- package/dist/async-lazy-dropdown-state/use-async-lazy-dropdown-state.js +23 -13
- package/dist/async-lazy-dropdown-state/use-async-lazy-dropdown-state.js.map +1 -1
- package/dist/date-range.js +2 -1
- package/dist/date-range.js.map +1 -1
- package/dist/demo/dropdown-state.js +284 -60
- package/dist/demo/dropdown-state.js.map +1 -1
- package/dist/demo/index.js +1 -0
- package/dist/demo/index.js.map +1 -1
- package/dist/dropdown-state.js +168 -222
- package/dist/dropdown-state.js.map +1 -1
- package/dist/form-helpers.js +73 -116
- package/dist/form-helpers.js.map +1 -1
- package/dist/form-validators.js +25 -39
- package/dist/form-validators.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/persistent-form-state/domain-storage.js +22 -16
- package/dist/persistent-form-state/domain-storage.js.map +1 -1
- package/dist/persistent-form-state/in-memory-storage.js +14 -5
- package/dist/persistent-form-state/in-memory-storage.js.map +1 -1
- package/dist/persistent-form-state/index.js +1 -0
- package/dist/persistent-form-state/index.js.map +1 -1
- package/dist/persistent-form-state/persistent-form-state.js +40 -71
- package/dist/persistent-form-state/persistent-form-state.js.map +1 -1
- package/package.json +5 -5
- package/dist/__tests__/form-helpers.test.js +0 -263
- package/dist/__tests__/form-helpers.test.js.map +0 -1
- package/dist/__tests__/form-validators.test.js +0 -48
- package/dist/__tests__/form-validators.test.js.map +0 -1
- package/dist/async-lazy-dropdown-state/async-lazy-dropdown-state.stories.js +0 -46
- package/dist/async-lazy-dropdown-state/async-lazy-dropdown-state.stories.js.map +0 -1
- package/dist/persistent-form-state/__tests__/domain-storage.test.js +0 -60
- package/dist/persistent-form-state/__tests__/domain-storage.test.js.map +0 -1
|
@@ -1,80 +1,84 @@
|
|
|
1
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
8
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
22
|
+
}
|
|
10
23
|
import { computed, makeObservable } from 'mobx';
|
|
11
24
|
import { AsyncDataSource } from '@servicetitan/data-query';
|
|
12
25
|
import { DropdownState } from '../dropdown-state';
|
|
13
26
|
export class AsyncLazyDropdownState extends DropdownState {
|
|
14
|
-
constructor(dataFetcher) {
|
|
15
|
-
super({
|
|
16
|
-
dataSource: new AsyncDataSource({
|
|
17
|
-
get: async () => {
|
|
18
|
-
const result = await dataFetcher(this.search);
|
|
19
|
-
return {
|
|
20
|
-
data: result,
|
|
21
|
-
total: result.length,
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
lazy: true,
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "arrayValue", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: []
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "onChange", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: (value) => {
|
|
38
|
-
const isEmptyValue = value === undefined || (Array.isArray(value) && value.length === 0);
|
|
39
|
-
this.arrayValue = isEmptyValue ? [] : !Array.isArray(value) ? [value] : value;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, "getOptionsWithValue", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: () => {
|
|
47
|
-
const options = [...this.options];
|
|
48
|
-
if (!this.search) {
|
|
49
|
-
const values = this.arrayValue;
|
|
50
|
-
const selectedOptions = options.filter(option => !!values.find(value => value.value === option.value));
|
|
51
|
-
const unselectedOptions = options.filter(option => !values.find(value => value.value === option.value));
|
|
52
|
-
const missingSelectedOptions = values.filter(value => !options.some(option => option.value === value.value));
|
|
53
|
-
return [...missingSelectedOptions, ...selectedOptions, ...unselectedOptions];
|
|
54
|
-
}
|
|
55
|
-
return options;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
makeObservable(this);
|
|
59
|
-
}
|
|
60
27
|
get optionsWithValue() {
|
|
61
28
|
return this.getOptionsWithValue();
|
|
62
29
|
}
|
|
63
30
|
setDataFetcher(dataFetcher) {
|
|
64
31
|
this.setDataSource(new AsyncDataSource({
|
|
65
|
-
get: async ()
|
|
32
|
+
get: async ()=>{
|
|
66
33
|
const result = await dataFetcher(this.search);
|
|
67
34
|
return {
|
|
68
35
|
data: result,
|
|
69
|
-
total: result.length
|
|
36
|
+
total: result.length
|
|
70
37
|
};
|
|
71
|
-
}
|
|
38
|
+
}
|
|
72
39
|
}));
|
|
73
40
|
}
|
|
41
|
+
constructor(dataFetcher){
|
|
42
|
+
super({
|
|
43
|
+
dataSource: new AsyncDataSource({
|
|
44
|
+
get: async ()=>{
|
|
45
|
+
const result = await dataFetcher(this.search);
|
|
46
|
+
return {
|
|
47
|
+
data: result,
|
|
48
|
+
total: result.length
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
lazy: true
|
|
53
|
+
}), _define_property(this, "arrayValue", []), _define_property(this, "onChange", (value)=>{
|
|
54
|
+
const isEmptyValue = value === undefined || Array.isArray(value) && value.length === 0;
|
|
55
|
+
this.arrayValue = isEmptyValue ? [] : !Array.isArray(value) ? [
|
|
56
|
+
value
|
|
57
|
+
] : value;
|
|
58
|
+
}), _define_property(this, "getOptionsWithValue", ()=>{
|
|
59
|
+
const options = [
|
|
60
|
+
...this.options
|
|
61
|
+
];
|
|
62
|
+
if (!this.search) {
|
|
63
|
+
const values = this.arrayValue;
|
|
64
|
+
const selectedOptions = options.filter((option)=>!!values.find((value)=>value.value === option.value));
|
|
65
|
+
const unselectedOptions = options.filter((option)=>!values.find((value)=>value.value === option.value));
|
|
66
|
+
const missingSelectedOptions = values.filter((value)=>!options.some((option)=>option.value === value.value));
|
|
67
|
+
return [
|
|
68
|
+
...missingSelectedOptions,
|
|
69
|
+
...selectedOptions,
|
|
70
|
+
...unselectedOptions
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
return options;
|
|
74
|
+
});
|
|
75
|
+
makeObservable(this);
|
|
76
|
+
}
|
|
74
77
|
}
|
|
75
|
-
|
|
78
|
+
_ts_decorate([
|
|
76
79
|
computed,
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
_ts_metadata("design:type", void 0),
|
|
81
|
+
_ts_metadata("design:paramtypes", [])
|
|
79
82
|
], AsyncLazyDropdownState.prototype, "optionsWithValue", null);
|
|
83
|
+
|
|
80
84
|
//# sourceMappingURL=async-lazy-dropdown-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/async-lazy-dropdown-state/async-lazy-dropdown-state.ts"],"sourcesContent":["import { computed, makeObservable } from 'mobx';\nimport { AsyncDataSource } from '@servicetitan/data-query';\nimport { AnvilSelectOptionsProps, AnvilSelectPropsStrict } from '@servicetitan/design-system';\nimport { DropdownOption, DropdownState } from '../dropdown-state';\n\nexport type DataFetcher = (searchQuery: string) => Promise<DropdownOption<any>[]>;\n\nexport class AsyncLazyDropdownState<T extends DropdownOption<any>> extends DropdownState<T> {\n private arrayValue: AnvilSelectOptionsProps[] = [];\n\n constructor(dataFetcher: DataFetcher) {\n super({\n dataSource: new AsyncDataSource({\n get: async () => {\n const result: any[] = await dataFetcher(this.search);\n\n return {\n data: result,\n total: result.length,\n };\n },\n }),\n lazy: true,\n });\n\n makeObservable(this);\n }\n\n @computed\n get optionsWithValue() {\n return this.getOptionsWithValue();\n }\n\n onChange = (value: AnvilSelectPropsStrict['value']) => {\n const isEmptyValue = value === undefined || (Array.isArray(value) && value.length === 0);\n\n this.arrayValue = isEmptyValue ? [] : !Array.isArray(value) ? [value!] : value;\n };\n\n setDataFetcher(dataFetcher: DataFetcher) {\n this.setDataSource(\n new AsyncDataSource({\n get: async () => {\n const result: any[] = await dataFetcher(this.search);\n\n return {\n data: result,\n total: result.length,\n };\n },\n })\n );\n }\n\n private getOptionsWithValue = () => {\n const options = [...this.options];\n\n if (!this.search) {\n const values = this.arrayValue;\n\n const selectedOptions = options.filter(\n option => !!values.find(value => value.value === option.value)\n );\n\n const unselectedOptions = options.filter(\n option => !values.find(value => value.value === option.value)\n );\n\n const missingSelectedOptions = values.filter(\n value => !options.some(option => option.value === value.value)\n );\n return [...missingSelectedOptions, ...selectedOptions, ...unselectedOptions];\n }\n\n return options;\n };\n}\n"],"names":["computed","makeObservable","AsyncDataSource","DropdownState","AsyncLazyDropdownState","optionsWithValue","getOptionsWithValue","setDataFetcher","dataFetcher","setDataSource","get","result","search","data","total","length","constructor","dataSource","lazy","arrayValue","onChange","value","isEmptyValue","undefined","Array","isArray","options","values","selectedOptions","filter","option","find","unselectedOptions","missingSelectedOptions","some"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,QAAQ,EAAEC,cAAc,QAAQ,OAAO;AAChD,SAASC,eAAe,QAAQ,2BAA2B;AAE3D,SAAyBC,aAAa,QAAQ,oBAAoB;AAIlE,OAAO,MAAMC,+BAA8DD;IAqBvE,IACIE,mBAAmB;QACnB,OAAO,IAAI,CAACC,mBAAmB;IACnC;IAQAC,eAAeC,WAAwB,EAAE;QACrC,IAAI,CAACC,aAAa,CACd,IAAIP,gBAAgB;YAChBQ,KAAK;gBACD,MAAMC,SAAgB,MAAMH,YAAY,IAAI,CAACI,MAAM;gBAEnD,OAAO;oBACHC,MAAMF;oBACNG,OAAOH,OAAOI,MAAM;gBACxB;YACJ;QACJ;IAER;IA1CAC,YAAYR,WAAwB,CAAE;QAClC,KAAK,CAAC;YACFS,YAAY,IAAIf,gBAAgB;gBAC5BQ,KAAK;oBACD,MAAMC,SAAgB,MAAMH,YAAY,IAAI,CAACI,MAAM;oBAEnD,OAAO;wBACHC,MAAMF;wBACNG,OAAOH,OAAOI,MAAM;oBACxB;gBACJ;YACJ;YACAG,MAAM;QACV,IAfJ,uBAAQC,cAAwC,EAAE,GAyBlDC,uBAAAA,YAAW,CAACC;YACR,MAAMC,eAAeD,UAAUE,aAAcC,MAAMC,OAAO,CAACJ,UAAUA,MAAMN,MAAM,KAAK;YAEtF,IAAI,CAACI,UAAU,GAAGG,eAAe,EAAE,GAAG,CAACE,MAAMC,OAAO,CAACJ,SAAS;gBAACA;aAAO,GAAGA;QAC7E,IAiBA,uBAAQf,uBAAsB;YAC1B,MAAMoB,UAAU;mBAAI,IAAI,CAACA,OAAO;aAAC;YAEjC,IAAI,CAAC,IAAI,CAACd,MAAM,EAAE;gBACd,MAAMe,SAAS,IAAI,CAACR,UAAU;gBAE9B,MAAMS,kBAAkBF,QAAQG,MAAM,CAClCC,CAAAA,SAAU,CAAC,CAACH,OAAOI,IAAI,CAACV,CAAAA,QAASA,MAAMA,KAAK,KAAKS,OAAOT,KAAK;gBAGjE,MAAMW,oBAAoBN,QAAQG,MAAM,CACpCC,CAAAA,SAAU,CAACH,OAAOI,IAAI,CAACV,CAAAA,QAASA,MAAMA,KAAK,KAAKS,OAAOT,KAAK;gBAGhE,MAAMY,yBAAyBN,OAAOE,MAAM,CACxCR,CAAAA,QAAS,CAACK,QAAQQ,IAAI,CAACJ,CAAAA,SAAUA,OAAOT,KAAK,KAAKA,MAAMA,KAAK;gBAEjE,OAAO;uBAAIY;uBAA2BL;uBAAoBI;iBAAkB;YAChF;YAEA,OAAON;QACX;QAlDIzB,eAAe,IAAI;IACvB;AAkDJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/async-lazy-dropdown-state/index.ts"],"sourcesContent":["export * from './async-lazy-dropdown-state';\nexport * from './use-async-lazy-dropdown-state';\n"],"names":[],"mappings":"AAAA,cAAc,8BAA8B;AAC5C,cAAc,kCAAkC"}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { AsyncLazyDropdownState } from './async-lazy-dropdown-state';
|
|
3
|
-
export const useAsyncLazyDropdownState = (value,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
useEffect(() => {
|
|
3
|
+
export const useAsyncLazyDropdownState = (value, // try memoising dataFetcher
|
|
4
|
+
dataFetcher)=>{
|
|
5
|
+
const [state] = useState(()=>new AsyncLazyDropdownState(dataFetcher));
|
|
6
|
+
useEffect(()=>{
|
|
8
7
|
state.onChange(value);
|
|
9
|
-
}, [
|
|
8
|
+
}, [
|
|
9
|
+
state,
|
|
10
|
+
value
|
|
11
|
+
]);
|
|
10
12
|
const isInitialMount = useRef(true);
|
|
11
|
-
useEffect(()
|
|
13
|
+
useEffect(()=>{
|
|
12
14
|
if (isInitialMount.current) {
|
|
13
15
|
isInitialMount.current = false;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
+
} else {
|
|
16
17
|
state.setDataFetcher(dataFetcher);
|
|
17
18
|
}
|
|
18
|
-
}, [
|
|
19
|
-
|
|
19
|
+
}, [
|
|
20
|
+
state,
|
|
21
|
+
dataFetcher
|
|
22
|
+
]);
|
|
23
|
+
const onOpenChange = useCallback((open)=>{
|
|
20
24
|
if (open) {
|
|
21
25
|
state.setSearch('');
|
|
22
26
|
}
|
|
23
|
-
}, [
|
|
24
|
-
|
|
27
|
+
}, [
|
|
28
|
+
state
|
|
29
|
+
]);
|
|
30
|
+
return [
|
|
31
|
+
state,
|
|
32
|
+
onOpenChange
|
|
33
|
+
];
|
|
25
34
|
};
|
|
35
|
+
|
|
26
36
|
//# sourceMappingURL=use-async-lazy-dropdown-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/async-lazy-dropdown-state/use-async-lazy-dropdown-state.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { AnvilSelectPropsStrict } from '@servicetitan/design-system';\nimport { AsyncLazyDropdownState, DataFetcher } from './async-lazy-dropdown-state';\nimport { DropdownOption } from '../dropdown-state';\n\nexport const useAsyncLazyDropdownState = (\n value: AnvilSelectPropsStrict['value'],\n // try memoising dataFetcher\n dataFetcher: DataFetcher\n) => {\n const [state] = useState(() => new AsyncLazyDropdownState(dataFetcher));\n useEffect(() => {\n state.onChange(value);\n }, [state, value]);\n\n const isInitialMount = useRef(true);\n useEffect(() => {\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else {\n state.setDataFetcher(dataFetcher);\n }\n }, [state, dataFetcher]);\n\n const onOpenChange = useCallback(\n (open: boolean) => {\n if (open) {\n state.setSearch('');\n }\n },\n [state]\n );\n\n return [state, onOpenChange] as [\n AsyncLazyDropdownState<DropdownOption<any>>,\n (open: boolean) => void,\n ];\n};\n"],"names":["useCallback","useEffect","useRef","useState","AsyncLazyDropdownState","useAsyncLazyDropdownState","value","dataFetcher","state","onChange","isInitialMount","current","setDataFetcher","onOpenChange","open","setSearch"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEjE,SAASC,sBAAsB,QAAqB,8BAA8B;AAGlF,OAAO,MAAMC,4BAA4B,CACrCC,OACA,4BAA4B;AAC5BC;IAEA,MAAM,CAACC,MAAM,GAAGL,SAAS,IAAM,IAAIC,uBAAuBG;IAC1DN,UAAU;QACNO,MAAMC,QAAQ,CAACH;IACnB,GAAG;QAACE;QAAOF;KAAM;IAEjB,MAAMI,iBAAiBR,OAAO;IAC9BD,UAAU;QACN,IAAIS,eAAeC,OAAO,EAAE;YACxBD,eAAeC,OAAO,GAAG;QAC7B,OAAO;YACHH,MAAMI,cAAc,CAACL;QACzB;IACJ,GAAG;QAACC;QAAOD;KAAY;IAEvB,MAAMM,eAAeb,YACjB,CAACc;QACG,IAAIA,MAAM;YACNN,MAAMO,SAAS,CAAC;QACpB;IACJ,GACA;QAACP;KAAM;IAGX,OAAO;QAACA;QAAOK;KAAa;AAIhC,EAAE"}
|
package/dist/date-range.js
CHANGED
package/dist/date-range.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/date-range.ts"],"sourcesContent":["export interface DateRange {\n from?: Date;\n to?: Date;\n}\n"],"names":[],"mappings":"AAAA,WAGC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useRef, Fragment } from 'react';
|
|
3
3
|
import { InMemoryDataSource, AsyncDataSource } from '@servicetitan/data-query';
|
|
4
|
-
import { AnvilSelect, Text, ButtonGroup, Button
|
|
4
|
+
import { AnvilSelect, Text, ButtonGroup, Button } from '@servicetitan/design-system';
|
|
5
5
|
import { FieldState } from 'formstate';
|
|
6
6
|
import { observer } from 'mobx-react';
|
|
7
7
|
import { DropdownState } from '..';
|
|
@@ -12,111 +12,335 @@ function useDropdownState(state) {
|
|
|
12
12
|
return useRef(state).current;
|
|
13
13
|
}
|
|
14
14
|
const options = [
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
{
|
|
16
|
+
value: 1,
|
|
17
|
+
text: 'Alderaan',
|
|
18
|
+
diameter: 12500,
|
|
19
|
+
moons: 0
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: 2,
|
|
23
|
+
text: 'Bespin',
|
|
24
|
+
diameter: 118000,
|
|
25
|
+
moons: 2
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: 3,
|
|
29
|
+
text: 'Coruscant',
|
|
30
|
+
diameter: 12240,
|
|
31
|
+
moons: 4
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
value: 4,
|
|
35
|
+
text: 'Dagobah',
|
|
36
|
+
diameter: 14410,
|
|
37
|
+
moons: 0
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
value: 5,
|
|
41
|
+
text: 'Hoth',
|
|
42
|
+
diameter: 7200,
|
|
43
|
+
moons: 3
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
value: 6,
|
|
47
|
+
text: 'Kashyyyk',
|
|
48
|
+
diameter: 12765,
|
|
49
|
+
moons: 3
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
value: 7,
|
|
53
|
+
text: 'Naboo',
|
|
54
|
+
diameter: 12120,
|
|
55
|
+
moons: 3
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: 8,
|
|
59
|
+
text: 'Tatooine',
|
|
60
|
+
diameter: 10465,
|
|
61
|
+
moons: 3
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
value: 9,
|
|
65
|
+
text: 'Yavin',
|
|
66
|
+
diameter: 200000,
|
|
67
|
+
moons: 26
|
|
68
|
+
}
|
|
24
69
|
];
|
|
25
70
|
const optionsWithGroups = [
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
{
|
|
72
|
+
value: 1,
|
|
73
|
+
text: 'Hem Dazon',
|
|
74
|
+
group: 'Arcona'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
value: 2,
|
|
78
|
+
text: 'El-Les',
|
|
79
|
+
group: 'Arcona'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: 3,
|
|
83
|
+
text: 'Jheeg',
|
|
84
|
+
group: 'Arcona'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
value: 4,
|
|
88
|
+
text: 'Paploo',
|
|
89
|
+
group: 'Ewok'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 5,
|
|
93
|
+
text: 'Gallo',
|
|
94
|
+
group: 'Gungan'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: 6,
|
|
98
|
+
text: 'Lyonie',
|
|
99
|
+
group: 'Gungan'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: 7,
|
|
103
|
+
text: 'Tobler Ceel',
|
|
104
|
+
group: 'Gungan'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
value: 8,
|
|
108
|
+
text: 'Ganne',
|
|
109
|
+
group: 'Gungan'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
value: 9,
|
|
113
|
+
text: 'Augara Jowil',
|
|
114
|
+
group: 'Gungan'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
value: 10,
|
|
118
|
+
text: 'Reegesk',
|
|
119
|
+
group: 'Ranat'
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
value: 11,
|
|
123
|
+
text: 'Rik-tak',
|
|
124
|
+
group: 'Ranat'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
value: 12,
|
|
128
|
+
text: 'Bahb',
|
|
129
|
+
group: 'Zeltron'
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
value: 13,
|
|
133
|
+
text: 'Chantique',
|
|
134
|
+
group: 'Zeltron'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
value: 14,
|
|
138
|
+
text: 'Luxa',
|
|
139
|
+
group: 'Zeltron'
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
value: 15,
|
|
143
|
+
text: 'Rahuhl',
|
|
144
|
+
group: 'Zeltron'
|
|
145
|
+
}
|
|
41
146
|
];
|
|
42
|
-
const InMemoryDropdownStateExample = observer(()
|
|
147
|
+
const InMemoryDropdownStateExample = observer(()=>{
|
|
43
148
|
const field = useDropdownField([]);
|
|
44
149
|
const state = useDropdownState(new DropdownState({
|
|
45
|
-
dataSource: new InMemoryDataSource(options)
|
|
150
|
+
dataSource: new InMemoryDataSource(options)
|
|
46
151
|
}));
|
|
47
|
-
const handleChange = (data)
|
|
48
|
-
field.onChange(Array.isArray(data) ? data : [
|
|
152
|
+
const handleChange = (data)=>{
|
|
153
|
+
field.onChange(Array.isArray(data) ? data : [
|
|
154
|
+
data
|
|
155
|
+
]);
|
|
49
156
|
};
|
|
50
|
-
const withReset = (handler)
|
|
51
|
-
return async ()
|
|
157
|
+
const withReset = (handler)=>{
|
|
158
|
+
return async ()=>{
|
|
52
159
|
handleChange([]);
|
|
53
160
|
state.setSearch('');
|
|
54
161
|
state.setDataSource(null);
|
|
55
162
|
state.setSearchByGroup(false);
|
|
56
|
-
state.setSort([
|
|
163
|
+
state.setSort([
|
|
164
|
+
{
|
|
165
|
+
field: 'text'
|
|
166
|
+
}
|
|
167
|
+
]);
|
|
57
168
|
state.setFilter(null);
|
|
58
|
-
state.setGroup([
|
|
169
|
+
state.setGroup([
|
|
170
|
+
{
|
|
171
|
+
field: 'group'
|
|
172
|
+
}
|
|
173
|
+
]);
|
|
59
174
|
await Promise.resolve();
|
|
60
175
|
handler();
|
|
61
176
|
};
|
|
62
177
|
};
|
|
63
|
-
const withoutGroups = withReset(()
|
|
178
|
+
const withoutGroups = withReset(()=>{
|
|
64
179
|
state.setDataSource(new InMemoryDataSource(options));
|
|
65
180
|
});
|
|
66
|
-
const withGroups = withReset(()
|
|
181
|
+
const withGroups = withReset(()=>{
|
|
67
182
|
state.setDataSource(new InMemoryDataSource(optionsWithGroups));
|
|
68
183
|
});
|
|
69
|
-
const withGroupsAndSearch = withReset(()
|
|
184
|
+
const withGroupsAndSearch = withReset(()=>{
|
|
70
185
|
state.setDataSource(new InMemoryDataSource(optionsWithGroups));
|
|
71
186
|
state.setSearchByGroup(true);
|
|
72
187
|
});
|
|
73
|
-
const customSort = withReset(()
|
|
188
|
+
const customSort = withReset(()=>{
|
|
74
189
|
state.setDataSource(new InMemoryDataSource(options));
|
|
75
|
-
state.setSort([
|
|
190
|
+
state.setSort([
|
|
191
|
+
{
|
|
192
|
+
field: 'diameter',
|
|
193
|
+
dir: 'desc'
|
|
194
|
+
}
|
|
195
|
+
]);
|
|
76
196
|
});
|
|
77
|
-
const customFilter = withReset(()
|
|
197
|
+
const customFilter = withReset(()=>{
|
|
78
198
|
state.setDataSource(new InMemoryDataSource(options));
|
|
79
199
|
state.setFilter({
|
|
80
200
|
logic: 'and',
|
|
81
|
-
filters: [
|
|
201
|
+
filters: [
|
|
202
|
+
{
|
|
203
|
+
field: 'diameter',
|
|
204
|
+
value: 12250,
|
|
205
|
+
operator: 'gte'
|
|
206
|
+
}
|
|
207
|
+
]
|
|
82
208
|
});
|
|
83
209
|
});
|
|
84
|
-
const customGroup = withReset(()
|
|
210
|
+
const customGroup = withReset(()=>{
|
|
85
211
|
state.setDataSource(new InMemoryDataSource(options));
|
|
86
|
-
state.setGroup([
|
|
212
|
+
state.setGroup([
|
|
213
|
+
{
|
|
214
|
+
field: 'moons',
|
|
215
|
+
dir: 'desc'
|
|
216
|
+
}
|
|
217
|
+
]);
|
|
218
|
+
});
|
|
219
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
220
|
+
children: [
|
|
221
|
+
/*#__PURE__*/ _jsx(AnvilSelect, {
|
|
222
|
+
value: field.value,
|
|
223
|
+
onChange: handleChange,
|
|
224
|
+
options: state.options,
|
|
225
|
+
search: {
|
|
226
|
+
value: state.search,
|
|
227
|
+
onChange: state.onSearchChange
|
|
228
|
+
},
|
|
229
|
+
multiple: true
|
|
230
|
+
}),
|
|
231
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
232
|
+
size: 4,
|
|
233
|
+
className: "m-t-4 m-b-half",
|
|
234
|
+
children: "Without groups"
|
|
235
|
+
}),
|
|
236
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
237
|
+
onClick: withoutGroups,
|
|
238
|
+
children: "Apply"
|
|
239
|
+
}),
|
|
240
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
241
|
+
size: 4,
|
|
242
|
+
className: "m-t-4 m-b-half",
|
|
243
|
+
children: "With groups"
|
|
244
|
+
}),
|
|
245
|
+
/*#__PURE__*/ _jsxs(ButtonGroup, {
|
|
246
|
+
children: [
|
|
247
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
248
|
+
onClick: withGroups,
|
|
249
|
+
children: "Search in options"
|
|
250
|
+
}),
|
|
251
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
252
|
+
onClick: withGroupsAndSearch,
|
|
253
|
+
children: "Search in options & groups"
|
|
254
|
+
})
|
|
255
|
+
]
|
|
256
|
+
}),
|
|
257
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
258
|
+
size: 4,
|
|
259
|
+
className: "m-t-4 m-b-half",
|
|
260
|
+
children: "Custom sort"
|
|
261
|
+
}),
|
|
262
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
263
|
+
onClick: customSort,
|
|
264
|
+
children: "Apply"
|
|
265
|
+
}),
|
|
266
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
267
|
+
size: 4,
|
|
268
|
+
className: "m-t-4 m-b-half",
|
|
269
|
+
children: "Custom filter"
|
|
270
|
+
}),
|
|
271
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
272
|
+
onClick: customFilter,
|
|
273
|
+
children: "Apply"
|
|
274
|
+
}),
|
|
275
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
276
|
+
size: 4,
|
|
277
|
+
className: "m-t-4 m-b-half",
|
|
278
|
+
children: "Custom group"
|
|
279
|
+
}),
|
|
280
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
281
|
+
onClick: customGroup,
|
|
282
|
+
children: "Apply"
|
|
283
|
+
})
|
|
284
|
+
]
|
|
87
285
|
});
|
|
88
|
-
return (_jsxs(Fragment, { children: [_jsx(AnvilSelect, { value: field.value, onChange: handleChange, options: state.options, search: { value: state.search, onChange: state.onSearchChange }, multiple: true }), _jsx(Text, { size: 4, className: "m-t-4 m-b-half", children: "Without groups" }), _jsx(Button, { onClick: withoutGroups, children: "Apply" }), _jsx(Text, { size: 4, className: "m-t-4 m-b-half", children: "With groups" }), _jsxs(ButtonGroup, { children: [_jsx(Button, { onClick: withGroups, children: "Search in options" }), _jsx(Button, { onClick: withGroupsAndSearch, children: "Search in options & groups" })] }), _jsx(Text, { size: 4, className: "m-t-4 m-b-half", children: "Custom sort" }), _jsx(Button, { onClick: customSort, children: "Apply" }), _jsx(Text, { size: 4, className: "m-t-4 m-b-half", children: "Custom filter" }), _jsx(Button, { onClick: customFilter, children: "Apply" }), _jsx(Text, { size: 4, className: "m-t-4 m-b-half", children: "Custom group" }), _jsx(Button, { onClick: customGroup, children: "Apply" })] }));
|
|
89
286
|
});
|
|
90
|
-
const AsyncDropdownStateExample = observer(()
|
|
287
|
+
const AsyncDropdownStateExample = observer(()=>{
|
|
91
288
|
const field = useDropdownField([]);
|
|
92
289
|
const state = useDropdownState(new DropdownState({
|
|
93
290
|
dataSource: new AsyncDataSource({
|
|
94
|
-
async get({ filter }) {
|
|
95
|
-
var
|
|
96
|
-
const search =
|
|
97
|
-
const result = search
|
|
98
|
-
|
|
99
|
-
: options;
|
|
100
|
-
await new Promise(resolver => setTimeout(resolver, 1000));
|
|
291
|
+
async get ({ filter }) {
|
|
292
|
+
var _filter_filters_, _filter_filters;
|
|
293
|
+
const search = filter === null || filter === void 0 ? void 0 : (_filter_filters = filter.filters) === null || _filter_filters === void 0 ? void 0 : (_filter_filters_ = _filter_filters[0]) === null || _filter_filters_ === void 0 ? void 0 : _filter_filters_.value;
|
|
294
|
+
const result = search ? options.filter(({ text })=>text.toLowerCase().includes(search.toLowerCase())) : options;
|
|
295
|
+
await new Promise((resolver)=>setTimeout(resolver, 1000));
|
|
101
296
|
return {
|
|
102
297
|
data: result,
|
|
103
|
-
total: result.length
|
|
298
|
+
total: result.length
|
|
104
299
|
};
|
|
105
|
-
}
|
|
300
|
+
}
|
|
106
301
|
}, undefined, true),
|
|
107
|
-
lazy: true
|
|
302
|
+
lazy: true
|
|
108
303
|
}));
|
|
109
|
-
const handleChange = (data)
|
|
110
|
-
field.onChange(Array.isArray(data) ? data : [
|
|
304
|
+
const handleChange = (data)=>{
|
|
305
|
+
field.onChange(Array.isArray(data) ? data : [
|
|
306
|
+
data
|
|
307
|
+
]);
|
|
111
308
|
};
|
|
112
|
-
const handleOpenChange = (open)
|
|
309
|
+
const handleOpenChange = (open)=>{
|
|
113
310
|
if (open) {
|
|
114
311
|
state.fetch();
|
|
115
312
|
}
|
|
116
313
|
};
|
|
117
|
-
return
|
|
314
|
+
return /*#__PURE__*/ _jsx(AnvilSelect, {
|
|
315
|
+
value: field.value,
|
|
316
|
+
onChange: handleChange,
|
|
317
|
+
options: state.options,
|
|
318
|
+
search: {
|
|
319
|
+
value: state.search,
|
|
320
|
+
onChange: state.onSearchChange
|
|
321
|
+
},
|
|
322
|
+
onOpenChange: handleOpenChange,
|
|
323
|
+
loading: state.loading,
|
|
324
|
+
multiple: true
|
|
325
|
+
});
|
|
118
326
|
});
|
|
119
|
-
export const DropdownStateExample = ()
|
|
120
|
-
return
|
|
327
|
+
export const DropdownStateExample = ()=>{
|
|
328
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
329
|
+
children: [
|
|
330
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
331
|
+
size: 5,
|
|
332
|
+
className: "m-b-half",
|
|
333
|
+
children: "InMemoryDataSource"
|
|
334
|
+
}),
|
|
335
|
+
/*#__PURE__*/ _jsx(InMemoryDropdownStateExample, {}),
|
|
336
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
337
|
+
size: 5,
|
|
338
|
+
className: "m-t-5 m-b-half",
|
|
339
|
+
children: "AsyncDataSource"
|
|
340
|
+
}),
|
|
341
|
+
/*#__PURE__*/ _jsx(AsyncDropdownStateExample, {})
|
|
342
|
+
]
|
|
343
|
+
});
|
|
121
344
|
};
|
|
345
|
+
|
|
122
346
|
//# sourceMappingURL=dropdown-state.js.map
|