@inseefr/lunatic 3.0.0-rc.13 → 3.0.0-rc.15
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/lib/main.css +0 -2
- package/lib/main.css.map +1 -1
- package/lib/package.json +3 -3
- package/lib/src/components/Loop/Loop.d.ts +1 -1
- package/lib/src/components/LunaticComponents.d.ts +5 -4
- package/lib/src/components/LunaticComponents.js.map +1 -1
- package/lib/src/components/PairwiseLinks/PairwiseLinks.js +31 -5
- package/lib/src/components/PairwiseLinks/PairwiseLinks.js.map +1 -1
- package/lib/src/components/Radio/Radio.d.ts +1 -0
- package/lib/src/components/RosterForLoop/RosterForLoop.spec.js.map +1 -1
- package/lib/src/components/Sequence/Sequence.d.ts +3 -1
- package/lib/src/components/Subsequence/Subsequence.d.ts +3 -1
- package/lib/src/components/Suggester/CustomSuggester.d.ts +9 -8
- package/lib/src/components/Suggester/CustomSuggester.js +4 -31
- package/lib/src/components/Suggester/CustomSuggester.js.map +1 -1
- package/lib/src/components/Suggester/Suggester.d.ts +1 -1
- package/lib/src/components/Suggester/Suggester.js +57 -35
- package/lib/src/components/Suggester/Suggester.js.map +1 -1
- package/lib/src/components/Suggester/SuggesterNotification.d.ts +5 -6
- package/lib/src/components/Suggester/SuggesterNotification.js +5 -10
- package/lib/src/components/Suggester/SuggesterNotification.js.map +1 -1
- package/lib/src/components/Suggester/useSuggestions.d.ts +20 -0
- package/lib/src/components/Suggester/useSuggestions.js +86 -0
- package/lib/src/components/Suggester/useSuggestions.js.map +1 -0
- package/lib/src/components/Switch/Switch.d.ts +1 -0
- package/lib/src/components/library.d.ts +15 -5
- package/lib/src/components/shared/Combobox/Combobox.d.ts +2 -0
- package/lib/src/components/shared/Combobox/Combobox.js +5 -6
- package/lib/src/components/shared/Combobox/Combobox.js.map +1 -1
- package/lib/src/components/shared/Combobox/ComboboxType.d.ts +1 -0
- package/lib/src/components/shared/Combobox/Panel/ComboboxOption.js +4 -0
- package/lib/src/components/shared/Combobox/Panel/ComboboxOption.js.map +1 -1
- package/lib/src/components/shared/Combobox/Panel/ComboboxPanel.d.ts +1 -1
- package/lib/src/components/shared/Combobox/Panel/ComboboxPanel.js +15 -1
- package/lib/src/components/shared/Combobox/Panel/ComboboxPanel.js.map +1 -1
- package/lib/src/components/shared/Combobox/Selection/ComboboxLabelSelection.js +6 -0
- package/lib/src/components/shared/Combobox/Selection/ComboboxLabelSelection.js.map +1 -1
- package/lib/src/components/type.d.ts +41 -11
- package/lib/src/components/type.js.map +1 -1
- package/lib/src/hooks/use-track-changes.js +1 -1
- package/lib/src/hooks/use-track-changes.js.map +1 -1
- package/lib/src/hooks/useDebounce.d.ts +4 -0
- package/lib/src/hooks/useDebounce.js +23 -0
- package/lib/src/hooks/useDebounce.js.map +1 -0
- package/lib/src/hooks/useDocumentEvent.js +1 -1
- package/lib/src/hooks/useDocumentEvent.js.map +1 -1
- package/lib/src/hooks/{use-ref-sync.js → useRefSync.js} +1 -1
- package/lib/src/hooks/useRefSync.js.map +1 -0
- package/lib/src/hooks/useSuggesterInfo.d.ts +1 -1
- package/lib/src/i18n/dictionary.d.ts +16 -0
- package/lib/src/i18n/dictionary.js +16 -0
- package/lib/src/i18n/dictionary.js.map +1 -1
- package/lib/src/i18n/index.d.ts +1 -1
- package/lib/src/use-lunatic/commons/fill-components/fill-component-expressions.js +3 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
- package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +71 -66
- package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +68 -63
- package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +16 -16
- package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +70 -60
- package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.js +16 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.js.map +1 -1
- package/lib/src/use-lunatic/commons/use-components-from-state.d.ts +2 -1
- package/lib/src/use-lunatic/commons/use-components-from-state.js.map +1 -1
- package/lib/src/use-lunatic/hooks/use-page-has-response.d.ts +2 -2
- package/lib/src/use-lunatic/hooks/use-page-has-response.js +6 -3
- package/lib/src/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/lib/src/use-lunatic/replace-component-sequence.d.ts +3 -3
- package/lib/src/use-lunatic/type-source.d.ts +7 -2
- package/lib/src/use-lunatic/use-lunatic.d.ts +4 -486
- package/lib/src/use-lunatic/use-lunatic.js +2 -2
- package/lib/src/use-lunatic/use-lunatic.js.map +1 -1
- package/lib/src/use-lunatic/use-lunatic.test.js +2 -2
- package/lib/src/use-lunatic/use-lunatic.test.js.map +1 -1
- package/lib/src/utils/function.d.ts +1 -0
- package/lib/src/utils/function.js +18 -0
- package/lib/src/utils/function.js.map +1 -1
- package/package.json +3 -3
- package/lib/src/components/Suggester/SuggesterStatus.d.ts +0 -23
- package/lib/src/components/Suggester/SuggesterStatus.js +0 -24
- package/lib/src/components/Suggester/SuggesterStatus.js.map +0 -1
- package/lib/src/hooks/use-ref-sync.js.map +0 -1
- /package/lib/src/hooks/{use-ref-sync.d.ts → useRefSync.d.ts} +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { createSearching } from './helpers';
|
|
3
|
+
import { useEffectDebounced } from '../../hooks/useDebounce';
|
|
4
|
+
import { SuggesterStatus } from '../../use-lunatic/use-suggesters';
|
|
5
|
+
export const OTHER_VALUE = 'OTHER';
|
|
6
|
+
const getStateFromSuggesterStatus = (suggesterStatus) => {
|
|
7
|
+
if (suggesterStatus === SuggesterStatus.error ||
|
|
8
|
+
suggesterStatus === SuggesterStatus.unknown) {
|
|
9
|
+
return 'error';
|
|
10
|
+
}
|
|
11
|
+
return 'success';
|
|
12
|
+
};
|
|
13
|
+
export function useSuggestions({ indexStatus, storeName, idbVersion, workersBasePath, selectedOptions, allowArbitrary, }) {
|
|
14
|
+
const [search, setSearch] = useState('');
|
|
15
|
+
const isReady = indexStatus === SuggesterStatus.success;
|
|
16
|
+
const lastSearch = useRef();
|
|
17
|
+
const [state, setState] = useState(getStateFromSuggesterStatus(indexStatus));
|
|
18
|
+
let [options, setOptions] = useState(selectedOptions);
|
|
19
|
+
const searching = useMemo(() => {
|
|
20
|
+
if (!isReady) {
|
|
21
|
+
// While waiting for the search to be ready, remember the last search done
|
|
22
|
+
return (name) => {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
lastSearch.current = [name, resolve];
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const searching = createSearching(storeName, idbVersion, workersBasePath);
|
|
29
|
+
// Solve the last pending search
|
|
30
|
+
const pendingSearch = lastSearch.current;
|
|
31
|
+
if (pendingSearch && pendingSearch[0]) {
|
|
32
|
+
searching(pendingSearch[0]).then((r) => pendingSearch[1](r));
|
|
33
|
+
lastSearch.current = undefined;
|
|
34
|
+
}
|
|
35
|
+
return searching;
|
|
36
|
+
}, [isReady, storeName, idbVersion, workersBasePath]);
|
|
37
|
+
useEffectDebounced(() => {
|
|
38
|
+
searching?.(search)
|
|
39
|
+
.then((r) => {
|
|
40
|
+
setOptions(r.results);
|
|
41
|
+
setState('success');
|
|
42
|
+
})
|
|
43
|
+
.catch(() => setState('error'));
|
|
44
|
+
}, [search], 300);
|
|
45
|
+
if (search && allowArbitrary && options.length === 0 && state === 'success') {
|
|
46
|
+
options = [
|
|
47
|
+
{
|
|
48
|
+
id: OTHER_VALUE,
|
|
49
|
+
label: search,
|
|
50
|
+
value: OTHER_VALUE,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
// Since the underlying implementation of onFocus / onBlur can be wrong, ensure we don't call focus / blur handler multiple times
|
|
55
|
+
const [isFocused, setFocused] = useState(false);
|
|
56
|
+
return {
|
|
57
|
+
search,
|
|
58
|
+
setSearch: (s) => {
|
|
59
|
+
if (state === 'error') {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
setState('loading');
|
|
63
|
+
setSearch(s);
|
|
64
|
+
},
|
|
65
|
+
state,
|
|
66
|
+
options: isFocused ? options : selectedOptions,
|
|
67
|
+
onBlur: () => {
|
|
68
|
+
// Prevent extra calls
|
|
69
|
+
if (!isFocused) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setFocused(false);
|
|
73
|
+
setSearch('');
|
|
74
|
+
setOptions(selectedOptions);
|
|
75
|
+
},
|
|
76
|
+
onFocus: () => {
|
|
77
|
+
// Prevent extra calls
|
|
78
|
+
if (isFocused) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
setFocused(true);
|
|
82
|
+
setSearch(selectedOptions[0]?.label ?? '');
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=useSuggestions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSuggestions.js","sourceRoot":"","sources":["../../../../src/components/Suggester/useSuggestions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAWnE,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAInC,MAAM,2BAA2B,GAAG,CACnC,eAAgC,EACE,EAAE;IACpC,IACC,eAAe,KAAK,eAAe,CAAC,KAAK;QACzC,eAAe,KAAK,eAAe,CAAC,OAAO,EAC1C,CAAC;QACF,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,EAC9B,WAAW,EACX,SAAS,EACT,UA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B,IAAI,SAAS,EAAE,CAAC;gBACf,OAAO;YACR,CAAC;YACD,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { CheckboxGroup } from './CheckboxGroup/CheckboxGroup';
|
|
|
4
4
|
import { CheckboxBoolean } from './CheckboxBoolean/CheckboxBoolean';
|
|
5
5
|
import { Input } from './Input/Input';
|
|
6
6
|
import { Textarea } from './Textarea/Textarea';
|
|
7
|
+
import type { LunaticComponentProps } from './type';
|
|
7
8
|
import type { ComponentType } from 'react';
|
|
8
9
|
import { InputNumber } from './InputNumber/InputNumber';
|
|
9
10
|
import { Duration } from './Duration/Duration';
|
|
@@ -14,15 +15,19 @@ import { CheckboxOne } from './CheckboxOne/CheckboxOne';
|
|
|
14
15
|
import { Suggester } from './Suggester/Suggester';
|
|
15
16
|
import { Summary } from './Summary/Summary';
|
|
16
17
|
export declare const library: {
|
|
17
|
-
Sequence: ComponentType<Pick<import("./type").LunaticBaseProps<string>, "label" | "description" | "declarations" | "id" | "style"
|
|
18
|
-
|
|
18
|
+
Sequence: ComponentType<Pick<import("./type").LunaticBaseProps<string>, "label" | "description" | "declarations" | "id" | "style"> & {
|
|
19
|
+
componentType?: "Sequence" | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
Subsequence: ComponentType<Pick<import("./type").LunaticBaseProps<string>, "label" | "declarations" | "id"> & {
|
|
22
|
+
componentType?: "Subsequence" | undefined;
|
|
23
|
+
}>;
|
|
19
24
|
RosterForLoop: (props: import("./type").LunaticBaseProps<unknown> & {
|
|
20
25
|
lines: {
|
|
21
26
|
min: number;
|
|
22
27
|
max: number;
|
|
23
28
|
};
|
|
24
29
|
iterations: number;
|
|
25
|
-
getComponents: (n: number) => import("
|
|
30
|
+
getComponents: (n: number) => LunaticComponentProps<keyof import("./type").ComponentPropsByType>[];
|
|
26
31
|
executeExpression: <T extends unknown = unknown>(expression: unknown, args?: {
|
|
27
32
|
iteration?: number | number[] | undefined;
|
|
28
33
|
bindingDependencies?: string[] | undefined;
|
|
@@ -35,6 +40,7 @@ export declare const library: {
|
|
|
35
40
|
colspan?: number | undefined;
|
|
36
41
|
}[] | undefined;
|
|
37
42
|
paginatedLoop?: boolean | undefined;
|
|
43
|
+
componentType?: "RosterForLoop" | undefined;
|
|
38
44
|
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
39
45
|
Loop: typeof Loop;
|
|
40
46
|
Table: typeof Table;
|
|
@@ -53,6 +59,7 @@ export declare const library: {
|
|
|
53
59
|
response: {
|
|
54
60
|
name: string;
|
|
55
61
|
};
|
|
62
|
+
componentType?: "Radio" | undefined;
|
|
56
63
|
}>;
|
|
57
64
|
Input: typeof Input;
|
|
58
65
|
Duration: typeof Duration;
|
|
@@ -65,9 +72,11 @@ export declare const library: {
|
|
|
65
72
|
true: string;
|
|
66
73
|
false: string;
|
|
67
74
|
} | undefined;
|
|
75
|
+
componentType?: "Switch" | undefined;
|
|
68
76
|
}>;
|
|
69
77
|
Question: ({ components, ...props }: Pick<import("./type").LunaticBaseProps<unknown>, "label" | "description" | "declarations" | "id"> & {
|
|
70
|
-
components: import("
|
|
78
|
+
components: LunaticComponentProps<keyof import("./type").ComponentPropsByType>[];
|
|
79
|
+
componentType?: "Question" | undefined;
|
|
71
80
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
72
81
|
FilterDescription: ({ id, label }: {
|
|
73
82
|
id: string;
|
|
@@ -86,7 +95,8 @@ export declare const library: {
|
|
|
86
95
|
yAxisIterations: number;
|
|
87
96
|
symLinks: Record<string, Record<string, string>>;
|
|
88
97
|
value: Record<string, unknown[]>;
|
|
89
|
-
getComponents: (x: number, y: number) => import("
|
|
98
|
+
getComponents: (x: number, y: number) => LunaticComponentProps<keyof import("./type").ComponentPropsByType>[];
|
|
99
|
+
componentType?: "PairwiseLinks" | undefined;
|
|
90
100
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
91
101
|
Roundabout: typeof Roundabout;
|
|
92
102
|
Suggester: typeof Suggester;
|
|
@@ -14,8 +14,10 @@ type Props = ComboboxSelectionProps & ComboboxPanelProps & {
|
|
|
14
14
|
onChange?: (s: string | null) => void;
|
|
15
15
|
onSelect: (s: string | null) => void;
|
|
16
16
|
onBlur?: () => void;
|
|
17
|
+
onFocus?: () => void;
|
|
17
18
|
options: ComboboxOptionType[];
|
|
18
19
|
readOnly?: boolean;
|
|
20
|
+
isLoading?: boolean;
|
|
19
21
|
};
|
|
20
22
|
export declare const Combobox: import("react").ComponentType<Props>;
|
|
21
23
|
export {};
|
|
@@ -11,16 +11,16 @@ import { between, forceInt } from '../../../utils/number';
|
|
|
11
11
|
import { Label } from '../Label/Label';
|
|
12
12
|
import { slottableComponent } from '../HOC/slottableComponent';
|
|
13
13
|
const EMPTY_SEARCH = '';
|
|
14
|
-
function LunaticComboBox({ className, classNamePrefix, classStyle = 'default-style', placeholder = 'Commencez votre saisie...', editable = false, disabled, readOnly, id, optionRenderer, labelRenderer, onChange, onSelect, value, options, messageError, search
|
|
14
|
+
function LunaticComboBox({ className, classNamePrefix, classStyle = 'default-style', placeholder = 'Commencez votre saisie...', editable = false, disabled, readOnly, id, optionRenderer, labelRenderer, onChange, onSelect, value, options, messageError, search = EMPTY_SEARCH, getOptionValue = getDefaultOptionValue, label, description, errors, onBlur, onFocus, isLoading, }) {
|
|
15
15
|
const [expanded, setExpanded] = useState(false);
|
|
16
16
|
const [focused, setFocused] = useState(false);
|
|
17
|
-
const [search, setSearch] = useState(searchProps ?? '');
|
|
18
17
|
const selectedIndex = getIndexFromOptions(options, value, getOptionValue);
|
|
19
18
|
const labelId = `label-${id}`;
|
|
20
19
|
const handleFocus = () => {
|
|
21
20
|
if (disabled || readOnly) {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
23
|
+
onFocus?.();
|
|
24
24
|
setExpanded(true);
|
|
25
25
|
setFocused(true);
|
|
26
26
|
};
|
|
@@ -28,24 +28,23 @@ function LunaticComboBox({ className, classNamePrefix, classStyle = 'default-sty
|
|
|
28
28
|
if (disabled || readOnly) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
onBlur?.();
|
|
32
31
|
setExpanded(false);
|
|
33
32
|
setFocused(false);
|
|
33
|
+
onBlur?.();
|
|
34
34
|
};
|
|
35
35
|
const handleSelect = (index, close = true) => {
|
|
36
36
|
const indexNumber = between(forceInt(index), 0, options.length);
|
|
37
37
|
const option = options[indexNumber];
|
|
38
38
|
if (close) {
|
|
39
39
|
setExpanded(false);
|
|
40
|
+
onBlur?.();
|
|
40
41
|
}
|
|
41
42
|
onSelect(getOptionValue(option));
|
|
42
43
|
};
|
|
43
44
|
const handleChange = (s) => {
|
|
44
|
-
setSearch(s ?? '');
|
|
45
45
|
onChange?.(s);
|
|
46
46
|
};
|
|
47
47
|
const handleClear = () => {
|
|
48
|
-
setSearch('');
|
|
49
48
|
setExpanded(false);
|
|
50
49
|
onChange?.(EMPTY_SEARCH);
|
|
51
50
|
onSelect(null);
|
|
@@ -78,7 +77,7 @@ function LunaticComboBox({ className, classNamePrefix, classStyle = 'default-sty
|
|
|
78
77
|
if (messageError) {
|
|
79
78
|
return (_jsx("div", { className: "lunatic-combo-box-message-error", children: messageError }));
|
|
80
79
|
}
|
|
81
|
-
return (_jsxs(ComboboxContainer, { id: id, className: className, classStyle: classStyle, classNamePrefix: classNamePrefix, errors: errors, children: [_jsx(Label, { htmlFor: id, id: labelId, description: description, children: label }), _jsxs(ComboboxContent, { focused: focused, onFocus: handleFocus, onBlur: handleBlur, onKeyDown: onKeyDown, classNamePrefix: classNamePrefix, children: [_jsx(ComboboxSelection, { labelRenderer: labelRenderer, placeholder: placeholder, search: search, expanded: expanded, id: id, labelId: labelId, disabled: disabled, readOnly: readOnly, focused: focused, editable: editable, selectedIndex: selectedIndex, options: options, onChange: handleChange, classNamePrefix: classNamePrefix, invalid: !!errors }), _jsx(ComboboxPanel, { optionRenderer: optionRenderer, options: options, focused: focused, selectedIndex: selectedIndex, expanded: expanded, id: id, search: search, onSelect: handleSelect })] }), showClearButton && (_jsx(ComboboxClearButton, { className: classnames({ focused }), search: search, onClick: handleClear, editable: editable }))] }));
|
|
80
|
+
return (_jsxs(ComboboxContainer, { id: id, className: className, classStyle: classStyle, classNamePrefix: classNamePrefix, errors: errors, children: [_jsx(Label, { htmlFor: id, id: labelId, description: description, children: label }), _jsxs(ComboboxContent, { focused: focused, onFocus: handleFocus, onBlur: handleBlur, onKeyDown: onKeyDown, classNamePrefix: classNamePrefix, children: [_jsx(ComboboxSelection, { labelRenderer: labelRenderer, placeholder: placeholder, search: search, expanded: expanded, id: id, labelId: labelId, disabled: disabled, readOnly: readOnly, focused: focused, editable: editable, selectedIndex: selectedIndex, options: options, onChange: handleChange, classNamePrefix: classNamePrefix, invalid: !!errors }), _jsx(ComboboxPanel, { isLoading: isLoading, optionRenderer: optionRenderer, options: options, focused: focused, selectedIndex: selectedIndex, expanded: expanded, id: id, search: search, onSelect: handleSelect })] }), showClearButton && (_jsx(ComboboxClearButton, { className: classnames({ focused }), search: search, onClick: handleClear, editable: editable }))] }));
|
|
82
81
|
}
|
|
83
82
|
function getIndexFromOptions(options, value, getOptionValue) {
|
|
84
83
|
if (!Array.isArray(options)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.js","sourceRoot":"","sources":["../../../../../src/components/shared/Combobox/Combobox.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAkB,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM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Ae,IAAI,CACnB,KAAC,mBAAmB,IACnB,SAAS,EAAE,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,EAClC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,QAAQ,GACjB,CACF,IACkB,CACpB,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAC3B,OAA6B,EAC7B,KAAoB,EACpB,cAAiD;IAEjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;AAClE,CAAC;AAED;;GAEG;AACH,SAAS,qBAAqB,CAAC,SAA6B,EAAE,KAAK,EAAE,EAAE,EAAE;IACxE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC7B,OAAO,EAAE,IAAI,KAAK,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import { slottableComponent } from '../../HOC/slottableComponent';
|
|
4
|
+
import D from '../../../../i18n';
|
|
4
5
|
export const ComboboxOption = slottableComponent('ComboboxOption', ({ option, selected }) => {
|
|
5
6
|
const { id, value, label } = option;
|
|
7
|
+
if (value === 'OTHER') {
|
|
8
|
+
return (_jsx("div", { className: classnames('lunatic-combo-box-option', { selected }), children: _jsx("span", { className: "label", children: `${D.SUGGESTER_NO_RESULT} : ${D.SUGGESTER_ARBITRARY} "${label}"` }) }));
|
|
9
|
+
}
|
|
6
10
|
if (label && typeof label === 'string' && label.length) {
|
|
7
11
|
return (_jsxs("div", { className: classnames('lunatic-combo-box-option', { selected }), children: [_jsx("span", { className: "id", children: id || value }), _jsx("span", { children: " - " }), _jsx("span", { className: "label", children: label })] }));
|
|
8
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxOption.js","sourceRoot":"","sources":["../../../../../../src/components/shared/Combobox/Panel/ComboboxOption.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"ComboboxOption.js","sourceRoot":"","sources":["../../../../../../src/components/shared/Combobox/Panel/ComboboxOption.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,CAAC,MAAM,kBAAkB,CAAC;AAOjC,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAC/C,gBAAgB,EAChB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAS,EAAE,EAAE;IAC/B,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAEpC,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QACvB,OAAO,CACN,cAAK,SAAS,EAAE,UAAU,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,CAAC,YACnE,eAAM,SAAS,EAAC,OAAO,YACrB,GAAG,CAAC,CAAC,mBAAmB,MAAM,CAAC,CAAC,mBAAmB,KAAK,KAAK,GAAG,GAC3D,GACF,CACN,CAAC;IACH,CAAC;IAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACxD,OAAO,CACN,eAAK,SAAS,EAAE,UAAU,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,CAAC,aACnE,eAAM,SAAS,EAAC,IAAI,YAAE,EAAE,IAAI,KAAK,GAAQ,EACzC,iCAAgB,EAChB,eAAM,SAAS,EAAC,OAAO,YAAE,KAAK,GAAQ,IACjC,CACN,CAAC;IACH,CAAC;IACD,OAAO,CACN,cAAK,SAAS,EAAE,UAAU,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,CAAC,YACnE,eAAM,SAAS,EAAC,IAAI,YAAE,EAAE,GAAQ,GAC3B,CACN,CAAC;AACH,CAAC,CACD,CAAC"}
|
|
@@ -2,4 +2,4 @@ import type { ComboboxPanelProps } from '../ComboboxType';
|
|
|
2
2
|
/**
|
|
3
3
|
* Floating menu containing selectable options
|
|
4
4
|
*/
|
|
5
|
-
export declare function ComboboxPanel({ optionRenderer: OptionRender, options, focused, selectedIndex, expanded, id, search, onSelect, }: ComboboxPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function ComboboxPanel({ optionRenderer: OptionRender, options, focused, selectedIndex, expanded, id, search, onSelect, isLoading, }: ComboboxPanelProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -2,12 +2,26 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { ComboboxOptionContainer } from './ComboboxOptionContainer';
|
|
3
3
|
import { ComboboxPanelContainer } from './ComboboxPanelContainer';
|
|
4
4
|
import { ComboboxOption } from './ComboboxOption';
|
|
5
|
+
import D from '../../../../i18n';
|
|
5
6
|
/**
|
|
6
7
|
* Floating menu containing selectable options
|
|
7
8
|
*/
|
|
8
|
-
export function ComboboxPanel({ optionRenderer: OptionRender, options = [], focused, selectedIndex, expanded, id, search, onSelect, }) {
|
|
9
|
+
export function ComboboxPanel({ optionRenderer: OptionRender, options = [], focused, selectedIndex, expanded, id, search, onSelect, isLoading, }) {
|
|
9
10
|
const visibleOptions = expanded ? options : [];
|
|
10
11
|
const ComboBoxOptionComponent = OptionRender ?? ComboboxOption;
|
|
12
|
+
// Do not display the panel if it's empty
|
|
13
|
+
if (visibleOptions.length === 0 && !search) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (isLoading) {
|
|
17
|
+
return (_jsx(ComboboxPanelContainer, { expanded: expanded, focused: focused, id: `${id}-list`, children: _jsx("div", { className: "lunatic-combo-box-option", children: _jsx("span", { className: "label", children: D.SUGGESTER_LOADING }) }) }));
|
|
18
|
+
}
|
|
19
|
+
if (search && visibleOptions.length === 0) {
|
|
20
|
+
return (_jsx(ComboboxPanelContainer, { expanded: expanded, focused: focused, id: `${id}-list`, children: _jsx("div", { className: "lunatic-combo-box-option", children: _jsx("span", { className: "label", children: D.SUGGESTER_NO_RESULT }) }) }));
|
|
21
|
+
}
|
|
22
|
+
if (visibleOptions.length === 0) {
|
|
23
|
+
return (_jsx(ComboboxPanelContainer, { expanded: expanded, focused: focused, id: `${id}-list`, children: _jsx("div", { className: "lunatic-combo-box-option", children: _jsx("span", { className: "label", children: D.SUGGESTER_NO_RESULT }) }) }));
|
|
24
|
+
}
|
|
11
25
|
return (_jsx(ComboboxPanelContainer, { expanded: expanded, focused: focused, id: `${id}-list`, children: visibleOptions.map((option, index) => (_jsx(ComboboxOptionContainer, { index: index.toString(), selected: selectedIndex === index, onSelect: onSelect, children: _jsx(ComboBoxOptionComponent, { option: option, selected: selectedIndex === index, search: search }) }, option.id ?? option.value))) }));
|
|
12
26
|
}
|
|
13
27
|
//# sourceMappingURL=ComboboxPanel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxPanel.js","sourceRoot":"","sources":["../../../../../../src/components/shared/Combobox/Panel/ComboboxPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ComboboxPanel.js","sourceRo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E,CAAC,CAAC,mBAAmB,GAAQ,GACjD,GACkB,CACzB,CAAC;IACH,CAAC;IAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,CACN,KAAC,sBAAsB,IACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,GAAG,EAAE,OAAO,YAEhB,cAAK,SAAS,EAAC,0BAA0B,YACxC,eAAM,SAAS,EAAC,OAAO,YAAE,CAAC,CAAC,mBAAmB,GAAQ,GACjD,GACkB,CACzB,CAAC;IACH,CAAC;IAED,OAAO,CACN,KAAC,sBAAsB,IACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,GAAG,EAAE,OAAO,YAEf,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CACtC,KAAC,uBAAuB,IAEvB,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EACvB,QAAQ,EAAE,aAAa,KAAK,KAAK,EACjC,QAAQ,EAAE,QAAQ,YAElB,KAAC,uBAAuB,IACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,aAAa,KAAK,KAAK,EACjC,MAAM,EAAE,MAAM,GACb,IATG,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,CAUL,CAC1B,CAAC,GACsB,CACzB,CAAC;AACH,CAAC"}
|
|
@@ -13,6 +13,12 @@ function getContent(option, search, placeholder) {
|
|
|
13
13
|
}
|
|
14
14
|
const LunaticComboBoxLabelSelection = ({ option, placeholder, search, disabled = false, readOnly = false, }) => {
|
|
15
15
|
const isPlaceholder = !option && (!search || search.length === 0);
|
|
16
|
+
if (option?.value === 'OTHER') {
|
|
17
|
+
return (_jsx("div", { className: classNames('lunatic-combo-box-selected', {
|
|
18
|
+
disabled,
|
|
19
|
+
readOnly,
|
|
20
|
+
}), children: _jsx("span", { className: "selection", children: option.label }) }));
|
|
21
|
+
}
|
|
16
22
|
return (_jsx("div", { className: classNames('lunatic-combo-box-selected', {
|
|
17
23
|
disabled,
|
|
18
24
|
readOnly,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxLabelSelection.js","sourceRoot":"","sources":["../../../../../../src/components/shared/Combobox/Selection/ComboboxLabelSelection.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAUlE,SAAS,UAAU,CAClB,MAAuB,EACvB,MAAwB,EACxB,WAAoB;IAEpB,IAAI,MAAM,EAAE,CAAC;QACZ,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QACpC,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC;IAC1D,CAAC;IACD,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,WAAW,IAAI,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,6BAA6B,GAAG,CAAC,EACtC,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,GACT,EAAE,EAAE;IACX,MAAM,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;IAClE,OAAO,CACN,cACC,SAAS,EAAE,UAAU,CAAC,4BAA4B,EAAE;YACnD,QAAQ;YACR,QAAQ;SACR,CAAC,YAEF,eACC,SAAS,EAAE,UAAU,CAAC;gBACrB,WAAW,EAAE,aAAa;gBAC1B,SAAS,EAAE,CAAC,aAAa;aACzB,CAAC,YAED,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,GAClC,GACF,CACN,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CACvD,wBAAwB,EACxB,6BAA6B,CAC7B,CAAC"}
|
|
1
|
+
{"version":3,"file":"ComboboxLabelSelection.js","sourceRoot":"","sources":["../../../../../../src/components/shared/Combobox/Selection/ComboboxLabelSelection.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAUlE,SAAS,UAAU,CAClB,MAAuB,EACvB,MAAwB,EACxB,WAAoB;IAEpB,IAAI,MAAM,EAAE,CAAC;QACZ,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QACpC,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC;IAC1D,CAAC;IACD,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,WAAW,IAAI,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,6BAA6B,GAAG,CAAC,EACtC,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,GACT,EAAE,EAAE;IACX,MAAM,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;IAClE,IAAI,MAAM,EAAE,KAAK,KAAK,OAAO,EAAE,CAAC;QAC/B,OAAO,CACN,cACC,SAAS,EAAE,UAAU,CAAC,4BAA4B,EAAE;gBACnD,QAAQ;gBACR,QAAQ;aACR,CAAC,YAEF,eAAM,SAAS,EAAC,WAAW,YAAE,MAAM,CAAC,KAAK,GAAQ,GAC5C,CACN,CAAC;IACH,CAAC;IACD,OAAO,CACN,cACC,SAAS,EAAE,UAAU,CAAC,4BAA4B,EAAE;YACnD,QAAQ;YACR,QAAQ;SACR,CAAC,YAEF,eACC,SAAS,EAAE,UAAU,CAAC;gBACrB,WAAW,EAAE,aAAa;gBAC1B,SAAS,EAAE,CAAC,aAAa;aACzB,CAAC,YAED,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,GAClC,GACF,CACN,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CACvD,wBAAwB,EACxB,6BAA6B,CAC7B,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CSSProperties, FunctionComponent, ReactNode } from 'react';
|
|
2
2
|
import useLunatic from '../use-lunatic';
|
|
3
|
-
import type { FilledLunaticComponentProps } from '../use-lunatic/commons/fill-components/fill-components';
|
|
4
3
|
import type { LunaticComponentDefinition, LunaticError, LunaticState } from '../use-lunatic/type';
|
|
5
4
|
import { SuggesterStatus } from '../use-lunatic/use-suggesters';
|
|
6
5
|
type Formats = 'PTnHnM' | 'PnYnM';
|
|
@@ -40,7 +39,6 @@ export type LunaticBaseProps<ValueType = unknown> = {
|
|
|
40
39
|
label: ReactNode;
|
|
41
40
|
}[];
|
|
42
41
|
features?: string[];
|
|
43
|
-
componentType?: string;
|
|
44
42
|
goNextPage?: () => void;
|
|
45
43
|
goPreviousPage?: () => void;
|
|
46
44
|
};
|
|
@@ -57,7 +55,7 @@ export type SuggesterOption = {
|
|
|
57
55
|
fields: string[];
|
|
58
56
|
}>;
|
|
59
57
|
};
|
|
60
|
-
type ComponentPropsByType = {
|
|
58
|
+
export type ComponentPropsByType = {
|
|
61
59
|
InputNumber: LunaticBaseProps<number | null> & {
|
|
62
60
|
min?: number;
|
|
63
61
|
max?: number;
|
|
@@ -66,12 +64,14 @@ type ComponentPropsByType = {
|
|
|
66
64
|
response: {
|
|
67
65
|
name: string;
|
|
68
66
|
};
|
|
67
|
+
componentType?: 'InputNumber';
|
|
69
68
|
};
|
|
70
69
|
Duration: LunaticBaseProps<string | null> & {
|
|
71
70
|
format: Formats;
|
|
72
71
|
response: {
|
|
73
72
|
name: string;
|
|
74
73
|
};
|
|
74
|
+
componentType?: 'Duration';
|
|
75
75
|
};
|
|
76
76
|
Input: LunaticBaseProps<string> & {
|
|
77
77
|
maxLength?: number;
|
|
@@ -79,11 +79,17 @@ type ComponentPropsByType = {
|
|
|
79
79
|
response: {
|
|
80
80
|
name: string;
|
|
81
81
|
};
|
|
82
|
+
componentType?: 'Input';
|
|
83
|
+
};
|
|
84
|
+
Sequence: Pick<LunaticBaseProps<string>, 'id' | 'label' | 'style' | 'declarations' | 'description'> & {
|
|
85
|
+
componentType?: 'Sequence';
|
|
86
|
+
};
|
|
87
|
+
Subsequence: Pick<LunaticBaseProps<string>, 'id' | 'label' | 'declarations'> & {
|
|
88
|
+
componentType?: 'Subsequence';
|
|
82
89
|
};
|
|
83
|
-
Sequence: Pick<LunaticBaseProps<string>, 'id' | 'label' | 'style' | 'declarations' | 'description'>;
|
|
84
|
-
Subsequence: Pick<LunaticBaseProps<string>, 'id' | 'label' | 'declarations'>;
|
|
85
90
|
Question: Pick<LunaticBaseProps<unknown>, 'label' | 'id' | 'description' | 'declarations'> & {
|
|
86
|
-
components:
|
|
91
|
+
components: LunaticComponentProps[];
|
|
92
|
+
componentType?: 'Question';
|
|
87
93
|
};
|
|
88
94
|
RosterForLoop: LunaticBaseProps<unknown> & {
|
|
89
95
|
lines: {
|
|
@@ -91,7 +97,7 @@ type ComponentPropsByType = {
|
|
|
91
97
|
max: number;
|
|
92
98
|
};
|
|
93
99
|
iterations: number;
|
|
94
|
-
getComponents: (n: number) =>
|
|
100
|
+
getComponents: (n: number) => LunaticComponentProps[];
|
|
95
101
|
executeExpression: LunaticState['executeExpression'];
|
|
96
102
|
value: Record<string, unknown[]>;
|
|
97
103
|
header?: Array<{
|
|
@@ -100,6 +106,7 @@ type ComponentPropsByType = {
|
|
|
100
106
|
colspan?: number;
|
|
101
107
|
}>;
|
|
102
108
|
paginatedLoop?: boolean;
|
|
109
|
+
componentType?: 'RosterForLoop';
|
|
103
110
|
};
|
|
104
111
|
Loop: LunaticBaseProps<unknown> & {
|
|
105
112
|
lines: {
|
|
@@ -107,13 +114,14 @@ type ComponentPropsByType = {
|
|
|
107
114
|
max: number;
|
|
108
115
|
};
|
|
109
116
|
iterations: number;
|
|
110
|
-
getComponents: (n: number) =>
|
|
117
|
+
getComponents: (n: number) => LunaticComponentProps[];
|
|
111
118
|
executeExpression: LunaticState['executeExpression'];
|
|
112
119
|
value: Record<string, unknown[]>;
|
|
113
120
|
header?: Array<{
|
|
114
121
|
label: ReactNode;
|
|
115
122
|
}>;
|
|
116
123
|
paginatedLoop?: boolean;
|
|
124
|
+
componentType?: 'Loop';
|
|
117
125
|
};
|
|
118
126
|
Table: LunaticBaseProps<unknown> & {
|
|
119
127
|
value: Record<string, unknown>;
|
|
@@ -122,12 +130,13 @@ type ComponentPropsByType = {
|
|
|
122
130
|
rowspan?: number;
|
|
123
131
|
colspan?: number;
|
|
124
132
|
}>;
|
|
125
|
-
body: (
|
|
133
|
+
body: (LunaticComponentProps & {
|
|
126
134
|
colspan?: number;
|
|
127
135
|
rowspan?: number;
|
|
128
136
|
})[][];
|
|
129
137
|
executeExpression: LunaticState['executeExpression'];
|
|
130
138
|
iteration: LunaticState['pager']['iteration'];
|
|
139
|
+
componentType?: 'Table';
|
|
131
140
|
};
|
|
132
141
|
Datepicker: LunaticBaseProps<string | null> & {
|
|
133
142
|
dateFormat: 'YYYY-MM-DD' | 'YYYY-MM' | 'YYYY';
|
|
@@ -136,6 +145,7 @@ type ComponentPropsByType = {
|
|
|
136
145
|
response: {
|
|
137
146
|
name: string;
|
|
138
147
|
};
|
|
148
|
+
componentType?: 'Datepicker';
|
|
139
149
|
};
|
|
140
150
|
CheckboxGroup: LunaticBaseProps<Record<string, boolean | null>> & {
|
|
141
151
|
responses: Array<{
|
|
@@ -149,6 +159,7 @@ type ComponentPropsByType = {
|
|
|
149
159
|
handleChange: (response: {
|
|
150
160
|
name: string;
|
|
151
161
|
}, value: boolean, args?: Record<string, unknown>) => void;
|
|
162
|
+
componentType?: 'CheckboxGroup';
|
|
152
163
|
};
|
|
153
164
|
CheckboxOne: LunaticBaseProps<string | null> & {
|
|
154
165
|
options: Array<{
|
|
@@ -159,6 +170,7 @@ type ComponentPropsByType = {
|
|
|
159
170
|
response: {
|
|
160
171
|
name: string;
|
|
161
172
|
};
|
|
173
|
+
componentType?: 'CheckboxOne';
|
|
162
174
|
};
|
|
163
175
|
Switch: LunaticBaseProps<boolean> & {
|
|
164
176
|
response: {
|
|
@@ -168,11 +180,13 @@ type ComponentPropsByType = {
|
|
|
168
180
|
true: string;
|
|
169
181
|
false: string;
|
|
170
182
|
};
|
|
183
|
+
componentType?: 'Switch';
|
|
171
184
|
};
|
|
172
185
|
CheckboxBoolean: LunaticBaseProps<boolean> & {
|
|
173
186
|
response: {
|
|
174
187
|
name: string;
|
|
175
188
|
};
|
|
189
|
+
componentType?: 'CheckboxBoolean';
|
|
176
190
|
};
|
|
177
191
|
Radio: LunaticBaseProps<string | null> & {
|
|
178
192
|
options: Array<{
|
|
@@ -184,6 +198,7 @@ type ComponentPropsByType = {
|
|
|
184
198
|
response: {
|
|
185
199
|
name: string;
|
|
186
200
|
};
|
|
201
|
+
componentType?: 'Radio';
|
|
187
202
|
};
|
|
188
203
|
Roundabout: LunaticBaseProps<string> & {
|
|
189
204
|
iterations: number;
|
|
@@ -196,6 +211,7 @@ type ComponentPropsByType = {
|
|
|
196
211
|
partial?: Array<boolean>;
|
|
197
212
|
label?: Array<string>;
|
|
198
213
|
};
|
|
214
|
+
componentType?: 'Roundabout';
|
|
199
215
|
};
|
|
200
216
|
Dropdown: LunaticBaseProps<string | null> & {
|
|
201
217
|
options: Array<{
|
|
@@ -206,6 +222,7 @@ type ComponentPropsByType = {
|
|
|
206
222
|
response: {
|
|
207
223
|
name: string;
|
|
208
224
|
};
|
|
225
|
+
componentType?: 'Dropdown';
|
|
209
226
|
};
|
|
210
227
|
Textarea: LunaticBaseProps<string> & {
|
|
211
228
|
cols?: number;
|
|
@@ -215,8 +232,11 @@ type ComponentPropsByType = {
|
|
|
215
232
|
response: {
|
|
216
233
|
name: string;
|
|
217
234
|
};
|
|
235
|
+
componentType?: 'Textarea';
|
|
236
|
+
};
|
|
237
|
+
FilterDescription: Pick<LunaticBaseProps<string>, 'id' | 'label'> & {
|
|
238
|
+
componentType?: 'FilterDescription';
|
|
218
239
|
};
|
|
219
|
-
FilterDescription: Pick<LunaticBaseProps<string>, 'id' | 'label'>;
|
|
220
240
|
PairwiseLinks: Omit<LunaticBaseProps, 'value'> & {
|
|
221
241
|
components: LunaticComponentDefinition[];
|
|
222
242
|
features?: LunaticState['features'];
|
|
@@ -225,9 +245,11 @@ type ComponentPropsByType = {
|
|
|
225
245
|
yAxisIterations: number;
|
|
226
246
|
symLinks: Record<string, Record<string, string>>;
|
|
227
247
|
value: Record<string, unknown[]>;
|
|
228
|
-
getComponents: (x: number, y: number) =>
|
|
248
|
+
getComponents: (x: number, y: number) => LunaticComponentProps[];
|
|
249
|
+
componentType?: 'PairwiseLinks';
|
|
229
250
|
};
|
|
230
251
|
Suggester: LunaticBaseProps<string | null> & {
|
|
252
|
+
componentType?: 'Suggester';
|
|
231
253
|
storeName: string;
|
|
232
254
|
workersBasePath?: string;
|
|
233
255
|
getSuggesterStatus: (name: string) => {
|
|
@@ -253,10 +275,18 @@ type ComponentPropsByType = {
|
|
|
253
275
|
name: string;
|
|
254
276
|
attribute: string;
|
|
255
277
|
}[];
|
|
278
|
+
arbitrary: {
|
|
279
|
+
response: {
|
|
280
|
+
name: string;
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
arbitraryValue?: string;
|
|
284
|
+
allowArbitrary?: boolean;
|
|
256
285
|
executeExpression: LunaticState['executeExpression'];
|
|
257
286
|
iteration: LunaticState['pager']['iteration'];
|
|
258
287
|
};
|
|
259
288
|
Summary: LunaticBaseProps<string | null> & {
|
|
289
|
+
componentType?: 'Summary';
|
|
260
290
|
executeExpression: LunaticState['executeExpression'];
|
|
261
291
|
sections: Array<{
|
|
262
292
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/components/type.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/components/type.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,gBAAgB,CAAC;AAMxC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-track-changes.js","sourceRoot":"","sources":["../../../src/hooks/use-track-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"use-track-changes.js","sourceRoot":"","sources":["../../../src/hooks/use-track-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO1C;;GAEG;AACH,MAAM,UAAU,eAAe,CAC9B,OAAgB,EAChB,KAA4B,EAC5B,OAAyC;IAEzC,qCAAqC;IACrC,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAU,CAAC,CAAC;IACnD,+CAA+C;IAC/C,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,CA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extends unknown[], R = void>(fn: (...args: A) => R, ms: number) => (...args: A) => Promise<R>;
|
|
3
|
+
export declare const useDebouncedState: <A>(initialState: A, ms: number) => [A, (args: A) => void];
|
|
4
|
+
export declare const useEffectDebounced: (cb: () => void, deps: DependencyList, ms: number) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { debounce } from '../utils/function';
|
|
3
|
+
import { useRefSync } from './useRefSync';
|
|
4
|
+
export const useDebounce = (fn, ms) => {
|
|
5
|
+
const fnRef = useRefSync(fn);
|
|
6
|
+
const [debouncedFun, teardown] = useMemo(() => {
|
|
7
|
+
return debounce((...args) => fnRef.current(...args), ms);
|
|
8
|
+
}, []);
|
|
9
|
+
useEffect(() => teardown, []);
|
|
10
|
+
return debouncedFun;
|
|
11
|
+
};
|
|
12
|
+
export const useDebouncedState = (initialState, ms) => {
|
|
13
|
+
const [state, setState] = useState(initialState);
|
|
14
|
+
const debounceSetState = useDebounce(setState, ms);
|
|
15
|
+
return [state, debounceSetState];
|
|
16
|
+
};
|
|
17
|
+
export const useEffectDebounced = (cb, deps, ms) => {
|
|
18
|
+
const debouncedCb = useDebounce(cb, ms);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
debouncedCb().catch(console.error);
|
|
21
|
+
}, deps);
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=useDebounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../../../src/hooks/useDebounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,EAAqB,EACrB,EAAU,EACqB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