@inseefr/lunatic 0.2.2-experimental → 0.2.3-prisme
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/LICENSE +21 -21
- package/README.md +25 -23
- package/lib/index.js +1191 -475
- package/lib/index.js.map +1 -1
- package/package.json +174 -172
- package/src/components/breadcrumb/breadcrumb.scss +22 -22
- package/src/components/checkbox/boolean.js +172 -172
- package/src/components/checkbox/checkbox.scss +73 -73
- package/src/components/checkbox/group.js +231 -231
- package/src/components/checkbox/one.js +11 -11
- package/src/components/component-wrapper/controls/component.js +70 -0
- package/src/components/component-wrapper/controls/controls.scss +6 -0
- package/src/components/component-wrapper/controls/index.js +1 -0
- package/src/components/component-wrapper/controls/validators/datepicker.js +44 -0
- package/src/components/component-wrapper/controls/validators/index.js +16 -0
- package/src/components/component-wrapper/controls/validators/input-number.js +23 -0
- package/src/components/{missing-wrapper → component-wrapper}/index.js +0 -0
- package/src/components/component-wrapper/missing/component.js +200 -0
- package/src/components/component-wrapper/missing/index.js +1 -0
- package/src/components/{missing-wrapper → component-wrapper/missing}/missing.scss +32 -32
- package/src/components/component-wrapper/wrapper.js +23 -0
- package/src/components/components.js +1 -0
- package/src/components/datepicker/component.js +26 -11
- package/src/components/declarations/component.js +46 -46
- package/src/components/declarations/declarations.scss +40 -40
- package/src/components/declarations/wrappers/input-declarations-wrapper.js +328 -274
- package/src/components/declarations/wrappers/simple-declarations-wrapper.js +54 -54
- package/src/components/dropdown/commons/actions.js +65 -56
- package/src/components/dropdown/commons/children-to-option.js +9 -9
- package/src/components/dropdown/commons/cleaner-callbacks.js +58 -58
- package/src/components/dropdown/commons/components/dropdown-container.js +29 -29
- package/src/components/dropdown/commons/components/dropdown.js +204 -183
- package/src/components/dropdown/commons/event-callbacks/on-mousedown-callback.js +15 -15
- package/src/components/dropdown/commons/reducer.js +3 -0
- package/src/components/dropdown/commons/tools/index.js +17 -17
- package/src/components/dropdown/component.js +135 -135
- package/src/components/dropdown/dropdown-edit/dropdown-edit.js +194 -185
- package/src/components/dropdown/dropdown-edit/index.js +11 -11
- package/src/components/dropdown/dropdown-simple/dropdown.js +173 -164
- package/src/components/dropdown/dropdown-simple/index.js +20 -20
- package/src/components/dropdown/dropdown.scss +178 -178
- package/src/components/icon/icon.scss +15 -15
- package/src/components/index.js +2 -0
- package/src/components/index.scss +177 -175
- package/src/components/input/input-number.js +30 -54
- package/src/components/input/input.js +11 -11
- package/src/components/input/input.scss +31 -37
- package/src/components/loop/component.js +170 -169
- package/src/components/loop/loop.scss +13 -13
- package/src/components/loop/wrapper.js +1 -1
- package/src/components/loop-constructor/block/block.scss +10 -10
- package/src/components/loop-constructor/block/component.js +9 -9
- package/src/components/loop-constructor/roster/component.js +8 -8
- package/src/components/loop-constructor/wrapper/body-component.js +146 -125
- package/src/components/modal/component.js +36 -0
- package/src/components/modal/index.js +1 -0
- package/src/components/modal/modal.scss +33 -0
- package/src/components/progress-bar/progress-bar.scss +54 -54
- package/src/components/radio/component.js +9 -9
- package/src/components/radio/radio.scss +59 -59
- package/src/components/sequence/component.js +50 -50
- package/src/components/sequence/sequence.scss +10 -10
- package/src/components/subsequence/component.js +49 -49
- package/src/components/suggester/check-store.js +2 -4
- package/src/components/suggester/components/panel/default-option-renderer.js +27 -27
- package/src/components/suggester/components/panel/option-container.js +61 -61
- package/src/components/suggester/components/panel/panel.js +47 -47
- package/src/components/suggester/components/selection/default-label-renderer.js +31 -31
- package/src/components/suggester/components/selection/label.js +35 -35
- package/src/components/suggester/components/selection/selection.js +50 -50
- package/src/components/suggester/components/suggester-content.js +2 -2
- package/src/components/suggester/components/suggester.js +128 -88
- package/src/components/suggester/components/suggester.scss +101 -101
- package/src/components/suggester/default-style.scss +125 -125
- package/src/components/suggester/find-best-label/find-best-label.js +51 -49
- package/src/components/suggester/find-best-label/index.js +1 -1
- package/src/components/suggester/idb-suggester.js +73 -67
- package/src/components/suggester/lunatic-suggester.js +140 -137
- package/src/components/suggester/searching/create-searching.js +49 -47
- package/src/components/suggester/searching/index.js +1 -1
- package/src/components/suggester/state-management/actions.js +38 -38
- package/src/components/suggester/state-management/reducer/reduce-on-delete-search.js +11 -11
- package/src/components/suggester/state-management/reducer/reduce-on-init.js +29 -29
- package/src/components/suggester/state-management/reducer/reducer.js +38 -38
- package/src/components/suggester/suggester-wrapper.js +127 -121
- package/src/components/suggester-loader-widget/loader.js +67 -67
- package/src/components/suggester-loader-widget/widget.js +123 -123
- package/src/components/table/table.js +173 -171
- package/src/components/table/table.scss +26 -26
- package/src/components/textarea/component.js +11 -11
- package/src/components/textarea/textarea.scss +8 -8
- package/src/components/tooltip/tooltip.scss +30 -30
- package/src/stories/checkbox-boolean/data.json +78 -78
- package/src/stories/datepicker/data.json +3 -1
- package/src/stories/dropdown/README.md +44 -44
- package/src/stories/dropdown/data.json +98 -98
- package/src/stories/dropdown/dropdown.stories.js +89 -89
- package/src/stories/progress-bar/progress-bar.stories.js +24 -24
- package/src/stories/questionnaire/arithmetic-management.json +47 -0
- package/src/stories/questionnaire/arithmetic.json +247 -247
- package/src/stories/questionnaire/kish.json +275 -0
- package/src/stories/questionnaire/logement-queen.json +23390 -0
- package/src/stories/questionnaire/logement-s2.json +46028 -0
- package/src/stories/questionnaire/logement.json +20347 -26087
- package/src/stories/questionnaire/loop-and-controls.json +481 -0
- package/src/stories/questionnaire/questionnaire.stories.js +236 -138
- package/src/stories/questionnaire/update-external/data.json +1 -0
- package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
- package/src/stories/suggester/README.md +46 -46
- package/src/stories/suggester/bailleurs-sociaux/fetch-bailleurs.js +15 -15
- package/src/stories/suggester/bailleurs-sociaux/index.js +2 -2
- package/src/stories/suggester/bailleurs-sociaux/option-bailleur-renderer.js +58 -58
- package/src/stories/suggester/bailleurs-sociaux/preloader.svg +51 -51
- package/src/stories/suggester/bailleurs-sociaux/theme.scss +22 -22
- package/src/stories/suggester/bailleurs-sociaux-2021/fetch-bailleurs.js +12 -0
- package/src/stories/suggester/bailleurs-sociaux-2021/index.js +1 -0
- package/src/stories/suggester/cog-communes/fetch-cog.js +15 -15
- package/src/stories/suggester/data-auto.json +232 -231
- package/src/stories/suggester/data-vtl.json +82 -82
- package/src/stories/suggester/data.json +169 -136
- package/src/stories/suggester/naf-rev2/index.js +2 -2
- package/src/stories/suggester/naf-rev2/option-naf-renderer.js +17 -17
- package/src/stories/suggester/suggester-workers.stories.js +226 -179
- package/src/stories/suggester/suggester.stories.js +138 -133
- package/src/stories/utils/orchestrator-split.js +119 -0
- package/src/stories/utils/orchestrator.js +119 -108
- package/src/tests/components/input-number.spec.js +6 -12
- package/src/tests/components/missing-wrapper.spec.js +0 -1
- package/src/tests/utils/lib/table/roster.spec.js +25 -25
- package/src/tests/utils/to-expose/handler/results/res-input-edited.json +1 -1
- package/src/utils/components/dragger/dragger.scss +7 -7
- package/src/utils/idb-tools/create-db-opener.js +43 -43
- package/src/utils/idb-tools/create-open-db.js +25 -25
- package/src/utils/idb-tools/idb-bulk-insert.js +96 -96
- package/src/utils/idb-tools/index.js +10 -10
- package/src/utils/idb-tools/insert-entity.js +15 -15
- package/src/utils/idb-tools/open-db.js +13 -13
- package/src/utils/idb-tools/open-or-create-db.js +34 -34
- package/src/utils/lib/controls/index.js +1 -0
- package/src/utils/lib/controls/utils.js +152 -0
- package/src/utils/lib/decorator/title-decorator.js +16 -16
- package/src/utils/lib/env.js +2 -2
- package/src/utils/lib/index.js +2 -0
- package/src/utils/lib/input-number.js +1 -1
- package/src/utils/lib/options-positioning.js +9 -9
- package/src/utils/lib/pagination/navigation/shared.js +12 -9
- package/src/utils/lib/prop-types/lines.js +6 -6
- package/src/utils/lib/responses.js +11 -9
- package/src/utils/lib/splitting.js +142 -0
- package/src/utils/lib/style.js +10 -10
- package/src/utils/store-tools/auto-load.js +74 -73
- package/src/utils/suggester-workers/append-to-index/append.js +25 -25
- package/src/utils/suggester-workers/append-to-index/append.worker.js +16 -16
- package/src/utils/suggester-workers/append-to-index/create-append-task.js +45 -43
- package/src/utils/suggester-workers/append-to-index/index.js +2 -2
- package/src/utils/suggester-workers/append-to-index/prepare-entities.js +61 -61
- package/src/utils/suggester-workers/append-to-index/store-messages.js +21 -21
- package/src/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +56 -0
- package/src/utils/suggester-workers/commons-tokenizer/create-fields-tokenizer.js +56 -0
- package/src/utils/suggester-workers/commons-tokenizer/create-filter-stop-words.js +17 -17
- package/src/utils/suggester-workers/commons-tokenizer/filters/compose-filters.js +10 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.js +17 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.spec.js +14 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-accents.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-accents.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/{filter-double.js → filters/filter-double.js} +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-double.spec.js +20 -0
- package/src/utils/suggester-workers/commons-tokenizer/{filter-length.js → filters/filter-length.js} +7 -7
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-length.spec.js +18 -0
- package/src/utils/suggester-workers/commons-tokenizer/{filter-stemmer.js → filters/filter-stemmer.js} +13 -13
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +36 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +10 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/index.js +2 -0
- package/src/utils/suggester-workers/commons-tokenizer/{stop-words.js → filters/stop-words.js} +118 -118
- package/src/utils/suggester-workers/commons-tokenizer/get-regexp-from-pattern.js +8 -8
- package/src/utils/suggester-workers/commons-tokenizer/get-stemmer.js +18 -18
- package/src/utils/suggester-workers/commons-tokenizer/index.js +9 -8
- package/src/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.js +13 -9
- package/src/utils/suggester-workers/commons-tokenizer/soft-tokenizer.js +7 -7
- package/src/utils/suggester-workers/create-worker.js +56 -0
- package/src/utils/suggester-workers/find-best-label/find-best-label.js +39 -39
- package/src/utils/suggester-workers/find-best-label/find-best-label.worker.js +40 -40
- package/src/utils/suggester-workers/find-best-label/tokenize.js +30 -33
- package/src/utils/suggester-workers/find-best-label/tokenize.spec.js +19 -19
- package/src/utils/suggester-workers/searching/compute-score.js +33 -33
- package/src/utils/suggester-workers/searching/get-db.js +18 -18
- package/src/utils/suggester-workers/searching/index.js +1 -1
- package/src/utils/suggester-workers/searching/order/create-alphanumeric-orderer.js +20 -20
- package/src/utils/suggester-workers/searching/order/index.js +19 -19
- package/src/utils/suggester-workers/{query-parser → searching/query-parser}/index.js +2 -2
- package/src/utils/suggester-workers/searching/query-parser/query-parser-soft.js +7 -0
- package/src/utils/suggester-workers/{query-parser → searching/query-parser}/query-parser-soft.spec.js +24 -24
- package/src/utils/suggester-workers/searching/query-parser/query-parser-tokenized.js +34 -0
- package/src/utils/suggester-workers/searching/resolve-query-parser.js +27 -27
- package/src/utils/suggester-workers/searching/search-in-index.js +17 -17
- package/src/utils/suggester-workers/searching/searching.js +70 -70
- package/src/utils/suggester-workers/searching/searching.worker.js +11 -11
- package/src/utils/to-expose/calculated-variables.js +113 -113
- package/src/utils/to-expose/handler.js +149 -112
- package/src/utils/to-expose/hooks/filter-components.js +27 -12
- package/src/utils/to-expose/hooks/index.js +2 -1
- package/src/utils/to-expose/hooks/lunatic-split.js +428 -0
- package/src/utils/to-expose/hooks/lunatic.js +284 -187
- package/src/utils/to-expose/index.js +1 -1
- package/src/utils/to-expose/init-questionnaire.js +164 -164
- package/src/utils/to-expose/interpret/vtl.js +18 -18
- package/src/utils/to-expose/state.js +66 -58
- package/src/components/missing-wrapper/component.js +0 -120
- package/src/components/missing-wrapper/wrapper.js +0 -10
- package/src/tests/utils/to-expose/hooks/use-lunatic.spec.js +0 -46
- package/src/utils/suggester-workers/commons-tokenizer/create-tokenizer.js +0 -103
- package/src/utils/suggester-workers/commons-tokenizer/filter-accents-to-lower.js +0 -9
- package/src/utils/suggester-workers/commons-tokenizer/filter-synonyms.js +0 -10
- package/src/utils/suggester-workers/query-parser/query-parser-soft.js +0 -7
- package/src/utils/suggester-workers/query-parser/query-parser-tokenized.js +0 -31
- package/src/utils/suggester-workers/query-parser/query-parser-tokenized.spec.js +0 -32
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
4
|
-
import DropdownSimple from './dropdown-simple';
|
|
5
|
-
import DropdownEdit from './dropdown-edit';
|
|
6
|
-
import Declarations from '../declarations';
|
|
7
|
-
import * as U from '../../utils/lib';
|
|
8
|
-
import * as C from '../../constants';
|
|
9
|
-
import { interpret } from '../../utils/to-expose';
|
|
10
|
-
import './dropdown.scss';
|
|
11
|
-
|
|
12
|
-
function compileFeatures(features = []) {
|
|
13
|
-
return features.reduce((acc, f) => (f === 'MD' ? acc : [...acc, f]), []);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const Dropdown = ({
|
|
17
|
-
id,
|
|
18
|
-
label,
|
|
19
|
-
preferences,
|
|
20
|
-
response,
|
|
21
|
-
handleChange,
|
|
22
|
-
options,
|
|
23
|
-
writable,
|
|
24
|
-
declarations,
|
|
25
|
-
features,
|
|
26
|
-
bindings,
|
|
27
|
-
management,
|
|
28
|
-
freezeOptions,
|
|
29
|
-
...rest
|
|
30
|
-
}) => {
|
|
31
|
-
const [opts, setOpts] = useState(options);
|
|
32
|
-
|
|
33
|
-
//TODO: improve feature support for MD, adding plainText to options & search input
|
|
34
|
-
const updatedFeatures = useMemo(() => compileFeatures(features), [features]);
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!freezeOptions) {
|
|
38
|
-
const featOptions = options.map(
|
|
39
|
-
({ label: labelOption, ...restOpts }) => ({
|
|
40
|
-
label: interpret(updatedFeatures)(bindings)(labelOption),
|
|
41
|
-
...restOpts,
|
|
42
|
-
})
|
|
43
|
-
);
|
|
44
|
-
setOpts(featOptions);
|
|
45
|
-
}
|
|
46
|
-
}, [freezeOptions, updatedFeatures, features, bindings, options]);
|
|
47
|
-
|
|
48
|
-
const interpretedLabel = interpret(features, rest?.logFunction)(bindings)(
|
|
49
|
-
label
|
|
50
|
-
);
|
|
51
|
-
const value = U.getResponseByPreference(preferences)(response);
|
|
52
|
-
|
|
53
|
-
const onSelect = (e) =>
|
|
54
|
-
handleChange({
|
|
55
|
-
[U.getResponseName(response)]: e.value,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const DeclarationAfterLabel = () => (
|
|
59
|
-
<Declarations
|
|
60
|
-
id={id}
|
|
61
|
-
type={C.AFTER_QUESTION_TEXT}
|
|
62
|
-
declarations={declarations}
|
|
63
|
-
features={features}
|
|
64
|
-
bindings={bindings}
|
|
65
|
-
/>
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<>
|
|
70
|
-
<Declarations
|
|
71
|
-
id={id}
|
|
72
|
-
type={C.BEFORE_QUESTION_TEXT}
|
|
73
|
-
declarations={declarations}
|
|
74
|
-
features={features}
|
|
75
|
-
bindings={bindings}
|
|
76
|
-
/>
|
|
77
|
-
{writable ? (
|
|
78
|
-
<DropdownEdit
|
|
79
|
-
{...rest}
|
|
80
|
-
id={id}
|
|
81
|
-
value={value}
|
|
82
|
-
response={response}
|
|
83
|
-
label={interpretedLabel}
|
|
84
|
-
options={opts}
|
|
85
|
-
onSelect={onSelect}
|
|
86
|
-
management={management}
|
|
87
|
-
DeclarationAfterLabel={DeclarationAfterLabel}
|
|
88
|
-
/>
|
|
89
|
-
) : (
|
|
90
|
-
<DropdownSimple
|
|
91
|
-
{...rest}
|
|
92
|
-
id={id}
|
|
93
|
-
value={value}
|
|
94
|
-
response={response}
|
|
95
|
-
label={interpretedLabel}
|
|
96
|
-
options={opts}
|
|
97
|
-
onSelect={onSelect}
|
|
98
|
-
management={management}
|
|
99
|
-
DeclarationAfterLabel={DeclarationAfterLabel}
|
|
100
|
-
/>
|
|
101
|
-
)}
|
|
102
|
-
<Declarations
|
|
103
|
-
id={id}
|
|
104
|
-
type={C.DETACHABLE}
|
|
105
|
-
declarations={declarations}
|
|
106
|
-
features={features}
|
|
107
|
-
bindings={bindings}
|
|
108
|
-
/>
|
|
109
|
-
</>
|
|
110
|
-
);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
Dropdown.propTypes = {
|
|
114
|
-
disabled: PropTypes.bool,
|
|
115
|
-
writable: PropTypes.bool,
|
|
116
|
-
features: PropTypes.arrayOf(PropTypes.string),
|
|
117
|
-
handleChange: PropTypes.func,
|
|
118
|
-
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
119
|
-
className: PropTypes.string,
|
|
120
|
-
zIndex: PropTypes.number,
|
|
121
|
-
freezeOptions: PropTypes.bool,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
Dropdown.defaultProps = {
|
|
125
|
-
writable: false,
|
|
126
|
-
handleChange: () => null,
|
|
127
|
-
features: [],
|
|
128
|
-
label: undefined,
|
|
129
|
-
className: undefined,
|
|
130
|
-
zIndex: 0,
|
|
131
|
-
disabled: false,
|
|
132
|
-
freezeOptions: false,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export default
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import componentWrapper from '../component-wrapper';
|
|
4
|
+
import DropdownSimple from './dropdown-simple';
|
|
5
|
+
import DropdownEdit from './dropdown-edit';
|
|
6
|
+
import Declarations from '../declarations';
|
|
7
|
+
import * as U from '../../utils/lib';
|
|
8
|
+
import * as C from '../../constants';
|
|
9
|
+
import { interpret } from '../../utils/to-expose';
|
|
10
|
+
import './dropdown.scss';
|
|
11
|
+
|
|
12
|
+
function compileFeatures(features = []) {
|
|
13
|
+
return features.reduce((acc, f) => (f === 'MD' ? acc : [...acc, f]), []);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const Dropdown = ({
|
|
17
|
+
id,
|
|
18
|
+
label,
|
|
19
|
+
preferences,
|
|
20
|
+
response,
|
|
21
|
+
handleChange,
|
|
22
|
+
options,
|
|
23
|
+
writable,
|
|
24
|
+
declarations,
|
|
25
|
+
features,
|
|
26
|
+
bindings,
|
|
27
|
+
management,
|
|
28
|
+
freezeOptions,
|
|
29
|
+
...rest
|
|
30
|
+
}) => {
|
|
31
|
+
const [opts, setOpts] = useState(options);
|
|
32
|
+
|
|
33
|
+
//TODO: improve feature support for MD, adding plainText to options & search input
|
|
34
|
+
const updatedFeatures = useMemo(() => compileFeatures(features), [features]);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!freezeOptions) {
|
|
38
|
+
const featOptions = options.map(
|
|
39
|
+
({ label: labelOption, ...restOpts }) => ({
|
|
40
|
+
label: interpret(updatedFeatures)(bindings)(labelOption),
|
|
41
|
+
...restOpts,
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
setOpts(featOptions);
|
|
45
|
+
}
|
|
46
|
+
}, [freezeOptions, updatedFeatures, features, bindings, options]);
|
|
47
|
+
|
|
48
|
+
const interpretedLabel = interpret(features, rest?.logFunction)(bindings)(
|
|
49
|
+
label
|
|
50
|
+
);
|
|
51
|
+
const value = U.getResponseByPreference(preferences)(response);
|
|
52
|
+
|
|
53
|
+
const onSelect = (e) =>
|
|
54
|
+
handleChange({
|
|
55
|
+
[U.getResponseName(response)]: e.value,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const DeclarationAfterLabel = () => (
|
|
59
|
+
<Declarations
|
|
60
|
+
id={id}
|
|
61
|
+
type={C.AFTER_QUESTION_TEXT}
|
|
62
|
+
declarations={declarations}
|
|
63
|
+
features={features}
|
|
64
|
+
bindings={bindings}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<Declarations
|
|
71
|
+
id={id}
|
|
72
|
+
type={C.BEFORE_QUESTION_TEXT}
|
|
73
|
+
declarations={declarations}
|
|
74
|
+
features={features}
|
|
75
|
+
bindings={bindings}
|
|
76
|
+
/>
|
|
77
|
+
{writable ? (
|
|
78
|
+
<DropdownEdit
|
|
79
|
+
{...rest}
|
|
80
|
+
id={id}
|
|
81
|
+
value={value}
|
|
82
|
+
response={response}
|
|
83
|
+
label={interpretedLabel}
|
|
84
|
+
options={opts}
|
|
85
|
+
onSelect={onSelect}
|
|
86
|
+
management={management}
|
|
87
|
+
DeclarationAfterLabel={DeclarationAfterLabel}
|
|
88
|
+
/>
|
|
89
|
+
) : (
|
|
90
|
+
<DropdownSimple
|
|
91
|
+
{...rest}
|
|
92
|
+
id={id}
|
|
93
|
+
value={value}
|
|
94
|
+
response={response}
|
|
95
|
+
label={interpretedLabel}
|
|
96
|
+
options={opts}
|
|
97
|
+
onSelect={onSelect}
|
|
98
|
+
management={management}
|
|
99
|
+
DeclarationAfterLabel={DeclarationAfterLabel}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
<Declarations
|
|
103
|
+
id={id}
|
|
104
|
+
type={C.DETACHABLE}
|
|
105
|
+
declarations={declarations}
|
|
106
|
+
features={features}
|
|
107
|
+
bindings={bindings}
|
|
108
|
+
/>
|
|
109
|
+
</>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
Dropdown.propTypes = {
|
|
114
|
+
disabled: PropTypes.bool,
|
|
115
|
+
writable: PropTypes.bool,
|
|
116
|
+
features: PropTypes.arrayOf(PropTypes.string),
|
|
117
|
+
handleChange: PropTypes.func,
|
|
118
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
119
|
+
className: PropTypes.string,
|
|
120
|
+
zIndex: PropTypes.number,
|
|
121
|
+
freezeOptions: PropTypes.bool,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
Dropdown.defaultProps = {
|
|
125
|
+
writable: false,
|
|
126
|
+
handleChange: () => null,
|
|
127
|
+
features: [],
|
|
128
|
+
label: undefined,
|
|
129
|
+
className: undefined,
|
|
130
|
+
zIndex: 0,
|
|
131
|
+
disabled: false,
|
|
132
|
+
freezeOptions: false,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default componentWrapper(React.memo(Dropdown, U.areEqual));
|
|
@@ -1,185 +1,194 @@
|
|
|
1
|
-
import React, { useReducer, useRef, useEffect } from 'react';
|
|
2
|
-
import classnames from 'classnames';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import * as actions from '../commons/actions';
|
|
5
|
-
import Panel from '../commons/components/panel';
|
|
6
|
-
import DropdownContainer from '../commons/components/dropdown';
|
|
7
|
-
import { preparePrefix } from './prefix-tools';
|
|
8
|
-
import reducer, { initial } from '../commons/reducer';
|
|
9
|
-
import Option from './option';
|
|
10
|
-
import Icone from './icone';
|
|
11
|
-
|
|
12
|
-
/* **/
|
|
13
|
-
const isDisplay = ({ visible, visibleOptions }) =>
|
|
14
|
-
visible && visibleOptions.length > 0;
|
|
15
|
-
|
|
16
|
-
/** */
|
|
17
|
-
const onChangeCallback = (state, dispatch) => (e) => {
|
|
18
|
-
e.stopPropagation();
|
|
19
|
-
e.preventDefault();
|
|
20
|
-
const {
|
|
21
|
-
target: { value },
|
|
22
|
-
} = e;
|
|
23
|
-
dispatch(actions.setValue(value));
|
|
24
|
-
dispatch(actions.setPrefix(preparePrefix(value)));
|
|
25
|
-
if (value && value.length > 1) dispatch(actions.showPanel());
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/** */
|
|
29
|
-
const createOnSelect = (_, dispatch, onSelect) => (option) => {
|
|
30
|
-
dispatch(actions.setSelectedOption(option));
|
|
31
|
-
dispatch(actions.hidePanel());
|
|
32
|
-
onSelect(option);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param {props}
|
|
38
|
-
*/
|
|
39
|
-
function Dropdown({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
1
|
+
import React, { useReducer, useRef, useEffect } from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import * as actions from '../commons/actions';
|
|
5
|
+
import Panel from '../commons/components/panel';
|
|
6
|
+
import DropdownContainer from '../commons/components/dropdown';
|
|
7
|
+
import { preparePrefix } from './prefix-tools';
|
|
8
|
+
import reducer, { initial } from '../commons/reducer';
|
|
9
|
+
import Option from './option';
|
|
10
|
+
import Icone from './icone';
|
|
11
|
+
|
|
12
|
+
/* **/
|
|
13
|
+
const isDisplay = ({ visible, visibleOptions }) =>
|
|
14
|
+
visible && visibleOptions.length > 0;
|
|
15
|
+
|
|
16
|
+
/** */
|
|
17
|
+
const onChangeCallback = (state, dispatch) => (e) => {
|
|
18
|
+
e.stopPropagation();
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
const {
|
|
21
|
+
target: { value },
|
|
22
|
+
} = e;
|
|
23
|
+
dispatch(actions.setValue(value));
|
|
24
|
+
dispatch(actions.setPrefix(preparePrefix(value)));
|
|
25
|
+
if (value && value.length > 1) dispatch(actions.showPanel());
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** */
|
|
29
|
+
const createOnSelect = (_, dispatch, onSelect) => (option) => {
|
|
30
|
+
dispatch(actions.setSelectedOption(option));
|
|
31
|
+
dispatch(actions.hidePanel());
|
|
32
|
+
onSelect(option);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param {props}
|
|
38
|
+
*/
|
|
39
|
+
function Dropdown({
|
|
40
|
+
id: initId,
|
|
41
|
+
widthAuto,
|
|
42
|
+
options = [],
|
|
43
|
+
onSelect,
|
|
44
|
+
response,
|
|
45
|
+
className,
|
|
46
|
+
placeholderList,
|
|
47
|
+
label,
|
|
48
|
+
labelPosition,
|
|
49
|
+
mandatory,
|
|
50
|
+
value: valueFromProps,
|
|
51
|
+
zIndex,
|
|
52
|
+
management,
|
|
53
|
+
disabled,
|
|
54
|
+
focused: initFocused,
|
|
55
|
+
DeclarationAfterLabel,
|
|
56
|
+
logFunction,
|
|
57
|
+
}) {
|
|
58
|
+
const [state, dispatch] = useReducer(reducer, {
|
|
59
|
+
...initial,
|
|
60
|
+
id: `dropdown-${initId || new Date().getMilliseconds()}`,
|
|
61
|
+
disabled,
|
|
62
|
+
focused: initFocused,
|
|
63
|
+
});
|
|
64
|
+
const { prefix, visible, activeIndex, visibleOptions, value, focused, id } =
|
|
65
|
+
state;
|
|
66
|
+
const inputEl = useRef();
|
|
67
|
+
const containerEl = useRef();
|
|
68
|
+
const onSelect_ = createOnSelect(state, dispatch, onSelect);
|
|
69
|
+
|
|
70
|
+
const selectedOption = options.find((o) => o.label === value);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (visible && !activeIndex) {
|
|
74
|
+
dispatch(actions.initActiveIndex());
|
|
75
|
+
}
|
|
76
|
+
}, [activeIndex, visible]);
|
|
77
|
+
|
|
78
|
+
useEffect(
|
|
79
|
+
function () {
|
|
80
|
+
const { current } = inputEl;
|
|
81
|
+
if (current && focused) {
|
|
82
|
+
current.focus();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[inputEl, focused]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<DropdownContainer
|
|
90
|
+
className={className || 'lunatic-dropdown'}
|
|
91
|
+
state={state}
|
|
92
|
+
ref={containerEl}
|
|
93
|
+
dispatch={dispatch}
|
|
94
|
+
options={options}
|
|
95
|
+
label={label}
|
|
96
|
+
labelPosition={labelPosition}
|
|
97
|
+
mandatory={mandatory}
|
|
98
|
+
response={response}
|
|
99
|
+
onSelect={onSelect_}
|
|
100
|
+
value={valueFromProps}
|
|
101
|
+
zIndex={zIndex}
|
|
102
|
+
management={management}
|
|
103
|
+
logFunction={logFunction}
|
|
104
|
+
>
|
|
105
|
+
<DeclarationAfterLabel />
|
|
106
|
+
<span
|
|
107
|
+
className={classnames('lunatic-dropdown-input', { focused, disabled })}
|
|
108
|
+
>
|
|
109
|
+
<input
|
|
110
|
+
type="text"
|
|
111
|
+
ref={inputEl}
|
|
112
|
+
value={value || ''}
|
|
113
|
+
disabled={disabled}
|
|
114
|
+
placeholderList={placeholderList}
|
|
115
|
+
autoComplete="list"
|
|
116
|
+
autoCorrect="off"
|
|
117
|
+
autoCapitalize="off"
|
|
118
|
+
spellCheck="false"
|
|
119
|
+
tabIndex="0"
|
|
120
|
+
onChange={onChangeCallback(state, dispatch)}
|
|
121
|
+
/>
|
|
122
|
+
</span>
|
|
123
|
+
<Icone
|
|
124
|
+
prefix={prefix}
|
|
125
|
+
visible={visible}
|
|
126
|
+
disabled={disabled}
|
|
127
|
+
onDelete={(e) => {
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
inputEl.current.value = '';
|
|
130
|
+
dispatch(actions.resetSelection());
|
|
131
|
+
onSelect_({ value: null });
|
|
132
|
+
}}
|
|
133
|
+
onSwitch={(e) => {
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
if (visible) {
|
|
137
|
+
dispatch(actions.hidePanel());
|
|
138
|
+
} else {
|
|
139
|
+
dispatch(actions.showPanel());
|
|
140
|
+
containerEl.current.focus();
|
|
141
|
+
}
|
|
142
|
+
}}
|
|
143
|
+
/>
|
|
144
|
+
<div
|
|
145
|
+
tabIndex="-1"
|
|
146
|
+
className={classnames('lunatic-transition', {
|
|
147
|
+
visible: isDisplay(state),
|
|
148
|
+
'width-auto': widthAuto,
|
|
149
|
+
})}
|
|
150
|
+
>
|
|
151
|
+
<Panel
|
|
152
|
+
idDropdown={id}
|
|
153
|
+
options={visibleOptions}
|
|
154
|
+
display={isDisplay(state) && !disabled}
|
|
155
|
+
prefix={prefix}
|
|
156
|
+
activeIndex={activeIndex}
|
|
157
|
+
optionComponent={Option}
|
|
158
|
+
selectedOption={selectedOption}
|
|
159
|
+
onSelect={onSelect_}
|
|
160
|
+
handleActive={(index) => dispatch(actions.setActiveOption(index))}
|
|
161
|
+
/>
|
|
162
|
+
</div>
|
|
163
|
+
</DropdownContainer>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Dropdown.propTypes = {
|
|
168
|
+
widthAuto: PropTypes.bool,
|
|
169
|
+
zIndex: PropTypes.number,
|
|
170
|
+
disabled: PropTypes.bool,
|
|
171
|
+
focused: PropTypes.bool,
|
|
172
|
+
className: PropTypes.string,
|
|
173
|
+
id: PropTypes.string,
|
|
174
|
+
options: PropTypes.array.isRequired,
|
|
175
|
+
onSelect: PropTypes.func,
|
|
176
|
+
placeholderList: PropTypes.string,
|
|
177
|
+
value: PropTypes.oneOfType([
|
|
178
|
+
PropTypes.string,
|
|
179
|
+
PropTypes.number,
|
|
180
|
+
PropTypes.bool,
|
|
181
|
+
]),
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
Dropdown.defaultProps = {
|
|
185
|
+
options: [],
|
|
186
|
+
zIndex: 0,
|
|
187
|
+
onSelect: () => null,
|
|
188
|
+
placeholderList: 'Search...',
|
|
189
|
+
disabled: false,
|
|
190
|
+
focused: false,
|
|
191
|
+
widthAuto: false,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default Dropdown;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import DropdownEdit from "./dropdown-edit";
|
|
3
|
-
import childrenToOption from "../commons/children-to-option";
|
|
4
|
-
|
|
5
|
-
const createDropDown = Component => ({ children, options, ...props }) => {
|
|
6
|
-
const o = options || childrenToOption(children);
|
|
7
|
-
return <Component options={o} {...props} />;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export default createDropDown(DropdownEdit);
|
|
11
|
-
export { default as Option } from "./option";
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DropdownEdit from "./dropdown-edit";
|
|
3
|
+
import childrenToOption from "../commons/children-to-option";
|
|
4
|
+
|
|
5
|
+
const createDropDown = Component => ({ children, options, ...props }) => {
|
|
6
|
+
const o = options || childrenToOption(children);
|
|
7
|
+
return <Component options={o} {...props} />;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default createDropDown(DropdownEdit);
|
|
11
|
+
export { default as Option } from "./option";
|