@inseefr/lunatic 0.1.0-hackathon → 0.1.0-v2
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/index.js +1433 -835
- package/lib/index.js.map +1 -1
- package/package.json +11 -8
- package/src/components/breadcrumb/component.js +29 -29
- package/src/components/button/index.js +1 -1
- package/src/components/button/lunatic-button.js +32 -0
- package/src/components/checkbox/checkbox-boolean/index.js +1 -0
- package/src/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +44 -0
- package/src/components/checkbox/checkbox-group/checkbox-group.js +78 -0
- package/src/components/checkbox/checkbox-group/checkbox-option.js +46 -0
- package/src/components/checkbox/checkbox-group/index.js +1 -0
- package/src/components/checkbox/checkbox-group/lunatic-checkbox-group.js +32 -0
- package/src/components/checkbox/checkbox-one/index.js +1 -0
- package/src/components/checkbox/checkbox-one/lunatic-checkbox-one.js +7 -0
- package/src/components/checkbox/checkbox.scss +1 -73
- package/src/components/checkbox/commons/checkbox-option.js +49 -0
- package/src/components/checkbox/commons/index.js +1 -0
- package/src/components/checkbox/index.js +3 -3
- package/src/components/commons/components/field-container/field-container.js +28 -0
- package/src/components/commons/components/field-container/field-container.scss +0 -0
- package/src/components/commons/components/field-container/index.js +1 -0
- package/src/components/commons/components/fieldset.js +12 -0
- package/src/components/commons/components/input-container.js +30 -0
- package/src/components/commons/components/label.js +14 -0
- package/src/components/commons/components/lunatic-field.js +35 -0
- package/src/components/commons/create-customizable-field.js +13 -0
- package/src/components/commons/index.js +9 -0
- package/src/components/commons/use-on-handle-change.js +16 -0
- package/src/components/commons/use-options-keydown.js +22 -0
- package/src/components/commons/use-previous.js +11 -0
- 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 +33 -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 +1 -1
- package/src/components/{missing-wrapper → component-wrapper/missing}/component.js +72 -12
- package/src/components/component-wrapper/missing/index.js +1 -0
- package/src/components/{missing-wrapper → component-wrapper/missing}/missing.scss +0 -0
- package/src/components/component-wrapper/wrapper.js +23 -0
- package/src/components/components.js +22 -18
- package/src/components/datepicker/datepicker.js +25 -0
- package/src/components/datepicker/index.js +1 -1
- package/src/components/datepicker/lunatic-datepicker.js +50 -0
- package/src/components/declarations/declaration.js +11 -0
- package/src/components/declarations/declarations-after-text.js +8 -0
- package/src/components/declarations/declarations-before-text.js +8 -0
- package/src/components/declarations/declarations-detachable.js +8 -0
- package/src/components/declarations/declarations.js +35 -0
- package/src/components/declarations/index.js +4 -1
- package/src/components/declarations/wrappers/input-declarations-wrapper.js +40 -12
- package/src/components/declarations/wrappers/list-declarations-wrapper.js +235 -232
- package/src/components/dropdown/commons/actions.js +40 -31
- package/src/components/dropdown/commons/components/panel.js +78 -78
- package/src/components/dropdown/commons/reducer.js +152 -149
- package/src/components/dropdown/component.js +121 -115
- package/src/components/dropdown/dropdown-edit/dropdown-edit.js +6 -0
- package/src/components/dropdown/dropdown-simple/dropdown.js +8 -1
- package/src/components/filter-description/component.js +48 -42
- package/src/components/icon/component.js +31 -33
- package/src/components/index.scss +5 -3
- package/src/components/input/index.js +1 -2
- package/src/components/input/input.js +45 -9
- package/src/components/input/input.scss +0 -6
- package/src/components/input/lunatic-input.js +53 -0
- package/src/components/input-number/index.js +1 -0
- package/src/components/input-number/input-number.js +38 -0
- package/src/components/input-number/input-number.scss +0 -0
- package/src/components/input-number/lunatic-input-number.js +50 -0
- package/src/components/loop/{component.js → _old/component.js} +1 -0
- package/src/components/loop/{loop.scss → _old/loop.scss} +0 -0
- package/src/components/loop/{wrapper.js → _old/wrapper.js} +15 -15
- package/src/components/loop/block-for-loop/block-for-loop-ochestrator.js +6 -0
- package/src/components/loop/block-for-loop/block-for-loop.js +91 -0
- package/src/components/loop/block-for-loop/index.js +1 -0
- package/src/components/loop/block-for-loop/row.js +52 -0
- package/src/components/loop/commons/create-loop-orchestrator.js +36 -0
- package/src/components/loop/commons/index.js +2 -0
- package/src/components/loop/commons/row-component.js +52 -0
- package/src/components/loop/index.js +1 -1
- package/src/components/loop/loop.js +78 -0
- package/src/components/loop/roster-for-loop/add-row-button.js +12 -0
- package/src/components/loop/roster-for-loop/body.js +44 -0
- package/src/components/loop/roster-for-loop/header.js +25 -0
- package/src/components/loop/roster-for-loop/html-table/table.js +11 -0
- package/src/components/loop/roster-for-loop/html-table/tbody.js +11 -0
- package/src/components/loop/roster-for-loop/html-table/td.js +14 -0
- package/src/components/loop/roster-for-loop/html-table/th.js +11 -0
- package/src/components/loop/roster-for-loop/html-table/thead.js +11 -0
- package/src/components/loop/roster-for-loop/html-table/tr.js +11 -0
- package/src/components/loop/roster-for-loop/index.js +1 -0
- package/src/components/loop/roster-for-loop/roster-for-loop-orchestrator.js +6 -0
- package/src/components/loop/roster-for-loop/roster-for-loop.js +90 -0
- package/src/components/loop/roster-for-loop/roster-table.js +39 -0
- package/src/components/loop/roster-for-loop/roster.scss +42 -0
- package/src/components/loop/roster-for-loop/row.js +65 -0
- package/src/components/loop-constructor/block/component.js +2 -2
- package/src/components/loop-constructor/block/index.js +1 -1
- package/src/components/loop-constructor/index.js +1 -1
- package/src/components/loop-constructor/roster/component.js +2 -2
- package/src/components/loop-constructor/roster/index.js +1 -1
- package/src/components/loop-constructor/wrapper/body-component.js +6 -0
- package/src/components/loop-constructor/wrapper/build-components.js +33 -33
- package/src/components/loop-constructor/wrapper/index.js +1 -1
- package/src/components/modal/component.js +42 -0
- package/src/components/modal/index.js +1 -0
- package/src/components/modal/modal.scss +33 -0
- package/src/components/radio/index.js +1 -1
- package/src/components/radio/lunatic-radio-group.js +45 -0
- package/src/components/radio/radio-group.js +33 -0
- package/src/components/radio/radio-option.js +87 -0
- package/src/components/radio/radio.scss +52 -52
- package/src/components/sequence/index.js +1 -1
- package/src/components/sequence/sequence.js +75 -0
- package/src/components/subsequence/index.js +1 -1
- package/src/components/subsequence/subsequence.js +73 -0
- package/src/components/suggester/check-store.js +70 -70
- package/src/components/suggester/components/panel/option-container.js +11 -10
- package/src/components/suggester/components/panel/panel.js +20 -6
- package/src/components/suggester/components/selection/label.js +7 -6
- package/src/components/suggester/components/selection/selection.js +36 -11
- package/src/components/suggester/components/suggester-content.js +35 -42
- package/src/components/suggester/components/suggester.js +45 -26
- package/src/components/suggester/{components/create-on-keydown-callback.js → create-on-keydown-callback.js} +28 -28
- package/src/components/suggester/find-best-label/find-best-label.js +3 -1
- package/src/components/suggester/idb-suggester.js +2 -1
- package/src/components/suggester/lunatic-suggester.js +48 -96
- package/src/components/suggester/searching/create-searching.js +3 -1
- package/src/components/suggester/suggester-wrapper.js +75 -9
- package/src/components/switch/index.js +1 -0
- package/src/components/switch/lunatic-switch.js +49 -0
- package/src/components/switch/switch.js +72 -0
- package/src/components/switch/switch.scss +47 -0
- package/src/components/table/table.js +164 -158
- package/src/components/textarea/component.js +11 -5
- package/src/components/tooltip/response.js +58 -52
- package/src/stories/checkbox-boolean/data-forced.json +48 -48
- package/src/stories/checkbox-group/data-vtl.json +102 -102
- package/src/stories/cleaning/cleaning.stories.js +39 -0
- package/src/stories/cleaning/simple-loop.json +911 -0
- package/src/stories/cleaning/simpsons.json +5839 -0
- package/src/stories/datepicker/data.json +45 -43
- package/src/stories/declarations/declarations.stories.js +20 -13
- package/src/stories/icons/icons.stories.js +24 -16
- package/src/stories/loop-constructor/README.md +27 -27
- package/src/stories/loop-constructor/data-input-forced.json +64 -64
- package/src/stories/loop-constructor/data-input.json +100 -100
- package/src/stories/loop-constructor/data-loop-forced.json +66 -66
- package/src/stories/loop-constructor/data-loop-static-forced.json +66 -66
- package/src/stories/loop-constructor/data-loop-static.json +81 -81
- package/src/stories/loop-constructor/data-loop.json +81 -81
- package/src/stories/loop-constructor/data-roster-forced.json +68 -68
- package/src/stories/loop-constructor/data-roster.json +83 -83
- package/src/stories/loop-constructor/loop-constructor.stories.js +180 -180
- package/src/stories/questionnaire/logement-queen.json +23234 -0
- package/src/stories/questionnaire/logement.json +22068 -26812
- package/src/stories/questionnaire/questionnaire.stories.js +86 -29
- package/src/stories/questionnaire/update-external/data.json +1 -0
- package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
- 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/data-auto.json +1 -0
- package/src/stories/suggester/data.json +35 -2
- package/src/stories/suggester/lunatic-suggester-mui.scss +27 -0
- package/src/stories/suggester/suggester-material-ui.js +148 -0
- package/src/stories/suggester/suggester-workers.stories.js +48 -1
- package/src/stories/suggester/suggester.stories.js +27 -1
- package/src/stories/switch/README.md +31 -0
- package/src/stories/switch/SwitchMaterialUI.js +35 -0
- package/src/stories/switch/data-forced.json +48 -0
- package/src/stories/switch/data.json +80 -0
- package/src/stories/switch/switch.stories.js +78 -0
- package/src/stories/utils/custom-lunatic.scss +28 -23
- package/src/stories/utils/orchestrator.js +151 -58
- package/src/stories/utils/waiting/index.js +1 -0
- package/src/stories/utils/waiting/preloader.svg +1 -0
- package/src/stories/utils/waiting/waiting.js +21 -0
- package/src/stories/utils/waiting/waiting.scss +21 -0
- package/src/tests/sample.spec.js +5 -0
- package/src/utils/icons/checkbox-checked.icon.js +25 -0
- package/src/utils/icons/checkbox-unchecked.icon.js +25 -0
- package/src/utils/icons/radio-checked.icon.js +25 -0
- package/src/utils/icons/radio-unchecked.icon.js +25 -0
- package/src/utils/lib/controls/index.js +1 -0
- package/src/utils/lib/controls/utils.js +146 -0
- package/src/utils/lib/index.js +20 -19
- package/src/utils/lib/pagination/navigation/shared.js +7 -4
- package/src/utils/lib/responses.js +9 -7
- package/src/utils/lib/tooltip/build-response.js +53 -41
- package/src/utils/store-tools/auto-load.js +2 -1
- package/src/utils/store-tools/create/index.js +2 -1
- package/src/utils/store-tools/create/update-store-info.js +26 -26
- package/src/utils/store-tools/index.js +7 -5
- package/src/utils/suggester-workers/append-to-index/create-append-task.js +3 -1
- 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 +11 -11
- 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} +0 -0
- 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} +0 -0
- 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} +2 -2
- 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} +0 -0
- package/src/utils/suggester-workers/commons-tokenizer/index.js +6 -5
- package/src/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.js +7 -3
- package/src/utils/suggester-workers/commons-tokenizer/soft-tokenizer.js +1 -1
- package/src/utils/suggester-workers/create-worker.js +55 -0
- package/src/utils/suggester-workers/find-best-label/tokenize.js +2 -5
- package/src/utils/suggester-workers/{query-parser → searching/query-parser}/index.js +0 -0
- 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 +0 -0
- package/src/utils/suggester-workers/searching/query-parser/query-parser-tokenized.js +34 -0
- package/src/utils/suggester-workers/searching/resolve-query-parser.js +2 -2
- package/src/utils/suggester-workers/searching/searching.js +2 -2
- package/src/utils/to-expose/{calculated-variables.js → _old/calculated-variables.js} +0 -0
- package/src/utils/to-expose/{handler.js → _old/handler.js} +22 -0
- package/src/utils/to-expose/{init-questionnaire.js → _old/init-questionnaire.js} +0 -0
- package/src/utils/to-expose/{state.js → _old/state.js} +13 -14
- package/src/utils/to-expose/hooks/filter-components.js +106 -106
- package/src/utils/to-expose/hooks/index.js +1 -1
- package/src/utils/to-expose/hooks/lunatic.js +68 -7
- package/src/utils/to-expose/hooks/use-lunatic/actions.js +23 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/check-loops.js +61 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/create-map-pages.js +69 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-condition-filter.js +16 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-expression/create-execute-expression.js +182 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-expression/create-memoizer.js +42 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-expression/create-refresh-calculated.js +50 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-expression/execute-expression.js +60 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-expression/get-expressions-variables.js +22 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/execute-expression/index.js +1 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/fill-component-expressions.js +113 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/fill-components.js +31 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/get-compatible-vtl-expression.js +14 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/get-component-value/get-component-value.js +161 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/get-component-value/index.js +1 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/get-components-from-state.js +24 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/get-page-tag.js +10 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/index.js +12 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/is-First-last-page.js +8 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/is-paginated-loop.js +6 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/load-suggesters.js +59 -0
- package/src/utils/to-expose/hooks/use-lunatic/commons/use-components-from-state.js +20 -0
- package/src/utils/to-expose/hooks/use-lunatic/index.js +1 -0
- package/src/utils/to-expose/hooks/use-lunatic/initial-state.js +22 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/commons/index.js +3 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/commons/is-empty-on-empty-page.js +29 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/commons/resize-array-variable.js +26 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/commons/validate-loop-condition-filter.js +20 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/index.js +1 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-go-next-page.js +129 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-go-previous-page.js +131 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-handle-change/index.js +1 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +69 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.js +22 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.js +13 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-on-init.js +166 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-on-set-waiting.js +7 -0
- package/src/utils/to-expose/hooks/use-lunatic/reducer/reducer.js +26 -0
- package/src/utils/to-expose/hooks/use-lunatic/use-lunatic.js +79 -0
- package/src/utils/to-expose/index.js +16 -11
- package/src/components/button/component.js +0 -53
- package/src/components/checkbox/boolean.js +0 -172
- package/src/components/checkbox/group.js +0 -231
- package/src/components/checkbox/one.js +0 -11
- package/src/components/datepicker/component.js +0 -11
- package/src/components/input/input-number.js +0 -54
- package/src/components/missing-wrapper/wrapper.js +0 -10
- package/src/components/radio/component.js +0 -9
- package/src/components/sequence/component.js +0 -50
- package/src/components/subsequence/component.js +0 -49
- package/src/tests/components/breadcrumb.spec.js +0 -13
- package/src/tests/components/button.spec.js +0 -11
- package/src/tests/components/checkbox-boolean.spec.js +0 -45
- package/src/tests/components/checkbox-group.spec.js +0 -53
- package/src/tests/components/checkbox-one.spec.js +0 -32
- package/src/tests/components/datepicker.spec.js +0 -22
- package/src/tests/components/declarations-wrappers/input-declarations-wrapper.spec.js +0 -67
- package/src/tests/components/declarations-wrappers/list-declarations-wrapper.spec.js +0 -52
- package/src/tests/components/declarations-wrappers/simple-declarations-wrapper.spec.js +0 -21
- package/src/tests/components/declarations.spec.js +0 -46
- package/src/tests/components/input-number.spec.js +0 -194
- package/src/tests/components/input.spec.js +0 -18
- package/src/tests/components/loops/loop-static.json +0 -66
- package/src/tests/components/loops/loop.json +0 -258
- package/src/tests/components/loops/loop.spec.js +0 -30
- package/src/tests/components/loops/roster-for-loop.spec.js +0 -18
- package/src/tests/components/loops/roster-loop.json +0 -71
- package/src/tests/components/missing-wrapper.spec.js +0 -33
- package/src/tests/components/progress-bar.spec.js +0 -15
- package/src/tests/components/radio.spec.js +0 -27
- package/src/tests/components/sequence.spec.js +0 -9
- package/src/tests/components/subsequence.spec.js +0 -9
- package/src/tests/components/table.spec.js +0 -11
- package/src/tests/components/textarea.spec.js +0 -18
- package/src/tests/components/tooltip.spec.js +0 -25
- package/src/tests/setup/setupTests.js +0 -4
- package/src/tests/utils/lib/alphabet.spec.js +0 -36
- package/src/tests/utils/lib/array.spec.js +0 -22
- package/src/tests/utils/lib/checkbox/group.spec.js +0 -72
- package/src/tests/utils/lib/decorator/title-decorator.spec.js +0 -12
- package/src/tests/utils/lib/input-number.spec.js +0 -18
- package/src/tests/utils/lib/items-positioning.spec.js +0 -17
- package/src/tests/utils/lib/label-position.spec.js +0 -22
- package/src/tests/utils/lib/loops/bindings.spec.js +0 -75
- package/src/tests/utils/lib/loops/shared.spec.js +0 -82
- package/src/tests/utils/lib/missing/missing.spec.js +0 -74
- package/src/tests/utils/lib/missing/mock.js +0 -137
- package/src/tests/utils/lib/pagination/shared.spec.js +0 -42
- package/src/tests/utils/lib/responses.spec.js +0 -64
- package/src/tests/utils/lib/style.spec.js +0 -26
- package/src/tests/utils/lib/table/roster.spec.js +0 -25
- package/src/tests/utils/lib/tooltip/build-response.spec.js +0 -95
- package/src/tests/utils/lib/tooltip/content.spec.js +0 -109
- package/src/tests/utils/to-expose/handler/handler.spec.js +0 -94
- package/src/tests/utils/to-expose/handler/questionnaire.json +0 -158
- package/src/tests/utils/to-expose/handler/results/index.js +0 -6
- package/src/tests/utils/to-expose/handler/results/res-double.json +0 -158
- package/src/tests/utils/to-expose/handler/results/res-input-collected.json +0 -158
- package/src/tests/utils/to-expose/handler/results/res-input-edited.json +0 -158
- package/src/tests/utils/to-expose/handler/results/res-loop.json +0 -158
- package/src/tests/utils/to-expose/handler/results/res-matrix.json +0 -158
- package/src/tests/utils/to-expose/handler/results/res-responses.json +0 -158
- package/src/tests/utils/to-expose/hooks/use-lunatic.spec.js +0 -46
- package/src/tests/utils/to-expose/init-questionnaire/data.json +0 -12
- package/src/tests/utils/to-expose/init-questionnaire/init-questionnaire.spec.js +0 -19
- package/src/tests/utils/to-expose/init-questionnaire/questionnaire.json +0 -148
- package/src/tests/utils/to-expose/init-questionnaire/result.json +0 -181
- package/src/tests/utils/to-expose/interpret/interpret.spec.js +0 -48
- package/src/tests/utils/to-expose/state/questionnaire.json +0 -61
- package/src/tests/utils/to-expose/state/results.js +0 -78
- package/src/tests/utils/to-expose/state/state.spec.js +0 -59
- 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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { isOnEmptyPage, validateLoopConditionFilter } from './commons';
|
|
2
|
+
import { getCompatibleVTLExpression } from '../commons';
|
|
3
|
+
|
|
4
|
+
function getNextPage(state) {
|
|
5
|
+
const { pager } = state;
|
|
6
|
+
const { page, maxPage } = pager;
|
|
7
|
+
const p = Number.parseInt(page);
|
|
8
|
+
const mp = maxPage;
|
|
9
|
+
if (p < mp) {
|
|
10
|
+
return `${p + 1}`;
|
|
11
|
+
}
|
|
12
|
+
return `${maxPage}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function reduceNextSubPage(state) {
|
|
16
|
+
const { pager } = state;
|
|
17
|
+
const { subPage } = pager;
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
pager: { ...pager, subPage: subPage + 1 },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function reduceNextIteration(state) {
|
|
25
|
+
const { pager } = state;
|
|
26
|
+
const { iteration } = pager;
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
pager: { ...pager, subPage: 0, iteration: iteration + 1 },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function reduceNextPage(state, { next, iterations }) {
|
|
34
|
+
const { pager } = state;
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
isInLoop: false,
|
|
38
|
+
pager: {
|
|
39
|
+
...pager,
|
|
40
|
+
page: next,
|
|
41
|
+
iteration: undefined,
|
|
42
|
+
nbIterations: undefined,
|
|
43
|
+
subPage: undefined,
|
|
44
|
+
nbSubPages: undefined,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function reduceStartLoop(state, { next, iterations, loopDependencies }) {
|
|
50
|
+
const { pages, pager, executeExpression } = state;
|
|
51
|
+
const { subPages } = pages[next];
|
|
52
|
+
|
|
53
|
+
if (!validateLoopConditionFilter(state, { next })) {
|
|
54
|
+
return {
|
|
55
|
+
...state,
|
|
56
|
+
pager: {
|
|
57
|
+
...pager,
|
|
58
|
+
page: next,
|
|
59
|
+
subPage: undefined,
|
|
60
|
+
nbSubPages: undefined,
|
|
61
|
+
iteration: undefined,
|
|
62
|
+
nbIterations: undefined,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/*
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
*/
|
|
71
|
+
const nbIterations = executeExpression(
|
|
72
|
+
getCompatibleVTLExpression(iterations),
|
|
73
|
+
{
|
|
74
|
+
bindingDependencies: loopDependencies,
|
|
75
|
+
iteration: undefined,
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (Array.isArray(subPages)) {
|
|
80
|
+
return {
|
|
81
|
+
...state,
|
|
82
|
+
isInLoop: true,
|
|
83
|
+
pager: {
|
|
84
|
+
...pager,
|
|
85
|
+
page: next,
|
|
86
|
+
subPage: 0,
|
|
87
|
+
nbSubPages: subPages.length,
|
|
88
|
+
iteration: 0,
|
|
89
|
+
nbIterations,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return state;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function validateChange(state) {
|
|
97
|
+
if (isOnEmptyPage(state)) {
|
|
98
|
+
return reduceGoNextPage(state);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return state;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function reduceGoNextPage(state) {
|
|
105
|
+
const { pages, isInLoop, pager } = state;
|
|
106
|
+
const { iteration, nbIterations, subPage, nbSubPages, page } = pager;
|
|
107
|
+
|
|
108
|
+
if (isInLoop && subPage < nbSubPages - 1) {
|
|
109
|
+
return validateChange(reduceNextSubPage(state));
|
|
110
|
+
}
|
|
111
|
+
if (isInLoop && subPage === nbSubPages - 1 && iteration < nbIterations - 1) {
|
|
112
|
+
return validateChange(reduceNextIteration(state));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const next = getNextPage(state);
|
|
116
|
+
const { isLoop, iterations, loopDependencies } = pages[next];
|
|
117
|
+
if (next === page) {
|
|
118
|
+
// TODO on devrait jamais en arriver là !
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isLoop) {
|
|
122
|
+
return validateChange(
|
|
123
|
+
reduceStartLoop(state, { next, iterations, loopDependencies })
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return validateChange(reduceNextPage(state, { next }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export default reduceGoNextPage;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isOnEmptyPage } from './commons';
|
|
2
|
+
import { validateLoopConditionFilter } from './commons';
|
|
3
|
+
import { getCompatibleVTLExpression } from '../commons';
|
|
4
|
+
|
|
5
|
+
function getPreviousPage(pager) {
|
|
6
|
+
const { page } = pager;
|
|
7
|
+
const p = Number.parseInt(page);
|
|
8
|
+
if (p > 1) {
|
|
9
|
+
return `${page - 1}`;
|
|
10
|
+
}
|
|
11
|
+
return page;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function goStartLoop(state, { previous, iterations, loopDependencies }) {
|
|
15
|
+
const { pages, pager, executeExpression } = state;
|
|
16
|
+
const { subPages } = pages[previous];
|
|
17
|
+
|
|
18
|
+
if (validateLoopConditionFilter(state, { next: previous })) {
|
|
19
|
+
return {
|
|
20
|
+
...state,
|
|
21
|
+
pager: {
|
|
22
|
+
...pager,
|
|
23
|
+
page: previous,
|
|
24
|
+
subPage: undefined,
|
|
25
|
+
nbSubPages: undefined,
|
|
26
|
+
iteration: undefined,
|
|
27
|
+
nbIterations: undefined,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(subPages)) {
|
|
33
|
+
const nbIterations = executeExpression(
|
|
34
|
+
getCompatibleVTLExpression(iterations),
|
|
35
|
+
{
|
|
36
|
+
bindingDependencies: loopDependencies,
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
...state,
|
|
41
|
+
isInLoop: true,
|
|
42
|
+
pager: {
|
|
43
|
+
...pager,
|
|
44
|
+
page: previous,
|
|
45
|
+
subPage: subPages.length - 1,
|
|
46
|
+
nbSubPages: subPages.length,
|
|
47
|
+
iteration: nbIterations - 1,
|
|
48
|
+
nbIterations,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function goPreviousSubPage(state) {
|
|
56
|
+
const { pager } = state;
|
|
57
|
+
const { subPage } = pager;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
pager: { ...pager, subPage: subPage - 1 },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function goPreviousIteration(state) {
|
|
66
|
+
const { pager, pages } = state;
|
|
67
|
+
const { iteration, page } = pager;
|
|
68
|
+
const { subPages } = pages[page];
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...state,
|
|
72
|
+
pager: { ...pager, subPage: subPages.length - 1, iteration: iteration - 1 },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function goPreviousPage(state, { previous }) {
|
|
77
|
+
const { pager } = state;
|
|
78
|
+
const { page } = pager;
|
|
79
|
+
|
|
80
|
+
if (previous !== page) {
|
|
81
|
+
return {
|
|
82
|
+
...state,
|
|
83
|
+
isInLoop: false,
|
|
84
|
+
pager: {
|
|
85
|
+
...pager,
|
|
86
|
+
page: previous,
|
|
87
|
+
iteration: undefined,
|
|
88
|
+
nbIterations: undefined,
|
|
89
|
+
subPage: undefined,
|
|
90
|
+
nbSubPages: undefined,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return state;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function validateChange(state) {
|
|
99
|
+
if (isOnEmptyPage(state)) {
|
|
100
|
+
return reduceGoPreviousPage(state);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return state;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function reduceGoPreviousPage(state) {
|
|
107
|
+
const { pages, pager, isInLoop } = state;
|
|
108
|
+
const { iteration, subPage } = pager;
|
|
109
|
+
|
|
110
|
+
// dans une boucle et l'itération courante n'est pas finie
|
|
111
|
+
if (isInLoop && subPage > 0) {
|
|
112
|
+
return validateChange(goPreviousSubPage(state));
|
|
113
|
+
}
|
|
114
|
+
// dans une boucle, l'itération courante est finie mais il reste encore au moins une autre
|
|
115
|
+
if (isInLoop && subPage === 0 && iteration > 0) {
|
|
116
|
+
return validateChange(goPreviousIteration(state));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const previous = getPreviousPage(pager);
|
|
120
|
+
const { isLoop, iterations, loopDependencies } = pages[previous];
|
|
121
|
+
// on rentre dans une boucle
|
|
122
|
+
if (isLoop) {
|
|
123
|
+
return validateChange(
|
|
124
|
+
goStartLoop(state, { previous, loopDependencies, iterations })
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
// on change de page
|
|
128
|
+
return validateChange(goPreviousPage(state, { previous }));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default reduceGoPreviousPage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './reduce-handle-change';
|
package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import reduceVariablesArray from './reduce-variables-array';
|
|
2
|
+
import reduceVariablesSimple from './reduce-variables-simple';
|
|
3
|
+
|
|
4
|
+
function isOnSubPage(pager) {
|
|
5
|
+
const { subPage } = pager;
|
|
6
|
+
return subPage !== undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function updateVariables(state, action) {
|
|
10
|
+
const { payload } = action;
|
|
11
|
+
const { response, value, args = {} } = payload;
|
|
12
|
+
const { name } = response;
|
|
13
|
+
const { loop, index, length } = args;
|
|
14
|
+
|
|
15
|
+
const { pager, variables } = state;
|
|
16
|
+
const { nbIterations, iteration } = pager;
|
|
17
|
+
|
|
18
|
+
if (loop) {
|
|
19
|
+
const variablesNext = reduceVariablesArray(variables, {
|
|
20
|
+
name,
|
|
21
|
+
value,
|
|
22
|
+
index,
|
|
23
|
+
length,
|
|
24
|
+
});
|
|
25
|
+
return { ...state, variables: variablesNext };
|
|
26
|
+
} else if (isOnSubPage(pager)) {
|
|
27
|
+
const variablesNext = reduceVariablesArray(variables, {
|
|
28
|
+
name,
|
|
29
|
+
value,
|
|
30
|
+
index: iteration,
|
|
31
|
+
length: nbIterations,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return { ...state, variables: variablesNext };
|
|
35
|
+
} else {
|
|
36
|
+
const variablesNext = reduceVariablesSimple(variables, { name, value });
|
|
37
|
+
return { ...state, variables: variablesNext };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* met à jour bindings pour l'exe du VTL (en appelant la fonction fournit par createExecuteExpression)
|
|
43
|
+
* @param {*} state
|
|
44
|
+
* @param {*} action
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
function updateBindings(state, action) {
|
|
48
|
+
const { payload } = action;
|
|
49
|
+
const { response } = payload;
|
|
50
|
+
const { name } = response;
|
|
51
|
+
const { updateBindings, variables } = state;
|
|
52
|
+
const { value } = variables[name];
|
|
53
|
+
|
|
54
|
+
updateBindings(name, value);
|
|
55
|
+
|
|
56
|
+
return state;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param {*} state
|
|
62
|
+
* @param {*} action
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
function reduceHandleChange(state, action) {
|
|
66
|
+
return updateBindings(updateVariables(state, action), action);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default reduceHandleChange;
|
package/src/utils/to-expose/hooks/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { resizeArrayVariable } from '../commons';
|
|
2
|
+
|
|
3
|
+
function reduceVariablesArray(variables, { name, value, index, length }) {
|
|
4
|
+
if (name in variables) {
|
|
5
|
+
const variable = variables[name];
|
|
6
|
+
const { value: previousValue } = variable;
|
|
7
|
+
|
|
8
|
+
// validation de la valeur courante : si pas un tableau ou si la taille du tableau a changé
|
|
9
|
+
let valueNext = resizeArrayVariable([...previousValue], length);
|
|
10
|
+
|
|
11
|
+
// value affectation
|
|
12
|
+
valueNext[index] = value;
|
|
13
|
+
return {
|
|
14
|
+
...variables,
|
|
15
|
+
[name]: { ...variable, value: valueNext },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return variables;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default reduceVariablesArray;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function reduceVariablesSimple(variables, { name, value }) {
|
|
2
|
+
if (name in variables) {
|
|
3
|
+
const variable = variables[name];
|
|
4
|
+
return {
|
|
5
|
+
...variables,
|
|
6
|
+
[name]: { ...variable, value },
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return variables;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default reduceVariablesSimple;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMapPages,
|
|
3
|
+
checkLoops,
|
|
4
|
+
isFirstLastPage,
|
|
5
|
+
createExecuteExpression,
|
|
6
|
+
} from '../commons';
|
|
7
|
+
|
|
8
|
+
/* à bouger d'ici */
|
|
9
|
+
|
|
10
|
+
function getInitalValueFromCollected(variable, data = {}) {
|
|
11
|
+
const { values, name } = variable;
|
|
12
|
+
let fromData;
|
|
13
|
+
if (name in data) {
|
|
14
|
+
const { COLLECTED, FORCED } = data[name];
|
|
15
|
+
fromData = COLLECTED || FORCED;
|
|
16
|
+
}
|
|
17
|
+
if (values) {
|
|
18
|
+
const { COLLECTED, FORCED } = values;
|
|
19
|
+
return fromData || FORCED || COLLECTED;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getInitialValueFromExternal(variable, data = {}) {
|
|
25
|
+
const { name } = variable;
|
|
26
|
+
if (name in data) {
|
|
27
|
+
return data[name];
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getInitialValue(variable, data = {}) {
|
|
33
|
+
const { COLLECTED, EXTERNAL, CALCULATED } = data;
|
|
34
|
+
const { variableType } = variable;
|
|
35
|
+
switch (variableType) {
|
|
36
|
+
case 'COLLECTED':
|
|
37
|
+
return getInitalValueFromCollected(variable, COLLECTED);
|
|
38
|
+
case 'EXTERNAL':
|
|
39
|
+
return getInitialValueFromExternal(variable, EXTERNAL);
|
|
40
|
+
case 'CALCULATED':
|
|
41
|
+
return getInitialValueFromExternal(variable, CALCULATED);
|
|
42
|
+
default:
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function appendToArrayMap(map, key, entry) {
|
|
48
|
+
if (key in map) {
|
|
49
|
+
return { ...map, [key]: [...map[key], entry] };
|
|
50
|
+
}
|
|
51
|
+
return { ...map, [key]: [entry] };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function appendToObjectMap(map, key, object) {
|
|
55
|
+
if (key in map) {
|
|
56
|
+
return { ...map, [key]: { ...map[key], ...object } };
|
|
57
|
+
}
|
|
58
|
+
return { ...map, [key]: object };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param {*} source
|
|
64
|
+
* @param {*} data
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
function createVariables(source, data) {
|
|
68
|
+
const { variables } = source;
|
|
69
|
+
const [mapVariablesTypes, mapVariables] = variables.reduce(
|
|
70
|
+
function ([mapType, mapVar], variable) {
|
|
71
|
+
const { variableType: type, name } = variable;
|
|
72
|
+
|
|
73
|
+
return [
|
|
74
|
+
appendToArrayMap(mapType, type, variable),
|
|
75
|
+
appendToObjectMap(mapVar, name, {
|
|
76
|
+
variable,
|
|
77
|
+
type,
|
|
78
|
+
value: getInitialValue(variable, data),
|
|
79
|
+
}),
|
|
80
|
+
];
|
|
81
|
+
},
|
|
82
|
+
[{}, {}]
|
|
83
|
+
);
|
|
84
|
+
//
|
|
85
|
+
const { CALCULATED = [] } = mapVariablesTypes;
|
|
86
|
+
CALCULATED.forEach(function (calculated) {
|
|
87
|
+
const { bindingDependencies = [] } = calculated;
|
|
88
|
+
bindingDependencies.forEach(function (name) {
|
|
89
|
+
if (name in mapVariables) {
|
|
90
|
+
const variable = mapVariables[name];
|
|
91
|
+
const { CalculatedLinked } = variable;
|
|
92
|
+
if (CalculatedLinked) {
|
|
93
|
+
CalculatedLinked.push(calculated);
|
|
94
|
+
} else {
|
|
95
|
+
variable.CalculatedLinked = [calculated];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return mapVariables;
|
|
102
|
+
}
|
|
103
|
+
/* */
|
|
104
|
+
|
|
105
|
+
function checkInLoop(state) {
|
|
106
|
+
const { pager, pages, executeExpression } = state;
|
|
107
|
+
const { page } = pager;
|
|
108
|
+
if (page in pages) {
|
|
109
|
+
const { isLoop, subPages, iterations, loopDependencies } = pages[page];
|
|
110
|
+
|
|
111
|
+
if (isLoop) {
|
|
112
|
+
return {
|
|
113
|
+
...state,
|
|
114
|
+
pager: {
|
|
115
|
+
...pager,
|
|
116
|
+
subPage: 0,
|
|
117
|
+
nbSubPages: subPages.length,
|
|
118
|
+
iteration: 0,
|
|
119
|
+
nbIterations: executeExpression(iterations, {
|
|
120
|
+
iteration: 0,
|
|
121
|
+
bindingDependencies: loopDependencies,
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return state;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function reduceOnInit(state, action) {
|
|
131
|
+
const { payload } = action;
|
|
132
|
+
const { source, data, initialPage, features } = payload;
|
|
133
|
+
if (source && data) {
|
|
134
|
+
const variables = createVariables(source, data); // map des variables
|
|
135
|
+
const [executeExpression, updateBindings] = createExecuteExpression(
|
|
136
|
+
variables,
|
|
137
|
+
features
|
|
138
|
+
);
|
|
139
|
+
const pages = checkLoops(createMapPages(source));
|
|
140
|
+
const { maxPage } = source;
|
|
141
|
+
const pager = {
|
|
142
|
+
page: initialPage,
|
|
143
|
+
maxPage: Number.parseInt(maxPage) || 1,
|
|
144
|
+
subPage: undefined,
|
|
145
|
+
nbSubPages: undefined,
|
|
146
|
+
iteration: undefined,
|
|
147
|
+
nbIterations: undefined,
|
|
148
|
+
};
|
|
149
|
+
const { isFirstPage, isLastPage } = isFirstLastPage(pager);
|
|
150
|
+
|
|
151
|
+
return checkInLoop({
|
|
152
|
+
...state,
|
|
153
|
+
variables,
|
|
154
|
+
pages,
|
|
155
|
+
isFirstPage,
|
|
156
|
+
isLastPage,
|
|
157
|
+
pager,
|
|
158
|
+
executeExpression,
|
|
159
|
+
updateBindings,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return state;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export default reduceOnInit;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import reduceOnInit from './reduce-on-init';
|
|
2
|
+
import reduceGoNextPage from './reduce-go-next-page';
|
|
3
|
+
import reduceGoPreviousPage from './reduce-go-previous-page';
|
|
4
|
+
import reduceHandleChange from './reduce-handle-change';
|
|
5
|
+
import reduceOnSetWaiting from './reduce-on-set-waiting';
|
|
6
|
+
import * as actions from '../actions';
|
|
7
|
+
|
|
8
|
+
function reducer(state, action) {
|
|
9
|
+
const { type } = action;
|
|
10
|
+
switch (type) {
|
|
11
|
+
case actions.ON_INIT:
|
|
12
|
+
return reduceOnInit(state, action);
|
|
13
|
+
case actions.GO_NEXT_PAGE:
|
|
14
|
+
return reduceGoNextPage(state, action);
|
|
15
|
+
case actions.GO_PREVIOUS_PAGE:
|
|
16
|
+
return reduceGoPreviousPage(state, action);
|
|
17
|
+
case actions.HANDLE_CHANGE:
|
|
18
|
+
return reduceHandleChange(state, action);
|
|
19
|
+
case actions.ON_SET_WAITING:
|
|
20
|
+
return reduceOnSetWaiting(state, action);
|
|
21
|
+
default:
|
|
22
|
+
return state;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default reducer;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useReducer, useEffect, useCallback } from 'react';
|
|
2
|
+
import INITIAL_STATE from './initial-state';
|
|
3
|
+
import * as actions from './actions';
|
|
4
|
+
import reducer from './reducer';
|
|
5
|
+
import { loadSuggester } from './commons';
|
|
6
|
+
import { useComponentsFromState, getPageTag, isFirstLastPage } from './commons';
|
|
7
|
+
|
|
8
|
+
function useLunatic({ source, data, initialPage, features }) {
|
|
9
|
+
const [state, dispatch] = useReducer(reducer, INITIAL_STATE);
|
|
10
|
+
const { pager, executeExpression, waiting } = state;
|
|
11
|
+
const components = useComponentsFromState(state);
|
|
12
|
+
const { suggesters } = source;
|
|
13
|
+
|
|
14
|
+
useEffect(
|
|
15
|
+
function () {
|
|
16
|
+
async function doIt() {
|
|
17
|
+
if (suggesters) {
|
|
18
|
+
dispatch(actions.onSetWaiting(true));
|
|
19
|
+
const status = await loadSuggester(suggesters);
|
|
20
|
+
dispatch(actions.onSetWaiting(false));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
doIt();
|
|
24
|
+
},
|
|
25
|
+
[suggesters]
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
useEffect(
|
|
29
|
+
function () {
|
|
30
|
+
dispatch(actions.onInit({ source, data, initialPage, features }));
|
|
31
|
+
},
|
|
32
|
+
[source, data, initialPage, features]
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const goNextPage = useCallback(
|
|
36
|
+
function () {
|
|
37
|
+
dispatch(actions.goNextPage());
|
|
38
|
+
},
|
|
39
|
+
[dispatch]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const goPreviousPage = useCallback(
|
|
43
|
+
function () {
|
|
44
|
+
dispatch(actions.goPreviousPage());
|
|
45
|
+
},
|
|
46
|
+
[dispatch]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const getComponents = useCallback(
|
|
50
|
+
function () {
|
|
51
|
+
return components;
|
|
52
|
+
},
|
|
53
|
+
[components]
|
|
54
|
+
);
|
|
55
|
+
const handleChange = useCallback(
|
|
56
|
+
function (response, value, args) {
|
|
57
|
+
dispatch(actions.handleChange(response, value, args));
|
|
58
|
+
},
|
|
59
|
+
[dispatch]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const pageTag = getPageTag(pager);
|
|
63
|
+
const { isFirstPage, isLastPage } = isFirstLastPage(pager);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
getComponents,
|
|
67
|
+
handleChange,
|
|
68
|
+
goNextPage,
|
|
69
|
+
goPreviousPage,
|
|
70
|
+
executeExpression,
|
|
71
|
+
pageTag,
|
|
72
|
+
isFirstPage,
|
|
73
|
+
isLastPage,
|
|
74
|
+
pager,
|
|
75
|
+
waiting,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default useLunatic;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
// updateQuestionnaire is useless since 2.0 optimization efforts
|
|
2
|
-
// export { updateQuestionnaire } from './handler';
|
|
3
|
-
export { mergeQuestionnaireAndData } from './init-questionnaire';
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from './state';
|
|
10
|
-
export { interpret } from './interpret';
|
|
11
|
-
export
|
|
1
|
+
// updateQuestionnaire is useless since 2.0 optimization efforts
|
|
2
|
+
// export { updateQuestionnaire } from './handler';
|
|
3
|
+
// export { mergeQuestionnaireAndData } from './init-questionnaire';
|
|
4
|
+
// export {
|
|
5
|
+
// getState,
|
|
6
|
+
// getCollectedState,
|
|
7
|
+
// getCollectedStateByValueType,
|
|
8
|
+
// getBindings,
|
|
9
|
+
// } from './state';
|
|
10
|
+
// export { interpret } from './interpret';
|
|
11
|
+
// export * from './hooks';
|
|
12
|
+
export { default as useLunatic } from './hooks';
|
|
13
|
+
|
|
14
|
+
export const interpret = () => {
|
|
15
|
+
throw new Error('redefine interpret if needed');
|
|
16
|
+
};
|