@inseefr/lunatic 0.2.3-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/loop-constructor/wrapper/component.js +190 -190
- 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/breadcrumb/breadcrumb.stories.js +21 -21
- package/src/stories/checkbox-boolean/data.json +78 -78
- package/src/stories/datepicker/data.json +3 -1
- package/src/stories/declarations/declarations.stories.js +116 -116
- 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/calc-var.json +187 -187
- package/src/stories/questionnaire/data-logement.json +2691 -2691
- 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 -44537
- package/src/stories/questionnaire/logement-sequence.json +26741 -26741
- package/src/stories/questionnaire/logement.json +21073 -26813
- package/src/stories/questionnaire/loop-and-controls.json +481 -0
- package/src/stories/questionnaire/questionnaire.stories.js +236 -154
- package/src/stories/questionnaire/update-external/data.json +1 -0
- package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
- package/src/stories/sequence/sequence.stories.js +32 -32
- package/src/stories/subsequence/subsequence.stories.js +32 -32
- 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/loops/roster-loop.json +71 -71
- 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/tests/utils/to-expose/init-questionnaire/questionnaire.json +148 -148
- package/src/tests/utils/to-expose/init-questionnaire/result.json +181 -181
- 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 +256 -253
- 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 -188
- 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,38 +1,38 @@
|
|
|
1
|
-
export const ON_INIT = 'lunatic-suggester/on-init';
|
|
2
|
-
export const onInit = ({ id, disabled, value }) => ({
|
|
3
|
-
type: ON_INIT,
|
|
4
|
-
payload: { id, disabled, value },
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
export const ON_CHANGE_SEARCH = 'lunatic-suggester/on-change-search';
|
|
8
|
-
export const onChangeSearch = (search) => ({
|
|
9
|
-
type: ON_CHANGE_SEARCH,
|
|
10
|
-
payload: { search },
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const ON_UPDATE_OPTIONS = 'lunatic-suggester/on-update-options';
|
|
14
|
-
export const onUpdateOptions = (options, search) => ({
|
|
15
|
-
type: ON_UPDATE_OPTIONS,
|
|
16
|
-
payload: { options, search },
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const ON_FOCUS = 'lunatic-suggester/on-focus';
|
|
20
|
-
export const onFocus = () => ({ type: ON_FOCUS });
|
|
21
|
-
|
|
22
|
-
export const ON_BLUR = 'lunatic-suggester/on-blur';
|
|
23
|
-
export const onBlur = () => ({ type: ON_BLUR });
|
|
24
|
-
|
|
25
|
-
export const ON_CLICK_OPTION = 'lunatic-suggester/on-click-option';
|
|
26
|
-
export const onClickOption = (index) => ({
|
|
27
|
-
type: ON_CLICK_OPTION,
|
|
28
|
-
payload: { index },
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export const ON_KEY_DOWN = 'lunatic-suggester/on-key-down';
|
|
32
|
-
export const onKeyDown = (key) => ({ type: ON_KEY_DOWN, payload: { key } });
|
|
33
|
-
|
|
34
|
-
export const ON_ERROR = 'lunatic-suggester/on-error';
|
|
35
|
-
export const onError = (message) => ({ type: ON_ERROR, payload: { message } });
|
|
36
|
-
|
|
37
|
-
export const ON_DELETE_SEARCH = 'lunatic-suggester/on-delete-search';
|
|
38
|
-
export const onDeleteSearch = () => ({ type: ON_DELETE_SEARCH });
|
|
1
|
+
export const ON_INIT = 'lunatic-suggester/on-init';
|
|
2
|
+
export const onInit = ({ id, disabled, value }) => ({
|
|
3
|
+
type: ON_INIT,
|
|
4
|
+
payload: { id, disabled, value },
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export const ON_CHANGE_SEARCH = 'lunatic-suggester/on-change-search';
|
|
8
|
+
export const onChangeSearch = (search) => ({
|
|
9
|
+
type: ON_CHANGE_SEARCH,
|
|
10
|
+
payload: { search },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const ON_UPDATE_OPTIONS = 'lunatic-suggester/on-update-options';
|
|
14
|
+
export const onUpdateOptions = (options, search) => ({
|
|
15
|
+
type: ON_UPDATE_OPTIONS,
|
|
16
|
+
payload: { options, search },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const ON_FOCUS = 'lunatic-suggester/on-focus';
|
|
20
|
+
export const onFocus = () => ({ type: ON_FOCUS });
|
|
21
|
+
|
|
22
|
+
export const ON_BLUR = 'lunatic-suggester/on-blur';
|
|
23
|
+
export const onBlur = () => ({ type: ON_BLUR });
|
|
24
|
+
|
|
25
|
+
export const ON_CLICK_OPTION = 'lunatic-suggester/on-click-option';
|
|
26
|
+
export const onClickOption = (index) => ({
|
|
27
|
+
type: ON_CLICK_OPTION,
|
|
28
|
+
payload: { index },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const ON_KEY_DOWN = 'lunatic-suggester/on-key-down';
|
|
32
|
+
export const onKeyDown = (key) => ({ type: ON_KEY_DOWN, payload: { key } });
|
|
33
|
+
|
|
34
|
+
export const ON_ERROR = 'lunatic-suggester/on-error';
|
|
35
|
+
export const onError = (message) => ({ type: ON_ERROR, payload: { message } });
|
|
36
|
+
|
|
37
|
+
export const ON_DELETE_SEARCH = 'lunatic-suggester/on-delete-search';
|
|
38
|
+
export const onDeleteSearch = () => ({ type: ON_DELETE_SEARCH });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function reduce(state) {
|
|
2
|
-
return {
|
|
3
|
-
...state,
|
|
4
|
-
search: '',
|
|
5
|
-
selectedIndex: undefined,
|
|
6
|
-
options: [],
|
|
7
|
-
expanded: false,
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default reduce;
|
|
1
|
+
function reduce(state) {
|
|
2
|
+
return {
|
|
3
|
+
...state,
|
|
4
|
+
search: '',
|
|
5
|
+
selectedIndex: undefined,
|
|
6
|
+
options: [],
|
|
7
|
+
expanded: false,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default reduce;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
function getStringValue(value) {
|
|
2
|
-
if (value) {
|
|
3
|
-
return `${value}`;
|
|
4
|
-
}
|
|
5
|
-
return '';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function getId() {
|
|
9
|
-
return `lunatic-suggester-${new Date().getTime()}`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function reduce(state, action) {
|
|
13
|
-
const { payload } = action;
|
|
14
|
-
const { id, disabled, value } = payload;
|
|
15
|
-
const { search } = state;
|
|
16
|
-
|
|
17
|
-
if (value && search.length === 0) {
|
|
18
|
-
return {
|
|
19
|
-
...state,
|
|
20
|
-
id: id || getId(),
|
|
21
|
-
disabled,
|
|
22
|
-
search: getStringValue(value),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return { ...state, id: id || getId(), disabled };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default reduce;
|
|
1
|
+
function getStringValue(value) {
|
|
2
|
+
if (value) {
|
|
3
|
+
return `${value}`;
|
|
4
|
+
}
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getId() {
|
|
9
|
+
return `lunatic-suggester-${new Date().getTime()}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function reduce(state, action) {
|
|
13
|
+
const { payload } = action;
|
|
14
|
+
const { id, disabled, value } = payload;
|
|
15
|
+
const { search } = state;
|
|
16
|
+
|
|
17
|
+
if (value && search.length === 0) {
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
id: id || getId(),
|
|
21
|
+
disabled,
|
|
22
|
+
search: getStringValue(value),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { ...state, id: id || getId(), disabled };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default reduce;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import * as actions from '../actions';
|
|
2
|
-
import reduceOnChangeSearch from './reduce-on-change-search';
|
|
3
|
-
import reduceOnUpdateOptions from './reduce-on-update-options';
|
|
4
|
-
import reduceOnFocus from './reduce-on-focus';
|
|
5
|
-
import reduceOnBlur from './reduce-on-blur';
|
|
6
|
-
import reduceOnClickOption from './reduce-on-click-option';
|
|
7
|
-
import reduceOnKeyDown from './reduce-on-key-down';
|
|
8
|
-
import reduceOnInit from './reduce-on-init';
|
|
9
|
-
import reduceOnError from './reduce-on-error';
|
|
10
|
-
import reduceOnDeleteSearch from './reduce-on-delete-search';
|
|
11
|
-
|
|
12
|
-
function reduce(state, action) {
|
|
13
|
-
const { type } = action;
|
|
14
|
-
switch (type) {
|
|
15
|
-
case actions.ON_CHANGE_SEARCH:
|
|
16
|
-
return reduceOnChangeSearch(state, action);
|
|
17
|
-
case actions.ON_UPDATE_OPTIONS:
|
|
18
|
-
return reduceOnUpdateOptions(state, action);
|
|
19
|
-
case actions.ON_FOCUS:
|
|
20
|
-
return reduceOnFocus(state, action);
|
|
21
|
-
case actions.ON_BLUR:
|
|
22
|
-
return reduceOnBlur(state, action);
|
|
23
|
-
case actions.ON_CLICK_OPTION:
|
|
24
|
-
return reduceOnClickOption(state, action);
|
|
25
|
-
case actions.ON_KEY_DOWN:
|
|
26
|
-
return reduceOnKeyDown(state, action);
|
|
27
|
-
case actions.ON_INIT:
|
|
28
|
-
return reduceOnInit(state, action);
|
|
29
|
-
case actions.ON_ERROR:
|
|
30
|
-
return reduceOnError(state, action);
|
|
31
|
-
case actions.ON_DELETE_SEARCH:
|
|
32
|
-
return reduceOnDeleteSearch(state, action);
|
|
33
|
-
default:
|
|
34
|
-
return state;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default reduce;
|
|
1
|
+
import * as actions from '../actions';
|
|
2
|
+
import reduceOnChangeSearch from './reduce-on-change-search';
|
|
3
|
+
import reduceOnUpdateOptions from './reduce-on-update-options';
|
|
4
|
+
import reduceOnFocus from './reduce-on-focus';
|
|
5
|
+
import reduceOnBlur from './reduce-on-blur';
|
|
6
|
+
import reduceOnClickOption from './reduce-on-click-option';
|
|
7
|
+
import reduceOnKeyDown from './reduce-on-key-down';
|
|
8
|
+
import reduceOnInit from './reduce-on-init';
|
|
9
|
+
import reduceOnError from './reduce-on-error';
|
|
10
|
+
import reduceOnDeleteSearch from './reduce-on-delete-search';
|
|
11
|
+
|
|
12
|
+
function reduce(state, action) {
|
|
13
|
+
const { type } = action;
|
|
14
|
+
switch (type) {
|
|
15
|
+
case actions.ON_CHANGE_SEARCH:
|
|
16
|
+
return reduceOnChangeSearch(state, action);
|
|
17
|
+
case actions.ON_UPDATE_OPTIONS:
|
|
18
|
+
return reduceOnUpdateOptions(state, action);
|
|
19
|
+
case actions.ON_FOCUS:
|
|
20
|
+
return reduceOnFocus(state, action);
|
|
21
|
+
case actions.ON_BLUR:
|
|
22
|
+
return reduceOnBlur(state, action);
|
|
23
|
+
case actions.ON_CLICK_OPTION:
|
|
24
|
+
return reduceOnClickOption(state, action);
|
|
25
|
+
case actions.ON_KEY_DOWN:
|
|
26
|
+
return reduceOnKeyDown(state, action);
|
|
27
|
+
case actions.ON_INIT:
|
|
28
|
+
return reduceOnInit(state, action);
|
|
29
|
+
case actions.ON_ERROR:
|
|
30
|
+
return reduceOnError(state, action);
|
|
31
|
+
case actions.ON_DELETE_SEARCH:
|
|
32
|
+
return reduceOnDeleteSearch(state, action);
|
|
33
|
+
default:
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default reduce;
|
|
@@ -1,121 +1,127 @@
|
|
|
1
|
-
import React, { useReducer, useEffect } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
reducer,
|
|
5
|
-
INITIAL_STATE,
|
|
6
|
-
SuggesterContext,
|
|
7
|
-
actions,
|
|
8
|
-
} from './state-management';
|
|
9
|
-
import { Suggester } from './components';
|
|
10
|
-
import DefaultLabelRenderer from './components/selection/default-label-renderer';
|
|
11
|
-
import { DefaultOptionRenderer } from './components';
|
|
12
|
-
import './default-style.scss';
|
|
13
|
-
|
|
14
|
-
function getSearch(search, value) {
|
|
15
|
-
if (search && search.length) {
|
|
16
|
-
return search;
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function SuggesterWrapper({
|
|
22
|
-
id,
|
|
23
|
-
className,
|
|
24
|
-
version,
|
|
25
|
-
labelledBy,
|
|
26
|
-
placeholderList,
|
|
27
|
-
optionRenderer,
|
|
28
|
-
onSelect,
|
|
29
|
-
searching,
|
|
30
|
-
labelRenderer,
|
|
31
|
-
disabled,
|
|
32
|
-
value,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
1
|
+
import React, { useReducer, useEffect } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import {
|
|
4
|
+
reducer,
|
|
5
|
+
INITIAL_STATE,
|
|
6
|
+
SuggesterContext,
|
|
7
|
+
actions,
|
|
8
|
+
} from './state-management';
|
|
9
|
+
import { Suggester } from './components';
|
|
10
|
+
import DefaultLabelRenderer from './components/selection/default-label-renderer';
|
|
11
|
+
import { DefaultOptionRenderer } from './components';
|
|
12
|
+
import './default-style.scss';
|
|
13
|
+
|
|
14
|
+
function getSearch(search, value) {
|
|
15
|
+
if (search && search.length) {
|
|
16
|
+
return search;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function SuggesterWrapper({
|
|
22
|
+
id,
|
|
23
|
+
className,
|
|
24
|
+
version,
|
|
25
|
+
labelledBy,
|
|
26
|
+
placeholderList,
|
|
27
|
+
optionRenderer,
|
|
28
|
+
onSelect,
|
|
29
|
+
searching,
|
|
30
|
+
labelRenderer,
|
|
31
|
+
disabled,
|
|
32
|
+
value,
|
|
33
|
+
focused,
|
|
34
|
+
response,
|
|
35
|
+
logFunction,
|
|
36
|
+
}) {
|
|
37
|
+
const [state, dispatch] = useReducer(reducer, INITIAL_STATE);
|
|
38
|
+
const { search, selectedIndex, options, expended } = state;
|
|
39
|
+
|
|
40
|
+
useEffect(
|
|
41
|
+
function () {
|
|
42
|
+
async function doIt() {
|
|
43
|
+
try {
|
|
44
|
+
const what = getSearch(search, value);
|
|
45
|
+
if (what && typeof searching === 'function') {
|
|
46
|
+
const { results, search: old } = await searching(what);
|
|
47
|
+
dispatch(actions.onUpdateOptions(results, old));
|
|
48
|
+
} else {
|
|
49
|
+
dispatch(actions.onDeleteSearch());
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error(e);
|
|
53
|
+
dispatch(actions.onError('Une erreur est survenue.'));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
doIt();
|
|
57
|
+
},
|
|
58
|
+
[search, searching, value]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
useEffect(
|
|
62
|
+
function () {
|
|
63
|
+
if (selectedIndex !== undefined && !expended) {
|
|
64
|
+
onSelect(options[selectedIndex], selectedIndex);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[selectedIndex, onSelect, options, expended]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
useEffect(
|
|
71
|
+
function () {
|
|
72
|
+
dispatch(actions.onInit({ id, disabled, value }));
|
|
73
|
+
},
|
|
74
|
+
[id, disabled, value]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<SuggesterContext.Provider value={[state, dispatch]}>
|
|
79
|
+
<Suggester
|
|
80
|
+
className={className}
|
|
81
|
+
placeholderList={placeholderList}
|
|
82
|
+
version={version}
|
|
83
|
+
labelledBy={labelledBy}
|
|
84
|
+
optionRenderer={optionRenderer}
|
|
85
|
+
labelRenderer={labelRenderer}
|
|
86
|
+
onSelect={onSelect}
|
|
87
|
+
value={value}
|
|
88
|
+
focused={focused}
|
|
89
|
+
response={response}
|
|
90
|
+
logFunction={logFunction}
|
|
91
|
+
/>
|
|
92
|
+
</SuggesterContext.Provider>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
SuggesterWrapper.propTypes = {
|
|
97
|
+
id: PropTypes.string,
|
|
98
|
+
className: PropTypes.string,
|
|
99
|
+
placeholderList: PropTypes.string,
|
|
100
|
+
labelledBy: PropTypes.string,
|
|
101
|
+
optionRenderer: PropTypes.func,
|
|
102
|
+
labelRenderer: PropTypes.func,
|
|
103
|
+
onSelect: PropTypes.func,
|
|
104
|
+
storeInfo: PropTypes.object,
|
|
105
|
+
value: PropTypes.oneOfType([
|
|
106
|
+
PropTypes.string,
|
|
107
|
+
PropTypes.number,
|
|
108
|
+
PropTypes.bool,
|
|
109
|
+
PropTypes.object,
|
|
110
|
+
]),
|
|
111
|
+
searching: PropTypes.func,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
SuggesterWrapper.defaultProps = {
|
|
115
|
+
id: undefined,
|
|
116
|
+
className: 'lunatic-suggester-default-style',
|
|
117
|
+
labelledBy: undefined,
|
|
118
|
+
placeholderList: 'Veuillez...',
|
|
119
|
+
optionRenderer: DefaultOptionRenderer,
|
|
120
|
+
labelRenderer: DefaultLabelRenderer,
|
|
121
|
+
language: 'French',
|
|
122
|
+
onSelect: () => null,
|
|
123
|
+
value: undefined,
|
|
124
|
+
searching: undefined,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default SuggesterWrapper;
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import { createAppendTask } from '../../utils/suggester-workers/append-to-index';
|
|
3
|
-
import Progress from './progress';
|
|
4
|
-
import { clearStoreData } from '../../utils/store-tools';
|
|
5
|
-
|
|
6
|
-
function empty() {}
|
|
7
|
-
|
|
8
|
-
function Loader({ start, db, store, idbVersion, fetch, post, handleClick }) {
|
|
9
|
-
const [progress, setProgress] = useState(0);
|
|
10
|
-
const [entities, setEntities] = useState(undefined);
|
|
11
|
-
|
|
12
|
-
useEffect(
|
|
13
|
-
function () {
|
|
14
|
-
async function load() {
|
|
15
|
-
if (typeof fetch === 'function' && start) {
|
|
16
|
-
const e = await fetch();
|
|
17
|
-
setEntities(e);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
load();
|
|
21
|
-
},
|
|
22
|
-
[fetch, start]
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
function log({ message }) {
|
|
26
|
-
const { type, percent } = message;
|
|
27
|
-
if (type === 'bulk-insert/complete') {
|
|
28
|
-
setProgress(percent);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
useEffect(
|
|
33
|
-
function () {
|
|
34
|
-
let abort;
|
|
35
|
-
async function go() {
|
|
36
|
-
try {
|
|
37
|
-
if (entities && db && idbVersion && store) {
|
|
38
|
-
const [startT, abort_] = createAppendTask(store, idbVersion, log);
|
|
39
|
-
abort = abort_;
|
|
40
|
-
clearStoreData(db);
|
|
41
|
-
await startT(entities);
|
|
42
|
-
post(store.name, entities.length);
|
|
43
|
-
}
|
|
44
|
-
} catch (e) {
|
|
45
|
-
console.warn(e);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
go();
|
|
50
|
-
|
|
51
|
-
return function () {
|
|
52
|
-
if (abort) {
|
|
53
|
-
abort();
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
[store, db, entities, idbVersion, post]
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<Progress percent={progress} display={true} handleClick={handleClick} />
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
Loader.defaultProps = { idbVersion: '1', post: empty, handleClick: empty };
|
|
66
|
-
|
|
67
|
-
export default Loader;
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { createAppendTask } from '../../utils/suggester-workers/append-to-index';
|
|
3
|
+
import Progress from './progress';
|
|
4
|
+
import { clearStoreData } from '../../utils/store-tools';
|
|
5
|
+
|
|
6
|
+
function empty() {}
|
|
7
|
+
|
|
8
|
+
function Loader({ start, db, store, idbVersion, fetch, post, handleClick }) {
|
|
9
|
+
const [progress, setProgress] = useState(0);
|
|
10
|
+
const [entities, setEntities] = useState(undefined);
|
|
11
|
+
|
|
12
|
+
useEffect(
|
|
13
|
+
function () {
|
|
14
|
+
async function load() {
|
|
15
|
+
if (typeof fetch === 'function' && start) {
|
|
16
|
+
const e = await fetch();
|
|
17
|
+
setEntities(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
load();
|
|
21
|
+
},
|
|
22
|
+
[fetch, start]
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
function log({ message }) {
|
|
26
|
+
const { type, percent } = message;
|
|
27
|
+
if (type === 'bulk-insert/complete') {
|
|
28
|
+
setProgress(percent);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
useEffect(
|
|
33
|
+
function () {
|
|
34
|
+
let abort;
|
|
35
|
+
async function go() {
|
|
36
|
+
try {
|
|
37
|
+
if (entities && db && idbVersion && store) {
|
|
38
|
+
const [startT, abort_] = createAppendTask(store, idbVersion, log);
|
|
39
|
+
abort = abort_;
|
|
40
|
+
clearStoreData(db);
|
|
41
|
+
await startT(entities);
|
|
42
|
+
post(store.name, entities.length);
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.warn(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
go();
|
|
50
|
+
|
|
51
|
+
return function () {
|
|
52
|
+
if (abort) {
|
|
53
|
+
abort();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
[store, db, entities, idbVersion, post]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Progress percent={progress} display={true} handleClick={handleClick} />
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Loader.defaultProps = { idbVersion: '1', post: empty, handleClick: empty };
|
|
66
|
+
|
|
67
|
+
export default Loader;
|